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
This commit is contained in:
Stefan Bodewig 2008-07-11 10:59:48 +00:00
parent 435c6e5511
commit 3523966203
4 changed files with 37 additions and 3 deletions

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
=============================================

View File

@ -195,6 +195,13 @@ <h3>Parameters</h3>
<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>

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());
}
}
}

View File

@ -159,7 +159,7 @@ public class SQLExec extends JDBCTask {
/**
* Action to perform if an error is found
**/
*/
private String onError = "abort";
/**