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/07/27 09:26:58 UTC

svn commit: r425987 - in /db/derby/code/trunk/java: client/org/apache/derby/client/net/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ testing/org/...

Author: kahatlen
Date: Thu Jul 27 00:26:57 2006
New Revision: 425987

URL: http://svn.apache.org/viewvc?rev=425987&view=rev
Log:
DERBY-1546: Derby JDBC 4.0 driver returns 3 for JDBC driver major version

Description of the changes:

  * EmbedDatabaseMetaData40 and NetDatabaseMetaData40 override
    getJDBCMajorVersion() and getJDBCMinorVersion().

  * jdbcapi/dbMetaDataJdbc30.java was modified to print "AS EXPECTED"
    instead of the returned value from the JDBC version methods (of
    course, it prints something else if the version is not as
    expected). This was done in order to avoid the need for separate
    jdk16 canons.

  * TestUtil.getJDBCMajorVersion() was updated to recognize JDBC major
    version > 3.

  * Fixed a bug in build.xml in functionTests/util. TestUtil.java is
    incorrectly compiled with source and target level 1.4. It works
    correctly after an 'ant clobber' because some other 1.3 class
    depends on it and causes it to be compiled as part of another ant
    target, but if TestUtil.java is the only file that needs
    recompilation, jdk 1.4 is used.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetDatabaseMetaData40.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dbMetaDataJdbc30.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dbMetaDataJdbc30.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbMetaDataJdbc30.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dbMetaDataJdbc30.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetDatabaseMetaData40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetDatabaseMetaData40.java?rev=425987&r1=425986&r2=425987&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetDatabaseMetaData40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetDatabaseMetaData40.java Thu Jul 27 00:26:57 2006
@@ -34,7 +34,27 @@
     public NetDatabaseMetaData40(NetAgent netAgent, NetConnection netConnection) {
         super(netAgent,netConnection);
     }
-    
+
+    /**
+     * Retrieves the major JDBC version number for this driver.
+     * @return JDBC version major number
+     * @exception SQLException if the connection is closed
+     */
+    public int getJDBCMajorVersion() throws SQLException {
+        checkForClosedConnection();
+        return 4;
+    }
+
+    /**
+     * Retrieves the minor JDBC version number for this driver.
+     * @return JDBC version minor number
+     * @exception SQLException if the connection is closed
+     */
+    public int getJDBCMinorVersion() throws SQLException {
+        checkForClosedConnection();
+        return 0;
+    }
+
     /**
      * Indicates whether or not this data source supports the SQL
      * <code>ROWID</code> type. Since Derby does not support the

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java?rev=425987&r1=425986&r2=425987&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java Thu Jul 27 00:26:57 2006
@@ -37,7 +37,25 @@
         super(connection,url);
         this.url = url;
     }
-   
+
+    /**
+     * Retrieves the major JDBC version number for this driver.
+     *
+     * @return JDBC version major number
+     */
+    public int getJDBCMajorVersion() {
+        return 4;
+    }
+
+    /**
+     * Retrieves the minor JDBC version number for this driver.
+     *
+     * @return JDBC version minor number
+     */
+    public int getJDBCMinorVersion() {
+        return 0;
+    }
+
     public RowIdLifetime getRowIdLifetime() throws SQLException {
         return RowIdLifetime.ROWID_UNSUPPORTED;
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dbMetaDataJdbc30.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dbMetaDataJdbc30.out?rev=425987&r1=425986&r2=425987&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dbMetaDataJdbc30.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/dbMetaDataJdbc30.out Thu Jul 27 00:26:57 2006
@@ -7,8 +7,7 @@
 supportsGetGeneratedKeys() : false
 supportsResultSetHoldability(HOLD_CURSORS_OVER_COMMIT) : true
 supportsResultSetHoldability(CLOSE_CURSORS_AT_COMMIT) : true
-getJDBCMajorVersion() : 3
-getJDBCMinorVersion() : 0
+getJDBCMajorVersion()/getJDBCMinorVersion() : AS EXPECTED
 getSQLStateType() : 2
 getResultSetHoldability() : 1
 getDatabaseMajorVersion() : 10

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dbMetaDataJdbc30.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dbMetaDataJdbc30.out?rev=425987&r1=425986&r2=425987&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dbMetaDataJdbc30.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/dbMetaDataJdbc30.out Thu Jul 27 00:26:57 2006
@@ -7,8 +7,7 @@
 supportsGetGeneratedKeys() : false
 supportsResultSetHoldability(HOLD_CURSORS_OVER_COMMIT) : true
 supportsResultSetHoldability(CLOSE_CURSORS_AT_COMMIT) : true
-getJDBCMajorVersion() : 3
-getJDBCMinorVersion() : 0
+getJDBCMajorVersion()/getJDBCMinorVersion() : AS EXPECTED
 getSQLStateType() : 2
 getResultSetHoldability() : 1
 getDatabaseMajorVersion() : 10

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbMetaDataJdbc30.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbMetaDataJdbc30.out?rev=425987&r1=425986&r2=425987&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbMetaDataJdbc30.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dbMetaDataJdbc30.out Thu Jul 27 00:26:57 2006
@@ -7,8 +7,7 @@
 supportsGetGeneratedKeys() : false
 supportsResultSetHoldability(HOLD_CURSORS_OVER_COMMIT) : true
 supportsResultSetHoldability(CLOSE_CURSORS_AT_COMMIT) : true
-getJDBCMajorVersion() : 3
-getJDBCMinorVersion() : 0
+getJDBCMajorVersion()/getJDBCMinorVersion() : AS EXPECTED
 getSQLStateType() : 2
 getResultSetHoldability() : 1
 getDatabaseMajorVersion() : 10

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dbMetaDataJdbc30.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dbMetaDataJdbc30.java?rev=425987&r1=425986&r2=425987&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dbMetaDataJdbc30.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/dbMetaDataJdbc30.java Thu Jul 27 00:26:57 2006
@@ -28,6 +28,7 @@
 import java.sql.Statement;
 
 import org.apache.derby.iapi.reference.JDBC30Translation;
+import org.apache.derby.iapi.services.info.JVMInfo;
 
 import org.apache.derby.tools.ij;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
@@ -104,10 +105,7 @@
         met.supportsResultSetHoldability(JDBC30Translation.CLOSE_CURSORS_AT_COMMIT));
 
 			System.out.println();
