You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2005/10/25 05:26:44 UTC

svn commit: r328246 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apache/derbyTesting/functionTests/tests/store/ tools/org/apache/derby/impl/t...

Author: kmarsden
Date: Mon Oct 24 20:26:28 2005
New Revision: 328246

URL: http://svn.apache.org/viewcvs?rev=328246&view=rev
Log:
DERBY-597 - Enhance ij connect statement to work in J2ME/CDC/FP
ummary of patch:
* If ij.dataSource property is set and the url in the 'connect' statement does not start with 'jdbc:', ij calls util.getDataSourceConnection to get connection (instead of using DriverManager).
  
* Added getDataSourceConnection(String dsName,String user,String password,String dbName,boolean firstTime) to util.java. This returns a connection using the data source passed in ij.dataSource property. This method is called by startJBMS in util.java and ConnectStatement() in ij. The parameter firstTime indicates whether this method is called at start of test by startJBMS or by ConnectStatement.
 
* getDataSourceConnection method in turn calls setupDataSource which calls the set methods of data source. If firstTime=true, it uses values of ij.dataSource.* properties to set up the data source object. Otherwise, the properties ij.dataSource.databaseName and ij.dataSource.createDatabase are ignored. Instead, value of 'dbName' parameter is used. [In first version of this patch, parameter 'firstTime' was called 'create']
  
* Removed J2ME excludes from 13 tests which pass with this patch. Some tests needed changes in the connect statement url and master files.

Contributed by Deepa Remesh 


Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTable.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTableVti.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/aggregateOptimization_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors3_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/supersimple_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TransactionTable_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/cisco_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/heapscan_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso1multi_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso2multi_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso3multi_app.properties
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/implicitConversions.out Mon Oct 24 20:26:28 2005
@@ -2557,7 +2557,7 @@
 -- negate tests for implicit conversions
 -- to/from (var)char
 -- union
-connect 'jdbc:derby:wombat';
+connect 'wombat';
 ij> autocommit on;
 ij> values cast(1 as smallint), 'a';
 ERROR 42X61: Types 'SMALLINT' and 'CHAR' are not UNION compatible.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTable.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTable.out?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTable.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTable.out Mon Oct 24 20:26:28 2005
@@ -1,8 +1,8 @@
 ij> -- multiuser lock table tests
 disconnect;
-ij> connect 'jdbc:derby:wombat;user=U1' AS C1;
+ij> connect 'wombat;user=U1' AS C1;
 ij> autocommit off;
-ij> connect 'jdbc:derby:wombat;user=U2' AS C2;
+ij> connect 'wombat;user=U2' AS C2;
 ij(C2)> autocommit off;
 ij(C2)> set connection C1;
 ij(C1)> -- create a table and populate it

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTableVti.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTableVti.out?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTableVti.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/lockTableVti.out Mon Oct 24 20:26:28 2005
@@ -1,5 +1,5 @@
 ij> --test to make sure WAIT state is displayed when lock table is printed
-connect 'jdbc:derby:wombat;user=c1' AS C1;
+connect 'wombat;user=c1' AS C1;
 ij(C1)> create procedure c1.sleep(t INTEGER) dynamic result sets 0  language java external name 'java.lang.Thread.sleep' parameter style java;
 0 rows inserted/updated/deleted
 ij(C1)> create table c1.account (a int primary key not null, b int);
@@ -20,7 +20,7 @@
 0 rows inserted/updated/deleted
 ij(C1)> update c1.account set b = b + 11;
 3 rows inserted/updated/deleted
-ij(C1)> connect 'jdbc:derby:wombat;user=c2' AS C2;
+ij(C1)> connect 'wombat;user=c2' AS C2;
 ij(C2)> autocommit off;
 ij(C2)> async C2S1 'update c1.account set b = b + 11';
 ij(C2)> set connection C1;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/aggregateOptimization_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/aggregateOptimization_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/aggregateOptimization_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/aggregateOptimization_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
 ij.protocol=jdbc:derby:
-usedefaults=true
-
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
\ No newline at end of file
+usedefaults=true
\ No newline at end of file

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions.sql
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions.sql?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions.sql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions.sql Mon Oct 24 20:26:28 2005
@@ -1153,7 +1153,7 @@
 -- to/from (var)char
 
 -- union
-connect 'jdbc:derby:wombat';
+connect 'wombat';
 autocommit on;
 values cast(1 as smallint), 'a';
 values 'a', cast(1 as smallint);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/implicitConversions_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.Driver
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable.sql
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable.sql?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable.sql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable.sql Mon Oct 24 20:26:28 2005
@@ -1,9 +1,9 @@
 -- multiuser lock table tests
 disconnect;
 
-connect 'jdbc:derby:wombat;user=U1' AS C1;
+connect 'wombat;user=U1' AS C1;
 autocommit off;
