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 dj...@apache.org on 2005/05/31 19:51:26 UTC

svn commit: r179245 - /incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java

Author: djd
Date: Tue May 31 10:51:26 2005
New Revision: 179245

URL: http://svn.apache.org/viewcvs?rev=179245&view=rev
Log:
When ij obtains its initial connection using a data source (ij.dataSource)
use DataSource.getConnection(user, password) if ij.user is set.


Modified:
    incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java

Modified: incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java?rev=179245&r1=179244&r2=179245&view=diff
==============================================================================
--- incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java (original)
+++ incubator/derby/code/trunk/java/tools/org/apache/derby/impl/tools/ij/util.java Tue May 31 10:51:26 2005
@@ -52,7 +52,8 @@
 	@author ames
  */
 public class util implements java.security.PrivilegedAction {
-
+	
+	private static final Class[] DS_GET_CONN_TYPES = {"".getClass(), "".getClass()};
 	private util() {}
 
 	//-----------------------------------------------------------------
@@ -383,6 +384,9 @@
 	String jdbcProtocol = util.getSystemProperty("ij.protocol");
 	if (jdbcProtocol != null)
 	    util.loadDriverIfKnown(jdbcProtocol);
+	
+    String user = util.getSystemProperty("ij.user");
+    String password = util.getSystemProperty("ij.password");
 
 	// deprecate the non-ij prefix name
 	databaseURL = util.getSystemProperty("database");
@@ -396,16 +400,13 @@
 	    if (!databaseURL.startsWith("jdbc:") && jdbcProtocol != null)
 		databaseURL = jdbcProtocol+databaseURL;
 
-	    String user = util.getSystemProperty("ij.user");
-	    String password = util.getSystemProperty("ij.password");
-
 	    // Update connInfo for ij system properties and
 	    // framework network server
 
 	    connInfo = updateConnInfo(user, password,connInfo);
 
 	    // JDBC driver
-	    String driver = System.getProperty("driver");
+	    String driver = util.getSystemProperty("driver");
 	    if (driver == null) {
 		driver = "org.apache.derby.jdbc.EmbeddedDriver";
 	    }
@@ -416,7 +417,7 @@
 	}
 
 	    // handle datasource property
-	    String dsName = System.getProperty("ij.dataSource");
+	    String dsName = util.getSystemProperty("ij.dataSource");
 	    if (dsName == null)
 	    	return null;
 
@@ -428,11 +429,17 @@
 		    ds = dc.newInstance();
 		    
 		    // set datasource properties
-		    setupDataSource(ds);
+		    setupDataSource(ds);	   
 
 		    // Java method call "by hand" {  con = ds.getConnection(); }
-			java.lang.reflect.Method m = dc.getMethod("getConnection", null); 
-			return (java.sql.Connection) m.invoke(ds, new Object[] {});
+		    // 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)