Browse Source

Allow ant to continue even if <sql> fails to connect to the database. PR 36712.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@675917 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
3523966203
4 changed files with 37 additions and 3 deletions
  1. +5
    -0
      WHATSNEW
  2. +7
    -0
      docs/manual/CoreTasks/sql.html
  3. +24
    -2
      src/main/org/apache/tools/ant/taskdefs/JDBCTask.java
  4. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java

+ 5
- 0
WHATSNEW View File

@@ -132,6 +132,11 @@ Other changes:
instances when overriding other methods like runStatements.
Bugzilla Report 27178.

* <sql> has a new failOnConnectionError attribute that can be used to
keep a build going even if the task failed to connect to the
database.
Bugzilla Report 36712.

Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================



+ 7
- 0
docs/manual/CoreTasks/sql.html View File

@@ -195,6 +195,13 @@ and <b>abort</b> execution and transaction and fail task.</p>
<td width="10%" valign="top">No, default <em>false</em></td>
</tr>

<tr>
<td width="12%" valign="top">failOnConnectionError</td>
<td width="78%" valign="top">If false, will only print a warning
message and not execute any statement if the task fails to connect
to the database. <em>Since Ant 1.8.0</em>.</td>
<td width="10%" valign="top">No, default <em>true</em></td>
</tr>
</table>

<h3>Parameters specified as nested elements</h3>


+ 24
- 2
src/main/org/apache/tools/ant/taskdefs/JDBCTask.java View File

@@ -142,6 +142,12 @@ public abstract class JDBCTask extends Task {
**/
private String version = null;

/**
* whether the task fails when ant fails to connect to the database.
* @since Ant 1.8.0
*/
private boolean failOnConnectionError = true;

/**
* Sets the classpath for loading the driver.
* @param classpath The classpath to set
@@ -231,6 +237,15 @@ public abstract class JDBCTask extends Task {
this.version = version;
}

/**
* whether the task should cause the build to fail if it cannot
* connect to the database.
* @since Ant 1.8.0
*/
public void setFailOnConnectionError(boolean b) {
failOnConnectionError = b;
}

/**
* Verify we are connected to the correct RDBMS
* @param conn the jdbc connection
@@ -296,7 +311,8 @@ public abstract class JDBCTask extends Task {
*
* The calling method is responsible for closing the connection.
*
* @return Connection the newly created connection.
* @return Connection the newly created connection or null if the
* connection failed and failOnConnectionError is false.
* @throws BuildException if the UserId/Password/Url is not set or there
* is no suitable driver or the driver fails to load.
*/
@@ -326,7 +342,13 @@ public abstract class JDBCTask extends Task {
conn.setAutoCommit(autocommit);
return conn;
} catch (SQLException e) {
throw new BuildException(e, getLocation());
// failed to connect
if (!failOnConnectionError) {
log("Failed to connect: " + e.getMessage(), Project.MSG_WARN);
return null;
} else {
throw new BuildException(e, getLocation());
}
}

}


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

@@ -159,7 +159,7 @@ public class SQLExec extends JDBCTask {

/**
* Action to perform if an error is found
**/
*/
private String onError = "abort";

/**


Loading…
Cancel
Save