Browse Source

- addresses enhancement request #27446

- added closeQuietly to reduce duplication

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@375178 13f79535-47bb-0310-9956-ffa450edef68
master
Kevin Jackson 19 years ago
parent
commit
23dac94433
1 changed files with 34 additions and 21 deletions
  1. +34
    -21
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 34
- 21
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -90,8 +90,6 @@ public class SQLExec extends JDBCTask {
} }
} }




private int goodSql = 0; private int goodSql = 0;


private int totalSql = 0; private int totalSql = 0;
@@ -147,6 +145,11 @@ public class SQLExec extends JDBCTask {
*/ */
private boolean showheaders = true; private boolean showheaders = true;


/**
* Print SQL stats (rows affected)
*/
private boolean showtrailers = true;
/** /**
* Results Output file. * Results Output file.
*/ */
@@ -310,6 +313,16 @@ public class SQLExec extends JDBCTask {
this.showheaders = showheaders; this.showheaders = showheaders;
} }


/**
* 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; * Set the output file;
* optional, defaults to the Ant log. * optional, defaults to the Ant log.
@@ -433,22 +446,10 @@ public class SQLExec extends JDBCTask {
} }
} }
} catch (IOException e) { } catch (IOException e) {
if (!isAutocommit() && conn != null && onError.equals("abort")) {
try {
conn.rollback();
} catch (SQLException ex) {
// ignore
}
}
closeQuietly();
throw new BuildException(e, getLocation()); throw new BuildException(e, getLocation());
} catch (SQLException e) { } catch (SQLException e) {
if (!isAutocommit() && conn != null && onError.equals("abort")) {
try {
conn.rollback();
} catch (SQLException ex) {
// ignore
}
}
closeQuietly();
throw new BuildException(e, getLocation()); throw new BuildException(e, getLocation());
} finally { } finally {
try { try {
@@ -580,10 +581,8 @@ public class SQLExec extends JDBCTask {
log(updateCountTotal + " rows affected", log(updateCountTotal + " rows affected",
Project.MSG_VERBOSE); 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(); SQLWarning warning = conn.getWarnings();
@@ -669,6 +668,21 @@ public class SQLExec extends JDBCTask {
out.println(); 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, * The action a task should perform on an error,
* one of "continue", "stop" and "abort" * one of "continue", "stop" and "abort"
@@ -767,5 +781,4 @@ public class SQLExec extends JDBCTask {
} }
} }
} }

} }

Loading…
Cancel
Save