db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r429154 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util: JDBC.java TestConfiguration.java
Date Sun, 06 Aug 2006 16:54:04 GMT
Author: djd
Date: Sun Aug  6 09:54:04 2006
New Revision: 429154

URL: http://svn.apache.org/viewvc?rev=429154&view=rev
Log:
DERBY-1638 Add methods to JDBC for JUnit that indicates if the virtual machine environment
supports JDBC 2,3 or 4 and JSR169. Naming of methods indicates that the define the vm
level of support rather than the clients level.

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java?rev=429154&r1=429153&r2=429154&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java
Sun Aug  6 09:54:04 2006
@@ -29,6 +29,85 @@
  */
 public class JDBC {
 	
+    /**
+     * Tell if we are allowed to use DriverManager to create database
+     * connections.
+     */
+    private static final boolean HAVE_DRIVER
+                           = haveClass("java.sql.Driver");
+    
+    /**
+     * Does the ParameterMetaData class exist, indicates
+     * JDBC 3 (or JSR 169). 
+     */
+    private static final boolean HAVE_PARAMETER_META_DATA
+                           = haveClass("java.sql.ParameterMetaData");
+
+    /**
+     * Does the java.sql.SQLXML class exist, indicates JDBC 4. 
+     */
+    private static final boolean HAVE_SQLXML
+                           = haveClass("java.sql.SQLXML");
+    
+    /**
+     * Can we load a specific class, use this to determine JDBC level.
+     * @param className Class to attempt load on.
+     * @return true if class can be loaded, false otherwise.
+     */
+    private static boolean haveClass(String className)
+    {
+        try {
+            Class.forName(className);
+            return true;
+        } catch (Exception e) {
+        	return false;
+        }    	
+    }
+ 	/**
+ 	 * <p>
+	 * Return true if the virtual machine environment
+	 * supports JDBC4 or later.
+	 * </p>
+	 */
+	public static boolean vmSupportsJDBC4()
+	{
+		return HAVE_DRIVER
+	       && HAVE_SQLXML;
+	}
+ 	/**
+ 	 * <p>
+	 * Return true if the virtual machine environment
+	 * supports JDBC3 or later.
+	 * </p>
+	 */
+	public static boolean vmSupportsJDBC3()
+	{
+		return HAVE_DRIVER
+		       && HAVE_PARAMETER_META_DATA;
+	}
+
+	/**
+ 	 * <p>
+	 * Return true if the virtual machine environment
+	 * supports JDBC2 or later.
+	 * </p>
+	 */
+	public static boolean vmSupportsJDBC2()
+	{
+		return HAVE_DRIVER;
+	}
+	/**
+ 	 * <p>
+	 * Return true if the virtual machine environment
+	 * supports JSR169 (JDBC 3 subset).
+	 * </p>
+	 */
+	public static boolean vmSupportsJSR169()
+	{
+		return !HAVE_DRIVER
+		       && HAVE_PARAMETER_META_DATA;
+	}	
+	
 	/**
 	 * Rollback and close a connection for cleanup.
 	 * Test code that is expecting Connection.close to succeed

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestConfiguration.java?rev=429154&r1=429153&r2=429154&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
Sun Aug  6 09:54:04 2006
@@ -25,8 +25,6 @@
 import java.sql.SQLException;
 import java.util.Properties;
 
-import org.apache.derby.iapi.services.info.JVMInfo;
-
 /**
  * Class which holds information about the configuration of a Test.
  */
@@ -39,23 +37,6 @@
         new TestConfiguration(getSystemProperties());
     
     /**
-     * Tell if we are allowed to use DriverManager to create database
-     * connections.
-     */
-    private static final boolean HAVE_DRIVER;
-
-    static {
-        // See if java.sql.Driver is available. If it is not, we must use
-        // DataSource to create connections.
-        boolean haveDriver = false;
-        try {
-            Class.forName("java.sql.Driver");
-            haveDriver = true;
-        } catch (Exception e) {}
-        HAVE_DRIVER = haveDriver;
-    }
-    
-    /**
      * This constructor creates a TestConfiguration from a Properties object.
      *
      * @throws NumberFormatException if the port specification is not an integer.
@@ -231,7 +212,7 @@
     public Connection getConnection (String databaseName) throws SQLException {
         Connection con = null;
         JDBCClient client =getJDBCClient();
-        if (HAVE_DRIVER) {            
+        if (JDBC.vmSupportsJDBC2()) {            
             loadJDBCDriver(client.getJDBCDriverName());
             if (!isSingleLegXA()) {
                 con = DriverManager.getConnection(
@@ -279,7 +260,7 @@
 		//
 		// DriverManager autoloads the client only as of JDBC4.
 		//
-		if ( !supportsJDBC4() )
+		if ( !JDBC.vmSupportsJDBC4() )
 		{
 			return false;
 		}
@@ -316,18 +297,6 @@
 		//
 
 		return false;
-	}
-
- 	/**
- 	 * <p>
-	 * Return true if the client supports JDBC4, i.e., if the VM level is at
-	 * least 1.6.
-	 * </p>
-	 */
-	public	boolean	supportsJDBC4()
-	{
-		if ( JVMInfo.JDK_ID >= JVMInfo.J2SE_16 ) { return true; }
-		else { return false; }
 	}
 
 	/**



Mime
View raw message