ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <jakarta-...@ehatchersolutions.com>
Subject Re: proposed patch to ANT SQL task
Date Tue, 21 Jan 2003 13:47:02 GMT
Paul,

Also, have a look at the DynamicConfigurator interface.  This would  
allow you to be completely dynamic about which attributes you accept.   
As stated though, be careful about which JDK you are relying on and  
that your code is backwards compatible to 1.1.

	Erik


On Tuesday, January 21, 2003, at 03:17  AM, Paul King wrote:
>
> Hi, I needed to pass properties in to a type-3 JDBC driver
> (WebLogic's RMI driver) in a SQL task.  Perhaps I missed
> how this could be done using existing functionality.
>
> I also removed the need to have userid and password specified.
> The JDBC spec doesn't require them and some database drivers
> such as cloudscape don't need them.  Net result is that
> I can now have databases which don't support user/pw fields
> (without dummy entries):
>
>    <target name="test_db_init">
>      <sql driver="COM.cloudscape.core.JDBCDriver"
>           url="jdbc:cloudscape:${base.dir}/database"
>           onerror="continue"
>           autocommit="true"
>      >
>      DELETE from NAMEAUDIT where NAME='xyzzy';
>      </sql>
>    </target>
>
> And I can support properties:
>
>    <target name="test_db_init2">
>      <sql driver="weblogic.jdbc.rmi.Driver"
>           url="jdbc:weblogic:rmi"
> properties="weblogic.server.url=t3:// 
> localhost:7001;weblogic.jdbc.datasource=Testing-ageapp-AgeDS"
>           onerror="continue"
>           autocommit="true"
>      >
>      DELETE from NAMEAUDIT where NAME='xyzzy';
>      </sql>
>    </target>
>
> Obviously you can place the username and password fields into the  
> properties field directly if you want or still use the old style
> separate elements.
>
> I haven't checked that my code meets any style guidelines at this point
> or checked if it breaks any existing tests - just wanted some feedback  
> first.
>
> I am new to this project and am not a commiter so let me know what I  
> need to do now.
>
> I also wanted to support datasources directly so that I could have
> something like:
>
>    <target name="test_db_init3">
>      <sql contextFactory="weblogic.jndi.WLInitialContextFactory"
>           url="t3://localhost:7001"
>           datasource="Testing-ageapp-AgeDS"
>           onerror="continue"
>           autocommit="true"
>      >
>      DELETE from NAMEAUDIT where NAME='xyzzy';
>      </sql>
>    </target>
>
> This would let me support the latest best practice of using
> datasources which would allow me to write more portable ant
> scripts across different app servers but I wasn't sure how to get
> the JNDI code to support the SQL's optional classpath element
> so I wimped out.
>
>
> Regards, Paul.
>
> -------->8----------
> *** JDBCTask.java.orig	Wed Oct  2 11:09:20 2002
> --- JDBCTask.java	Tue Jan 21 15:47:18 2003
> ***************
> *** 67,72 ****
> --- 67,73 ----
>   import java.sql.SQLException;
>   import java.util.Hashtable;
>   import java.util.Properties;
> + import java.util.StringTokenizer;
>
>   /**
>    * Handles JDBC configuration needed by SQL type tasks.
> ***************
> *** 171,177 ****
>        */
>       private String password = null;
>
> !     /**
>        * RDBMS Product needed for this SQL.
>        **/
>       private String rdbms = null;
> --- 172,183 ----
>        */
>       private String password = null;
>
> ! 	/**
> ! 	 * Properties
> ! 	 */
> ! 	private String properties = null;
> !
> ! 	/**
>        * RDBMS Product needed for this SQL.
>        **/
>       private String rdbms = null;
> ***************
> *** 233,252 ****
>           this.url = url;
>       }
>
> !     /**
> !      * Sets the password; required.
>        * @param password The password to set
>        */
> !     public void setPassword(String password) {
>           this.password = password;
>       }
>
> !     /**
>        * Auto commit flag for database connection;
>        * optional, default false.
>        * @param autocommit The autocommit to set
>        */
> !     public void setAutocommit(boolean autocommit) {
>           this.autocommit = autocommit;
>       }
>
> --- 239,280 ----
>           this.url = url;
>       }
>
> ! 	/**
> ! 	 * Set the user name for the connection;
> ! 	 * optional, but some RDBMSs will require it.
> ! 	 * @param userId The userId to set
> ! 	 */
> ! 	public void setUserid(String userId)
> ! 	{
> ! 		this.userId = userId;
> ! 	}
> !
> ! 	/**
> !      * Sets the password;
> ! 	 * optional, but some RDBMSs will require it.
>        * @param password The password to set
>        */
> !     public void setPassword(String password)
> ! 	{
>           this.password = password;
>       }
>
> ! 	/**
> ! 	 * Sets the properties; optional.
> ! 	 * @param properties The properties to set
> ! 	 */
> ! 	public void setProperties(String properties)
> ! 	{
> ! 		this.properties = properties;
> ! 	}
> !
> ! 	/**
>        * Auto commit flag for database connection;
>        * optional, default false.
>        * @param autocommit The autocommit to set
>        */
> !     public void setAutocommit(boolean autocommit)
> ! 	{
>           this.autocommit = autocommit;
>       }
>
> ***************
> *** 317,345 ****
>           return loader;
>       }
>
> !     /**
>        * Creates a new Connection as using the driver, url, userid and  
> password specified.
>        * The calling method is responsible for closing the connection.
>        * @return Connection the newly created connection.
>        * @throws BuildException if the UserId/Password/Url is not set  
> or there is no suitable driver or the driver fails to load.
>        */
> !     protected Connection getConnection() throws BuildException {
> !         if (userId == null) {
> !             throw new BuildException("User Id attribute must be  
> set!", location);
> !         }
> !         if (password == null) {
> !             throw new BuildException("Password attribute must be  
> set!", location);
> !         }
>           if (url == null) {
>               throw new BuildException("Url attribute must be set!",  
> location);
>           }
>           try {
>
>               log("connecting to " + getUrl(), Project.MSG_VERBOSE);
> !             Properties info = new Properties();
> !             info.put("user", getUserId());
> !             info.put("password", getPassword());
> !             Connection conn = getDriver().connect(getUrl(), info);
>
>               if (conn == null) {
>                   // Driver doesn't understand the URL
> --- 345,391 ----
>           return loader;
>       }
>
> ! 	/**
> ! 	 * Creates a new Properties data structure from userid, password  
> and specified properties.
> ! 	 * @return Properties the newly merged properties.
> ! 	 * @throws BuildException if the properties string is malformed.
> ! 	 */
> ! 	protected Propterties getAllProperties() throws BuildException
> ! 	{
> ! 		Properties info = new Properties();
> ! 		if (userId != null) info.put("user", getUserId());
> ! 		if (password != null) info.put("password", getPassword());
> ! 		if (properties != null)
> ! 		{
> ! 			StringTokenizer st = new StringTokenizer(getProperties(), ";");
> ! 			while (st.hasMoreTokens())
> ! 			{
> ! 				String token = st.nextToken();
> ! 				int keyEnd = token.indexOf('=');
> ! 				if (keyEnd < 0 || keyEnd == token.length()-1)
> ! 					throw new BuildException("Malformed Property!", location);
> ! 				info.put(token.substring(0,keyEnd),token.substring(keyEnd+1));
> ! 			}
> ! 		}
> ! 		return info;
> ! 	}
> !
> ! 	/**
>        * Creates a new Connection as using the driver, url, userid and  
> password specified.
>        * The calling method is responsible for closing the connection.
>        * @return Connection the newly created connection.
>        * @throws BuildException if the UserId/Password/Url is not set  
> or there is no suitable driver or the driver fails to load.
>        */
> !     protected Connection getConnection() throws BuildException
> ! 	{
>           if (url == null) {
>               throw new BuildException("Url attribute must be set!",  
> location);
>           }
>           try {
>
> + 			Connection conn=null;
>               log("connecting to " + getUrl(), Project.MSG_VERBOSE);
> ! 			conn = getDriver().connect(getUrl(), getAllProperties());
>
>               if (conn == null) {
>                   // Driver doesn't understand the URL
> ***************
> *** 453,466 ****
>       }
>
>       /**
> -      * Set the user name for the connection; required.
> -      * @param userId The userId to set
> -      */
> -     public void setUserid(String userId) {
> -         this.userId = userId;
> -     }
> -
> -     /**
>        * Gets the password.
>        * @return Returns a String
>        */
> --- 499,504 ----
> ***************
> *** 468,478 ****
>           return password;
>       }
>
> !     /**
>        * Gets the rdbms.
>        * @return Returns a String
>        */
> !     public String getRdbms() {
>           return rdbms;
>       }
>
> --- 506,526 ----
>           return password;
>       }
>
> ! 	/**
> ! 	 * Gets the properties.
> ! 	 * @return Returns a String
> ! 	 */
> ! 	public String getProperties()
> ! 	{
> ! 		return properties;
> ! 	}
> !
> ! 	/**
>        * Gets the rdbms.
>        * @return Returns a String
>        */
> !     public String getRdbms()
> ! 	{
>           return rdbms;
>       }
>
> -------->8----------
>
>
> --
> To unsubscribe, e-mail:    
> <mailto:ant-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:  
> <mailto:ant-dev-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message