You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by "John H. Lee" <jl...@c.kiracom.com> on 2000/07/26 03:16:54 UTC

[PATCH] SQLExec NullPointerException plus Filtering

Fixes bugs listed in previous [PATCH] message and allows filtering of
<sql> input file.  Project.replace() made public...problems with this?

-John



Index: SQLExec.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java,v

retrieving revision 1.3
diff -u -r1.3 SQLExec.java
--- SQLExec.java        2000/07/25 13:55:07     1.3
+++ SQLExec.java        2000/07/26 01:12:22
@@ -116,7 +116,19 @@
      * SQL input command
      */
     private String sqlCommand = "";
-
+
+    /**
+     * SQL input file property filtering
+     */
+    private boolean filtering = false;
+
+    /**
+     * Turn filtering on/off
+     */
+    public void setFiltering(String filter) {
+        filtering = Project.toBoolean(filter);
+    }
+
     /**
      * Set the name of the sql file to be run.
      */
@@ -170,7 +182,6 @@
      * Load the sql file and then execute it
      */
     public void execute() throws BuildException {
-        Connection conn = null;

         sqlCommand = sqlCommand.trim();

@@ -200,10 +211,11 @@
         }

         try{
-            conn.setAutoCommit(autocommit);
-
             log("connecting to " + url, Project.MSG_VERBOSE );
             conn = DriverManager.getConnection(url, userId, password);
+
+            conn.setAutoCommit(autocommit);
+
             statement = conn.createStatement();

             if (sqlCommand.length() != 0) {
@@ -258,7 +270,11 @@
             while ((line=in.readLine()) != null){
                 if (line.trim().startsWith("//")) continue;
                 if (line.trim().startsWith("--")) continue;
-
+
+                if (filtering) {
+                    line = project.replace(line, project.getFilters());

+                }
+
                 sql += " " + line;
                 if (sql.trim().endsWith(";")){
                     log("SQL: " + sql, Project.MSG_VERBOSE);





Index: Project.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v

retrieving revision 1.32
diff -u -r1.32 Project.java
--- Project.java        2000/07/21 14:24:35     1.32
+++ Project.java        2000/07/26 01:16:32
@@ -661,7 +661,7 @@
      *
      * @returns the string with the token replaced.
      */
-    private String replace(String s, Hashtable tokens) {
+    public String replace(String s, Hashtable tokens) {
         int index = s.indexOf(TOKEN_START);

         if (index > -1) {


Re: [PATCH] SQLExec NullPointerException plus Filtering

Posted by "John H. Lee" <jl...@c.kiracom.com>.
Stefan Bodewig wrote:

> >>>>> "JHL" == John H Lee <jl...@c.kiracom.com> writes:
>
>  JHL> allows filtering of <sql> input file.
>
> Filtering has been reserved for "copying" tasks so far, I'm not sure
> if we should spread this to other tasks as well.
>
> An alternative could be to do ${} expansions on the statements.
>
> What do others think?

I'd like to see closer integration of filtering and properties (ie ${}
expansions).  I think forcing filters to be defined as properties will
keep buildfiles clean.  Currently, it is possible to define a filter and
a property with the same name, but different values.  This can cause
confusion when writing and maintaining buildfiles, files to be filtered,
and property files.

An earlier patch I posted made all properties available as filters.  As
you pointed out, Stefan, this is potentially *very* dangerous.  I have
since added a "propertyFilters" boolean to <project>, forcing the
developer to be explicit about the use of this feature.

So, I see filtering as a general-purpose token-to-property replacement
tool and ${} expansion as an Ant buildfile/property construct.  In other
words, filtering provides public access to properties and ${} provides
private access.

Thoughts?

-John



Re: [PATCH] SQLExec NullPointerException plus Filtering

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "JHL" == John H Lee <jl...@c.kiracom.com> writes:

 JHL> allows filtering of <sql> input file.

Filtering has been reserved for "copying" tasks so far, I'm not sure
if we should spread this to other tasks as well.

An alternative could be to do ${} expansions on the statements.

What do others think?

Stefan