db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r493244 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit: JDBCDataSource.java TestConfiguration.java
Date Fri, 05 Jan 2007 23:42:03 GMT
Author: djd
Date: Fri Jan  5 15:42:02 2007
New Revision: 493244

URL: http://svn.apache.org/viewvc?view=rev&rev=493244
Log:
DERBY-2217 (partial) Cleanup in the junit test configuration to ensure that a copy
of TestConfiguration maintains the connection handling from the copy. All a decorator
to set the default connection handling to use DataSource api.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?view=diff&rev=493244&r1=493243&r2=493244
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Fri
Jan  5 15:42:02 2007
@@ -20,6 +20,7 @@
 package org.apache.derbyTesting.junit;
 
 import java.lang.reflect.Method;
+import java.security.AccessController;
 import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -98,15 +99,37 @@
     /**
      * Return a DataSource object of the passsed in type
      * configured with the passed in Java bean properties.
-     * This will actually work with an object that has Java bean
+     * This will actually work with any object that has Java bean
      * setter methods.
+     * <BR>
+     * If a thread context class loader exists then it is used
+     * to try and load the class.
      */
     static Object getDataSourceObject(String classname, HashMap beanProperties)
     {
-
-        Object ds;
+        ClassLoader contextLoader =
+            (ClassLoader) AccessController.doPrivileged
+        (new java.security.PrivilegedAction(){
+            
+            public Object run()  { 
+                return Thread.currentThread().getContextClassLoader();
+            }
+        });
+    
         try {
-            ds = Class.forName(classname).newInstance();
+            Object ds = null;
+            if (contextLoader != null)
+            {
+                try {
+                    ds = Class.forName(classname, true, contextLoader).newInstance();
+                } catch (Exception e) {
+                    // context loader may not be correctly hooked up
+                    // with parent, try without it.
+                }
+            }
+            
+            if (ds == null)
+                ds = Class.forName(classname).newInstance();
             
             for (Iterator i = beanProperties.keySet().iterator();
                 i.hasNext(); )

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?view=diff&rev=493244&r1=493243&r2=493244
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Fri Jan  5 15:42:02 2007
@@ -27,6 +27,7 @@
 import java.sql.SQLException;
 import java.util.Properties;
 
+import junit.extensions.TestSetup;
 import junit.framework.Assert;
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -271,7 +272,7 @@
      * @param test Test to be decorated
      * @return decorated test.
      */
-    public static Test singleUseDatabaseDecorator(Test test)
+    public static TestSetup singleUseDatabaseDecorator(Test test)
     {
         // Forward slash is ok, Derby treats database names
         // as URLs and translates forward slash to the local
@@ -347,11 +348,25 @@
      * The tearDown reverts the configuration to the previous
      * configuration.
      */
-    public static Test connectionXADecorator(Test test)
+    public static TestSetup connectionXADecorator(Test test)
     {
         return new ConnectorSetup(test,
                 "org.apache.derbyTesting.junit.XADataSourceConnector");
     }
+    /**
+     * Return a decorator that changes the configuration to obtain
+     * connections from a standard DataSource using
+     * <code>
+     * getConnection()
+     * </code>
+     * The tearDown reverts the configuration to the previous
+     * configuration.
+     */
+    public static TestSetup connectionDSDecorator(Test test)
+    {
+        return new ConnectorSetup(test,
+            "org.apache.derbyTesting.junit.DataSourceConnector");
+    }
     
     /**
      * Default embedded configuration
@@ -366,7 +381,7 @@
         
         this.jdbcClient = JDBCClient.getDefaultEmbedded();
         url = createJDBCUrlWithDatabaseName(dbName);
-        initConnector();
+        initConnector(null);
  
     }
 
@@ -384,7 +399,7 @@
         this.hostName = hostName;
         
         this.url = createJDBCUrlWithDatabaseName(dbName);
-        initConnector();
+        initConnector(copy.connector);
     }
 
     
@@ -408,7 +423,7 @@
         this.hostName = copy.hostName;
         
         this.url = copy.url;
-        initConnector();
+        initConnector(copy.connector);
     }
     /**
      * Obtain a new configuration identical to the passed in
@@ -429,7 +444,7 @@
         this.hostName = copy.hostName;
         
         this.url = createJDBCUrlWithDatabaseName(dbName);
-        initConnector();
+        initConnector(copy.connector);
     }
   
     /**
@@ -469,7 +484,7 @@
             jdbcClient = JDBCClient.getDefaultEmbedded();
         }
         url = createJDBCUrlWithDatabaseName(dbName);
-        initConnector();
+        initConnector(null);
     }
 
     /**
@@ -515,9 +530,21 @@
      * DataSource implementation for JSR 169.
      *
      */
-    private void initConnector()
+    private void initConnector(Connector oldConnector)
     {
-        if (JDBC.vmSupportsJDBC2())
+        if (oldConnector != null)
+        {
+            // Use the same type of connector as the
+            // configuration we are copying from.
+            
+            try {
+                connector = (Connector) Class.forName(
+                  oldConnector.getClass().getName()).newInstance();
+            } catch (Exception e) {
+                Assert.fail(e.getMessage());
+            }            
+        }
+        else if (JDBC.vmSupportsJDBC2())
         {
             try {
                 connector = (Connector) Class.forName(



Mime
View raw message