-			System.out.println("getJDBCMajorVersion() : " + met.getJDBCMajorVersion());
-
-			System.out.println();
-			System.out.println("getJDBCMinorVersion() : " + met.getJDBCMinorVersion());
+			checkJDBCVersion(met);
 
 			System.out.println();
 			System.out.println("getSQLStateType() : " + met.getSQLStateType());
@@ -205,6 +203,37 @@
 			System.out.println();
 		}
 		s.close();
+	}
+
+	/**
+	 * Check whether <code>getJDBCMajorVersion()</code> and
+	 * <code>getJDBCMinorVersion()</code> return the expected version numbers.
+	 * @param met the <code>DatabaseMetaData</code> object to test
+	 * @exception SQLException if a database error occurs
+	 */
+	private static void checkJDBCVersion(DatabaseMetaData met)
+		throws SQLException
+	{
+		final int major, minor;
+		if (TestUtil.isJCCFramework()) {
+			major = 3;
+			minor = 0;
+		} else if (JVMInfo.JDK_ID < JVMInfo.J2SE_16) {
+			major = 3;
+			minor = 0;
+		} else {
+			major = 4;
+			minor = 0;
+		}
+		System.out.print("getJDBCMajorVersion()/getJDBCMinorVersion() : ");
+		int maj = met.getJDBCMajorVersion();
+		int min = met.getJDBCMinorVersion();
+		if (major == maj && minor == min) {
+			System.out.println("AS EXPECTED");
+		} else {
+			System.out.println("GOT " + maj + "." + min +
+							   ", EXPECTED " + major + "." + minor);
+		}
 	}
 
 	/**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/TestUtil.java?rev=425987&r1=425986&r2=425987&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 Thu Jul 27 00:26:57 2006
@@ -737,18 +737,22 @@
 
 	/**
 		Get the JDBC version, inferring it from the driver.
-		We cannot use the JDBC DatabaseMetaData method
-		as it is not present in JDBC 2.0.
 	*/
 
 	public static int getJDBCMajorVersion(Connection conn)
 	{
 		try {
+			// DatabaseMetaData.getJDBCMajorVersion() was not part of JDBC 2.0.
+			// Check if setSavepoint() is present to decide whether the version
+			// is > 2.0.
 			conn.getClass().getMethod("setSavepoint", null);
-			return 3;
-		} catch (NoSuchMethodException e) {
-			return 2;
-		} catch (NoClassDefFoundError e2) {
+			DatabaseMetaData meta = conn.getMetaData();
+			Method method =
+				meta.getClass().getMethod("getJDBCMajorVersion", null);
+			return ((Number) method.invoke(meta, null)).intValue();
+		} catch (Throwable t) {
+			// Error probably means that either setSavepoint() or
+			// getJDBCMajorVersion() is not present. Assume JDBC 2.0.
 			return 2;
 		}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml?rev=425987&r1=425986&r2=425987&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/build.xml Thu Jul 27 00:26:57 2006
@@ -67,7 +67,6 @@
       <include name="${this.dir}/StaticInitializers/*.java"/> 
       <include name="${this.dir}/VTIClasses/*.java"/> 
       <include name="${this.dir}/corruptio/*.java"/>
-      <exclude name="${this.dir}/TestUtil.java"/>
       <exclude name="${this.dir}/XATestUtil.java"/>
     </javac>
     <javac
@@ -87,7 +86,6 @@
         <pathelement path="${java14compile.classpath}"/>
       </classpath>
       <!--exclude name=""/-->
-      <include name="${this.dir}/TestUtil.java"/>
 	  <include name="${this.dir}/XATestUtil.java"/>
     </javac>
   </target>