mirror of
https://github.com/apache/ant.git
synced 2025-05-18 14:04:48 +00:00
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:
parent
435c6e5511
commit
3523966203
5
WHATSNEW
5
WHATSNEW
@ -132,6 +132,11 @@ Other changes:
|
|||||||
instances when overriding other methods like runStatements.
|
instances when overriding other methods like runStatements.
|
||||||
Bugzilla Report 27178.
|
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
|
Changes from Ant 1.7.0 TO Ant 1.7.1
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
|
@ -195,6 +195,13 @@ <h3>Parameters</h3>
|
|||||||
<td width="10%" valign="top">No, default <em>false</em></td>
|
<td width="10%" valign="top">No, default <em>false</em></td>
|
||||||
</tr>
|
</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>
|
</table>
|
||||||
|
|
||||||
<h3>Parameters specified as nested elements</h3>
|
<h3>Parameters specified as nested elements</h3>
|
||||||
|
@ -142,6 +142,12 @@ public abstract class JDBCTask extends Task {
|
|||||||
**/
|
**/
|
||||||
private String version = null;
|
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.
|
* Sets the classpath for loading the driver.
|
||||||
* @param classpath The classpath to set
|
* @param classpath The classpath to set
|
||||||
@ -231,6 +237,15 @@ public abstract class JDBCTask extends Task {
|
|||||||
this.version = version;
|
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
|
* Verify we are connected to the correct RDBMS
|
||||||
* @param conn the jdbc connection
|
* @param conn the jdbc connection
|
||||||
@ -296,7 +311,8 @@ public abstract class JDBCTask extends Task {
|
|||||||
*
|
*
|
||||||
* The calling method is responsible for closing the connection.
|
* 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
|
* @throws BuildException if the UserId/Password/Url is not set or there
|
||||||
* is no suitable driver or the driver fails to load.
|
* is no suitable driver or the driver fails to load.
|
||||||
*/
|
*/
|
||||||
@ -326,8 +342,14 @@ public abstract class JDBCTask extends Task {
|
|||||||
conn.setAutoCommit(autocommit);
|
conn.setAutoCommit(autocommit);
|
||||||
return conn;
|
return conn;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// failed to connect
|
||||||
|
if (!failOnConnectionError) {
|
||||||
|
log("Failed to connect: " + e.getMessage(), Project.MSG_WARN);
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
throw new BuildException(e, getLocation());
|
throw new BuildException(e, getLocation());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ public class SQLExec extends JDBCTask {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to perform if an error is found
|
* Action to perform if an error is found
|
||||||
**/
|
*/
|
||||||
private String onError = "abort";
|
private String onError = "abort";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user