-connect 'jdbc:derby:wombat;user=U2' AS C2;
+connect 'wombat;user=U2' AS C2;
 autocommit off;
 
 set connection C1;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/lockTable_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.Driver
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors3_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors3_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors3_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/scrollCursors3_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/supersimple_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/supersimple_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/supersimple_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/supersimple_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TransactionTable_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TransactionTable_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TransactionTable_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TransactionTable_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/cisco_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/cisco_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/cisco_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/cisco_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/heapscan_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/heapscan_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/heapscan_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/heapscan_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti.sql
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti.sql?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti.sql (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti.sql Mon Oct 24 20:26:28 2005
@@ -1,5 +1,5 @@
 --test to make sure WAIT state is displayed when lock table is printed
-connect 'jdbc:derby:wombat;user=c1' AS C1;
+connect 'wombat;user=c1' AS C1;
 create procedure c1.sleep(t INTEGER) dynamic result sets 0  language java external name 'java.lang.Thread.sleep' parameter style java;
 create table c1.account (a int primary key not null, b int);
 autocommit off;
@@ -13,7 +13,7 @@
 call c1.sleep(200);
 
 update c1.account set b = b + 11;
-connect 'jdbc:derby:wombat;user=c2' AS C2;
+connect 'wombat;user=c2' AS C2;
 autocommit off;
 async C2S1 'update c1.account set b = b + 11';
 set connection C1;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/lockTableVti_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.Driver
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso1multi_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso1multi_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso1multi_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso1multi_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso2multi_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso2multi_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso2multi_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso2multi_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso3multi_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso3multi_app.properties?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso3multi_app.properties (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/rlliso3multi_app.properties Mon Oct 24 20:26:28 2005
@@ -1,5 +1 @@
-#Exclude for J2ME/Foundation - test requires java.sql.DriverManager
-runwithfoundation=false
-
-usedefaults=true
-
+usedefaults=true
\ No newline at end of file

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/ij.jj Mon Oct 24 20:26:28 2005
@@ -1148,6 +1148,24 @@
 		// JDBC or not.
 		// get the value of the string
 		// n.b. at some point this will have to deal with ''s
+		if (userT != null)
+    		userS = stringValue(userT.image);
+
+    	if (passwordT != null)
+    		passwordS = stringValue(passwordT.image);
+    			
+    	//If ij.dataSource property is set,use DataSource to get the connection
+		String dsName = util.getSystemProperty("ij.dataSource");
+		if (dsName != null){
+    		//Check that t.image does not start with jdbc:
+    		//If it starts with jdbc:, do not use DataSource to get connection
+    		sVal = stringValue(t.image);
+    		if(!sVal.startsWith("jdbc:") ){
+    			theConnection = util.getDataSourceConnection(dsName,userS,passwordS,sVal,false);
+    			return addSession( theConnection, n );
+    		}
+    	}    			
+    	
 		if (simplifiedPath)
 			// url for the database W/O 'jdbc:protocol:', i.e. just a dbname
 			// For example,
@@ -1164,12 +1182,6 @@
 			if (protocol == null) { throw ijException.noSuchProtocol(p); }
 			sVal = protocol + sVal; 
 		}
-
-		if (userT != null)
-			userS = stringValue(userT.image);
-
-		if (passwordT != null)
-			passwordS = stringValue(passwordT.image);
 
 		// add protocol if no driver matches url
 		boolean noDriver = false;

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java?rev=328246&r1=328245&r2=328246&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java Mon Oct 24 20:26:28 2005
@@ -335,30 +335,96 @@
     private static final Class[] INT_P = { Integer.TYPE };
 
 
-    static public void setupDataSource(Object ds) throws Exception {
+    /**
+     * Sets up a data source with values specified in ij.dataSource.* properties or
+     * passed as parameters of this method
+     * 
+     * @param ds DataSource object
+     * @param dbName Database Name
+     * @param firstTime If firstTime is false, ij.dataSource.createDatabase and ij.dataSource.databaseName 
+     * properties will not be used. The value in parameter dbName will be used instead of 
+     * ij.dataSource.databaseName.
+     * 
+     * @throws Exception
+     */
+    static public void setupDataSource(Object ds,String dbName,boolean firstTime) throws Exception {
 	// Loop over set methods on Datasource object, if there is a property
-	// then call the method with corresponding value.
-	java.lang.reflect.Method[] methods = ds.getClass().getMethods();
+	// then call the method with corresponding value. Call setCreateDatabase based on
+    //parameter create. 	
+   java.lang.reflect.Method[] methods = ds.getClass().getMethods();
 	for (int i = 0; i < methods.length; i++) {
 	    java.lang.reflect.Method m = methods[i];
 	    String name = m.getName();
+	    
 	    if (name.startsWith("set") && (name.length() > "set".length())) {
-		String property = name.substring("set".length()); // setXyyyZwww
-		property = "ij.dataSource."+property.substring(0,1).toLowerCase(java.util.Locale.ENGLISH)+ property.substring(1); // xyyyZwww
-		String value = util.getSystemProperty(property);
-		//System.out.println("setupDateSource: method="+name+" property="+property+" value="+((value==null)?"null":value));
-		if (value != null) {
-		    try {
-			// call string method
-			m.invoke(ds, new Object[] {value});
-		    } catch (Throwable ignore) {
-			// failed, assume it's an integer parameter
-			m.invoke(ds, new Object[] {Integer.valueOf(value)});
-		    }
-		}
+	     	//Check if setCreateDatabase has to be called based on create parameter
+	    	if(name.equals("setCreateDatabase") && !firstTime)
+	    		continue;
+	    	
+	    	String property = name.substring("set".length()); // setXyyyZwww
+	    	property = "ij.dataSource."+property.substring(0,1).toLowerCase(java.util.Locale.ENGLISH)+ property.substring(1); // xyyyZwww
+	    	String value = util.getSystemProperty(property);
+	    	if(name.equals("setDatabaseName") && !firstTime)
+	    		value = dbName;
+	    	if (value != null) {
+	    		try {
+	    			// call string method
+	    			m.invoke(ds, new Object[] {value});
+	    		} catch (Throwable ignore) {
+	    			// failed, assume it's an integer parameter
+	    			m.invoke(ds, new Object[] {Integer.valueOf(value)});
+	    		}
+	    	}
 	    }
 	}
     }
+    
+    /**
+     * Returns a connection obtained using the DataSource. This method will be called when ij.dataSource
+     * property is set. It uses ij.dataSource.* properties to get details for the connection. 
+     * 
+     * @param dsName Data Source name
+     * @param user User name
+     * @param password Password
+     * @param dbName Database Name
+     * @param firstTime Indicates if the method is called first time. This is passed to setupDataSource 
+     * method.
+     *   
+     * @return
+     * @throws SQLException
+     */
+    public static Connection getDataSourceConnection(String dsName,String user,String password,
+    												String dbName,boolean firstTime) throws SQLException{
+		// Get a new proxied connection through DataSource
+		Object ds = null; // really javax.sql.DataSource
+		try {
+			
+		    Class dc = Class.forName(dsName);
+		    ds = dc.newInstance();
+		    
+		    // set datasource properties
+		    setupDataSource(ds,dbName,firstTime);	   
+
+		    // Java method call "by hand" {  con = ds.getConnection(); }
+		    // or con = ds.getConnection(user, password)
+		    	
+			java.lang.reflect.Method m = 
+				user == null ? dc.getMethod("getConnection", null) :
+					 dc.getMethod("getConnection", DS_GET_CONN_TYPES);
+				
+			return (java.sql.Connection) m.invoke(ds,
+					 user == null ? null : new String[] {user, password});
+		} catch (InvocationTargetException ite)
+		{
+			if (ite.getTargetException() instanceof SQLException)
+				throw (SQLException) ite.getTargetException();
+			ite.printStackTrace(System.out);
+		} catch (Exception e)
+		{
+			e.printStackTrace(System.out);
+		}
+		return null;
+    }
 
 	/**
 		This will look for the System properties "ij.driver" and "ij.database"
@@ -433,37 +499,11 @@
 	    String dsName = util.getSystemProperty("ij.dataSource");
 	    if (dsName == null)
 	    	return null;
-
-		// Get a new proxied connection through DataSource
-		Object ds = null; // really javax.sql.DataSource
-		try {
-			
-		    Class dc = Class.forName(dsName);
-		    ds = dc.newInstance();
-		    
-		    // set datasource properties
-		    setupDataSource(ds);	   
-
-		    // Java method call "by hand" {  con = ds.getConnection(); }
-		    // or con = ds.getConnection(user, password)
-		    	
-			java.lang.reflect.Method m = 
-				user == null ? dc.getMethod("getConnection", null) :
-					 dc.getMethod("getConnection", DS_GET_CONN_TYPES);
-				
-			return (java.sql.Connection) m.invoke(ds,
-					 user == null ? null : new String[] {user, password});
-		} catch (InvocationTargetException ite)
-		{
-			if (ite.getTargetException() instanceof SQLException)
-				throw (SQLException) ite.getTargetException();
-			ite.printStackTrace(System.out);
-		} catch (Exception e)
-		{
-			e.printStackTrace(System.out);
-		}
-		
-		return null;
+	    
+	    //First connection - pass firstTime=true, dbName=null. For database name, 
+	    //value in ij.dataSource.databaseName will be used. 
+	    con = getDataSourceConnection(dsName,user,password,null,true);
+	    return con;
    }