You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ke...@apache.org on 2006/02/06 06:15:46 UTC

svn commit: r375178 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java

Author: kevj
Date: Sun Feb  5 21:15:44 2006
New Revision: 375178

URL: http://svn.apache.org/viewcvs?rev=375178&view=rev
Log:
- addresses enhancement request #27446
- added closeQuietly to reduce duplication

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java?rev=375178&r1=375177&r2=375178&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java Sun Feb  5 21:15:44 2006
@@ -90,8 +90,6 @@
         }
     }
 
-
-
     private int goodSql = 0;
 
     private int totalSql = 0;
@@ -148,6 +146,11 @@
     private boolean showheaders = true;
 
     /**
+     * Print SQL stats (rows affected)
+     */
+    private boolean showtrailers = true;
+    
+    /**
      * Results Output file.
      */
     private File output = null;
@@ -311,6 +314,16 @@
     }
 
     /**
+     * Print trailing info (rows affected) for the SQL
+     * Addresses Bug/Request #27446
+     * @param showtrailers if true prints the SQL rows affected
+     * @since Ant 1.7
+     */
+    public void setShowtrailers(boolean showtrailers) {
+        this.showtrailers = showtrailers;
+    }
+    
+    /**
      * Set the output file;
      * optional, defaults to the Ant log.
      * @param output the output file to use for logging messages.
@@ -433,22 +446,10 @@
                     }
                 }
             } catch (IOException e) {
-                if (!isAutocommit() && conn != null && onError.equals("abort")) {
-                    try {
-                        conn.rollback();
-                    } catch (SQLException ex) {
-                        // ignore
-                    }
-                }
+                closeQuietly();
                 throw new BuildException(e, getLocation());
             } catch (SQLException e) {
-                if (!isAutocommit() && conn != null && onError.equals("abort")) {
-                    try {
-                        conn.rollback();
-                    } catch (SQLException ex) {
-                        // ignore
-                    }
-                }
+                closeQuietly();
                 throw new BuildException(e, getLocation());
             } finally {
                 try {
@@ -580,10 +581,8 @@
             log(updateCountTotal + " rows affected",
                 Project.MSG_VERBOSE);
 
-            if (print) {
-                StringBuffer line = new StringBuffer();
-                line.append(updateCountTotal + " rows affected");
-                out.println(line);
+            if (print && showtrailers) {
+                out.println(updateCountTotal + " rows affected");
             }
 
             SQLWarning warning = conn.getWarnings();
@@ -669,6 +668,21 @@
         out.println();
     }
 
+    /*
+     * Closes an unused connection after an error and doesn't rethrow 
+     * a possible SQLException
+     * @since Ant 1.7
+     */
+    private void closeQuietly() {
+        if (!isAutocommit() && conn != null && onError.equals("abort")) {
+            try {
+                conn.rollback();
+            } catch (SQLException ex) {
+                // ignore
+            }
+        }
+    }
+    
     /**
      * The action a task should perform on an error,
      * one of "continue", "stop" and "abort"
@@ -767,5 +781,4 @@
             }
         }
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org