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 ka...@apache.org on 2006/03/29 14:26:28 UTC

svn commit: r389780 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util: BaseJDBCTestCase.java TestConfiguration.java TestUtil.java

Author: kahatlen
Date: Wed Mar 29 04:26:25 2006
New Revision: 389780

URL: http://svn.apache.org/viewcvs?rev=389780&view=rev
Log:
DERBY-1157: Helper methods in BaseJDBCTestCase for creating data
sources

Adding getDataSource(), getConnectionPoolDataSource() and
getXADataSource() to BaseJDBCTestCase. The new methods call various
methods in TestUtil for creating the data sources. A minor adjustment
had to be made to TestUtil.getDataSource() in order to make it return
JDBC 4.0 DataSources.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java?rev=389780&r1=389779&r2=389780&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java Wed Mar 29 04:26:25 2006
@@ -22,6 +22,8 @@
 import java.sql.*;
 import javax.sql.DataSource;
 import java.util.Properties;
+import javax.sql.ConnectionPoolDataSource;
+import javax.sql.XADataSource;
 
 /**
  * Base class for JDBC JUnit tests.
@@ -76,13 +78,96 @@
                     CONFIG.getUserPassword());
         } else {
             //Use DataSource for JSR169
-            Properties prop = new Properties();
-            prop.setProperty("databaseName", CONFIG.getDatabaseName());
-            prop.setProperty("connectionAttributes", "create=true");
-            DataSource ds = TestUtil.getDataSource(prop);
-            con = ds.getConnection();
+            con = getDataSource().getConnection();
         }
         return con;
+    }
+
+    /**
+     * Generate properties which can be set on a
+     * <code>DataSource</code> in order to connect to the default
+     * database.
+     *
+     * @return a <code>Properties</code> object containing server
+     * name, port number, database name and other attributes needed to
+     * connect to the default database
+     */
+    private static Properties getDefaultDataSourceProperties() {
+        Properties attrs = new Properties();
+        if (!usingEmbedded()) {
+            attrs.setProperty("serverName", CONFIG.getHostName());
+            attrs.setProperty("portNumber", Integer.toString(CONFIG.getPort()));
+        }
+        attrs.setProperty("databaseName", CONFIG.getDatabaseName());
+        attrs.setProperty("connectionAttributes", "create=true");
+        return attrs;
+    }
+
+    /**
+     * Return a <code>DataSource</code> for the appropriate framework.
+     *
+     * @param attrs properties for the data source
+     * @return a <code>DataSource</code> object
+     * @see TestUtil#getDataSource(Properties)
+     */
+    public static DataSource getDataSource(Properties attrs) {
+        return TestUtil.getDataSource(attrs);
+    }
+
+    /**
+     * Return a <code>DataSource</code> which can establish a
+     * connection to the default database.
+     *
+     * @return a <code>DataSource</code> object
+     */
+    public static DataSource getDataSource() {
+        return getDataSource(getDefaultDataSourceProperties());
+    }
+
+    /**
+     * Return a <code>ConnectionPoolDataSource</code> for the
+     * appropriate framework.
+     *
+     * @param attrs properties for the data source
+     * @return a <code>ConnectionPoolDataSource</code> object
+     * @see TestUtil#getConnectionPoolDataSource(Properties)
+     */
+    public static ConnectionPoolDataSource
+        getConnectionPoolDataSource(Properties attrs)
+    {
+        return TestUtil.getConnectionPoolDataSource(attrs);
+    }
+
+    /**
+     * Return a <code>ConnectionPoolDataSource</code> which can
+     * establish a connection to the default database.
+     *
+     * @return a <code>ConnectionPoolDataSource</code> object
+     */
+    public static ConnectionPoolDataSource getConnectionPoolDataSource() {
+        return getConnectionPoolDataSource(getDefaultDataSourceProperties());
+    }
+
+    /**
+     * Return an <code>XADataSource</code> for the appropriate
+     * framework.
+     *
+     * @param attrs properties for the data source
+     * @return an <code>XADataSource</code> object
+     * @see TestUtil#getXADataSource(Properties)
+     */
+    public static XADataSource getXADataSource(Properties attrs) {
+        return TestUtil.getXADataSource(attrs);
+    }
+
+    /**
+     * Return an <code>XADataSource</code> which can establish a
+     * connection to the default database.
+     *
+     * @return an <code>XADataSource</code> object
+     */
+    public static XADataSource getXADataSource() {
+        return getXADataSource(getDefaultDataSourceProperties());
     }
 
    /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java?rev=389780&r1=389779&r2=389780&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java Wed Mar 29 04:26:25 2006
@@ -158,6 +158,15 @@
     }
 
     /**
+     * Return the host name for the network server.
+     *
+     * @return host name.
+     */
+    public String getHostName() {
+        return hostName;
+    }
+
+    /**
      * Get port number for network server.
      * 
      * @return port number.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java?rev=389780&r1=389779&r2=389780&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java Wed Mar 29 04:26:25 2006
@@ -37,6 +37,7 @@
 import javax.sql.DataSource;
 
 import org.apache.derby.iapi.reference.JDBC30Translation;
+import org.apache.derby.iapi.services.info.JVMInfo;
 
 
 
@@ -306,6 +307,16 @@
 		if(HAVE_DRIVER_CLASS)
 		{
 			classname = getDataSourcePrefix() + REGULAR_DATASOURCE_STRING + "DataSource";
+			// The JDBC 4.0 implementation of the DataSource interface
+			// is suffixed with "40". Use it if it is available and
+			// the JVM version is at least 1.6.
+			if (JVMInfo.JDK_ID >= JVMInfo.J2SE_16) {
+				String classname40 = classname + "40";
+				try {
+					Class.forName(classname40);
+					classname = classname40;
+				} catch (ClassNotFoundException e) {}
+			}
 			return (javax.sql.DataSource) getDataSourceWithReflection(classname, attrs);
 		}
 		else