git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@805014 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -832,6 +832,10 @@ Other changes: | |||
| * Ant now builds against commons-net 2.0 as well. | |||
| Bugzilla Report 47669. | |||
| * A new nested element connectionProperty of <sql> allows setting of | |||
| arbitrary JDBC connection properties. | |||
| Bugzilla Report 33452. | |||
| Changes from Ant 1.7.0 TO Ant 1.7.1 | |||
| ============================================= | |||
| @@ -296,6 +296,29 @@ of transactions. </p> | |||
| href="../using.html#path">PATH like structure</a> and can also be set via a nested | |||
| <em>classpath</em> element. It is used to load the JDBC classes.</p> | |||
| <h4>connectionProperty</h4> | |||
| <p><em>Since Ant 1.8.0</em></p> | |||
| <p>Use nested <code><connectionProperty></code> elements to | |||
| specify additional JDBC properties that need to be set when | |||
| connecting to the database.</p> | |||
| <table border="1" cellpadding="2" cellspacing="0"> | |||
| <tr> | |||
| <td valign="top"><b>Attribute</b></td> | |||
| <td valign="top"><b>Description</b></td> | |||
| <td align="center" valign="top"><b>Required</b></td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">name</td> | |||
| <td valign="top">Name of the property</td> | |||
| <td valign="top" align="center">Yes</td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">value</td> | |||
| <td valign="top">Value of the property</td> | |||
| <td valign="top" align="center">Yes</td> | |||
| </tr> | |||
| </table> | |||
| <h3>Examples</h3> | |||
| <blockquote><pre><sql | |||
| driver="org.database.jdbcDriver" | |||
| @@ -310,6 +333,21 @@ href="../using.html#path">PATH like structure</a> and can also be set via a nest | |||
| org.database.jdbcDriver and executes the SQL statements contained within | |||
| the file data.sql</p> | |||
| <blockquote><pre><sql | |||
| driver="org.database.jdbcDriver" | |||
| url="jdbc:database-url" | |||
| userid="sa" | |||
| password="pass" | |||
| src="data.sql"> | |||
| <connectionProperty name="internal_logon" value="SYSDBA"> | |||
| </sql> | |||
| </pre></blockquote> | |||
| <p>Connects to the database given in <i>url</i> as the sa user using | |||
| the org.database.jdbcDriver and executes the SQL statements contained | |||
| within the file data.sql. Also sets the | |||
| property <i>internal_logon</i> to the value <i>SYSDBA</i>.</p> | |||
| <blockquote><pre><sql | |||
| driver="org.database.jdbcDriver" | |||
| url="jdbc:database-url" | |||
| @@ -22,9 +22,12 @@ import java.sql.Connection; | |||
| import java.sql.DatabaseMetaData; | |||
| import java.sql.Driver; | |||
| import java.sql.SQLException; | |||
| import java.util.ArrayList; | |||
| import java.util.Hashtable; | |||
| import java.util.Properties; | |||
| import java.util.Iterator; | |||
| import java.util.List; | |||
| import java.util.Locale; | |||
| import java.util.Properties; | |||
| import org.apache.tools.ant.AntClassLoader; | |||
| import org.apache.tools.ant.BuildException; | |||
| @@ -148,6 +151,13 @@ public abstract class JDBCTask extends Task { | |||
| */ | |||
| private boolean failOnConnectionError = true; | |||
| /** | |||
| * Additional properties to put into the JDBC connection string. | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| private List/*<Property>*/ connectionProperties = new ArrayList(); | |||
| /** | |||
| * Sets the classpath for loading the driver. | |||
| * @param classpath The classpath to set | |||
| @@ -305,6 +315,15 @@ public abstract class JDBCTask extends Task { | |||
| return loader; | |||
| } | |||
| /** | |||
| * Additional properties to put into the JDBC connection string. | |||
| * | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| public void addConnectionProperty(Property var) { | |||
| connectionProperties.add(var); | |||
| } | |||
| /** | |||
| * Creates a new Connection as using the driver, url, userid and password | |||
| * specified. | |||
| @@ -332,6 +351,22 @@ public abstract class JDBCTask extends Task { | |||
| Properties info = new Properties(); | |||
| info.put("user", getUserId()); | |||
| info.put("password", getPassword()); | |||
| for (Iterator props = connectionProperties.iterator(); | |||
| props.hasNext(); ) { | |||
| Property p = (Property) props.next(); | |||
| String name = p.getName(); | |||
| String value = p.getValue(); | |||
| if (name == null || value == null) { | |||
| log("Only name/value pairs are supported as connection" | |||
| + " properties.", Project.MSG_WARN); | |||
| } else { | |||
| log("Setting connection property " + name + " to " + value, | |||
| Project.MSG_VERBOSE); | |||
| info.put(name, value); | |||
| } | |||
| } | |||
| Connection conn = getDriver().connect(getUrl(), info); | |||
| if (conn == null) { | |||