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/16 09:53:05 UTC

svn commit: r386290 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/

Author: kahatlen
Date: Thu Mar 16 00:53:02 2006
New Revision: 386290

URL: http://svn.apache.org/viewcvs?rev=386290&view=rev
Log:
DERBY-970 (partial): Add new metadata methods to network client driver

This patch implements the following new JDBC 4 DatabaseMetaData
methods in the client driver:

  - getRowIdLifetime() - returns RowIdLifetime.ROWID_UNSUPPORTED

  - supportsStoredFunctionsUsingCallSyntax() - returns true

  - autoCommitFailureClosesAllResultSets() - returns false

  - providesQueryObjectGenerator() - returns false

Canon for jdbc4/TestDbMetaData.java is updated to reflect that the
methods are implemented on the client.

New test cases added to TestDbMetaData:

  - try to execute a stored procedure using the escape syntax, and see
    if the success/failure corresponds to the value returned by
    supportsStoredFunctionsUsingCallSyntax()

  - open a holdable result set in auto-commit mode and, on the same
    connection, execute a query which causes SQLException. Check
    whether the result set is open or closed, and see if the state
    corresponds to the value returned by
    autoCommitFailureClosesAllResultSets()

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetDatabaseMetaData40.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TestDbMetaData.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java?rev=386290&r1=386289&r2=386290&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java Thu Mar 16 00:53:02 2006
@@ -2312,6 +2312,50 @@
         }
     }
 
+    // ------------------- JDBC 4.0 -------------------------
+
+    /**
+     * Retrieves whether this database supports invoking user-defined
+     * or vendor functions using the stored procedure escape syntax.
+     *
+     * @return <code>true</code>, since Derby supports the escape syntax
+     * @exception SQLException if a database access error occurs
+     */
+    public final boolean supportsStoredFunctionsUsingCallSyntax()
+        throws SQLException
+    {
+        checkForClosedConnection();
+        return true;
+    }
+
+    /**
+     * Retrieves whether an <code>SQLException</code> will cause all
+     * open <code>ResultSet</code>s to be closed when auto-commit is
+     * <code>true</code>.
+     *
+     * @return <code>false</code>, since Derby does not close all open
+     * result sets when an error occurs
+     * @exception SQLException if a database access error occurs
+     */
+    public final boolean autoCommitFailureClosesAllResultSets()
+        throws SQLException
+    {
+        checkForClosedConnection();
+        return false;
+    }
+
+    /**
+     * Retrieves whether this JDBC driver provides its own
+     * <code>QueryObjectGenerator</code>.
+     *
+     * @return <code>false</code>, since Derby does not provide its
+     * own generator
+     * @exception SQLException if a database access error occurs
+     */
+    public final boolean providesQueryObjectGenerator() throws SQLException {
+        checkForClosedConnection();
+        return false;
+    }
 
     //----------------------------helper methods----------------------------------
 
@@ -2334,7 +2378,7 @@
      * SQLException instead of SqlException.  In particular this is used
      * by all the DatabaseMetadata methods
      */
-    private void checkForClosedConnection() throws SQLException
+    protected void checkForClosedConnection() throws SQLException
     {
         try {
             checkForClosedConnectionX();

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetDatabaseMetaData40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetDatabaseMetaData40.java?rev=386290&r1=386289&r2=386290&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 Mar 16 00:53:02 2006
@@ -32,32 +32,25 @@
         super(netAgent,netConnection);
     }
     
+    /**
+     * Indicates whether or not this data source supports the SQL
+     * <code>ROWID</code> type. Since Derby does not support the
+     * <code>ROWID</code> type, return <code>ROWID_UNSUPPORTED</code>.
+     *
+     * @return <code>ROWID_UNSUPPORTED</code>
+     * @exception SQLException if a database access error occurs
+     */
     public RowIdLifetime getRowIdLifetime() throws SQLException {
-	throw SQLExceptionFactory.notImplemented ("getRowIdLifetime ()");
-        
+        checkForClosedConnection();
+        return RowIdLifetime.ROWID_UNSUPPORTED;
     }
     
     public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
         throw SQLExceptionFactory.notImplemented ("getSchemas (String, String)");
     }
     
-    
-    public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
-        throw SQLExceptionFactory.notImplemented (
-                "supportsStoredFunctionsUsingCallSyntax ()");
-    }
-    
-    public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
-        throw SQLExceptionFactory.notImplemented (
-                "autoCommitFailureClosesAllResultSets ()");
-    }
-    
     public ResultSet getClientInfoProperties()
     throws SQLException {
         throw SQLExceptionFactory.notImplemented ("getClientInfoProperties ()");
-    }
-    
-    public boolean providesQueryObjectGenerator() throws SQLException {
-        throw SQLExceptionFactory.notImplemented ("providesQueryObjectGenerator ()");
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TestDbMetaData.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TestDbMetaData.out?rev=386290&r1=386289&r2=386290&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TestDbMetaData.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TestDbMetaData.out Thu Mar 16 00:53:02 2006
@@ -44,26 +44,6 @@
 SYSSTAT,null
 TABLE_SCHEM,TABLE_CATALOG
 APP,null
-supportsStoredFunctionsUsingCallSyntax():
-FAIL -- unexpected exception
-SQLSTATE(0A000):java.sql.SQLException: 0A000.S : [0] supportsStoredFunctionsUsingCallSyntax ()
-Caused by: org.apache.derby.client.am.SqlException: 0A000.S : [0] supportsStoredFunctionsUsingCallSyntax ()
-	... 4 more
-autoCommitFailureClosesAllResultSets():
-FAIL -- unexpected exception
-SQLSTATE(0A000):java.sql.SQLException: 0A000.S : [0] autoCommitFailureClosesAllResultSets ()
-Caused by: org.apache.derby.client.am.SqlException: 0A000.S : [0] autoCommitFailureClosesAllResultSets ()
-	... 4 more
-providesQueryObjectGenerator():
-FAIL -- unexpected exception
-SQLSTATE(0A000):java.sql.SQLException: 0A000.S : [0] providesQueryObjectGenerator ()
-Caused by: org.apache.derby.client.am.SqlException: 0A000.S : [0] providesQueryObjectGenerator ()
-	... 4 more
-getRowIdLifetime():
-FAIL -- unexpected exception
-SQLSTATE(0A000):java.sql.SQLException: 0A000.S : [0] getRowIdLifetime ()
-Caused by: org.apache.derby.client.am.SqlException: 0A000.S : [0] getRowIdLifetime ()
-	... 4 more
 getClientInfoProperties():
 FAIL -- unexpected exception
 SQLSTATE(0A000):java.sql.SQLException: 0A000.S : [0] getClientInfoProperties ()

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java?rev=386290&r1=386289&r2=386290&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java Thu Mar 16 00:53:02 2006
@@ -56,6 +56,9 @@
     // Run all the tests.
     private static void runTests(Connection con) throws Exception {
         testDatabaseMetaDataMethods(con);
+        testStoredProcEscapeSyntax(con);
+        testAutoCommitFailure(con);
+        con.close();
     }
 
     // Simply call each new metadata method and print the result.
@@ -66,52 +69,28 @@
         Statement s = con.createStatement();
         DatabaseMetaData met = con.getMetaData();
 
-        try {
-            if (!met.supportsStoredFunctionsUsingCallSyntax()) {
-                System.out.println
-                    ("FAIL: supportsStoredFunctionsUsingCallSyntax() " +
-                     "should return true");
-            }
-        } catch (SQLException e) {
-            // TODO: remove try/catch once method is implemented!
-            System.out.println("supportsStoredFunctionsUsingCallSyntax():");
-            dumpSQLExceptions(e);
+        if (!met.supportsStoredFunctionsUsingCallSyntax()) {
+            System.out.println
+                ("FAIL: supportsStoredFunctionsUsingCallSyntax() " +
+                 "should return true");
         }
 
-        try {
-            if (met.autoCommitFailureClosesAllResultSets()) {
-                System.out.println
-                    ("FAIL: autoCommitFailureClosesAllResultSets() " +
-                     "should return false");
-            }
-        } catch (SQLException e) {
-            // TODO: remove try/catch once method is implemented!
-            System.out.println("autoCommitFailureClosesAllResultSets():");
-            dumpSQLExceptions(e);
+        if (met.autoCommitFailureClosesAllResultSets()) {
+            System.out.println
+                ("FAIL: autoCommitFailureClosesAllResultSets() " +
+                 "should return false");
         }
 
-        try {
-            if (met.providesQueryObjectGenerator()) {
-                System.out.println
-                    ("FAIL: providesQueryObjectGenerator() should " +
-                     "return false");
-            }
-        } catch (SQLException e) {
-            // TODO: remove try/catch once method is implemented!
-            System.out.println("providesQueryObjectGenerator():");
-            dumpSQLExceptions(e);
+        if (met.providesQueryObjectGenerator()) {
+            System.out.println
+                ("FAIL: providesQueryObjectGenerator() should " +
+                 "return false");
         }
 
-        try {
-            RowIdLifetime lifetime = met.getRowIdLifetime();
-            if (lifetime != RowIdLifetime.ROWID_UNSUPPORTED) {
-                System.out.println("FAIL: getRowIdLifetime() should return " +
-                                   "ROWID_UNSUPPORTED, but got " + lifetime);
-            }
-        } catch (SQLException e) {
-            // TODO: remove try/catch once method is implemented!
-            System.out.println("getRowIdLifetime():");
-            dumpSQLExceptions(e);
+        RowIdLifetime lifetime = met.getRowIdLifetime();
+        if (lifetime != RowIdLifetime.ROWID_UNSUPPORTED) {
+            System.out.println("FAIL: getRowIdLifetime() should return " +
+                               "ROWID_UNSUPPORTED, but got " + lifetime);
         }
 
         try {
@@ -206,9 +185,85 @@
         }
 
         s.close();
+    }
 
-        con.close();
+    /**
+     * Test supportsStoredFunctionsUsingCallSyntax() by checking
+     * whether calling a stored procedure using the escape syntax
+     * succeeds.
+     *
+     * @param con <code>Connection</code> object used in test
+     * @exception SQLException if an unexpected database error occurs
+     */
+    private static void testStoredProcEscapeSyntax(Connection con)
+        throws SQLException
+    {
+        con.setAutoCommit(false);
+        String call = "{CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(0)}";
+        Statement stmt = con.createStatement();
+
+        boolean success;
+        try {
+            stmt.execute(call);
+            success = true;
+        } catch (SQLException e) {
+            success = false;
+        }
+
+        DatabaseMetaData dmd = con.getMetaData();
+        boolean supported = dmd.supportsStoredFunctionsUsingCallSyntax();
+        if (success != supported) {
+            System.out.println("supportsStoredFunctionsUsingCallSyntax() " +
+                               "returned " + supported + ", but executing " +
+                               call + (success ? " succeeded." : " failed."));
+        }
+        stmt.close();
+        con.rollback();
+    }
+
+    /**
+     * Test autoCommitFailureClosesAllResultSets() by checking whether
+     * a failure in auto-commit mode will close all result sets, even
+     * holdable ones.
+     *
+     * @param con <code>Connection</code> object used in test
+     * @exception SQLException if an unexpected database error occurs
+     */
+    private static void testAutoCommitFailure(Connection con)
+        throws SQLException
+    {
+        DatabaseMetaData dmd = con.getMetaData();
+        boolean shouldBeClosed = dmd.autoCommitFailureClosesAllResultSets();
+
+        con.setAutoCommit(true);
 
+        Statement s1 =
+            con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+                                ResultSet.CONCUR_READ_ONLY,
+                                ResultSet.HOLD_CURSORS_OVER_COMMIT);
+        ResultSet resultSet = s1.executeQuery("VALUES (1, 2), (3, 4)");
+
+        Statement s2 = con.createStatement();
+        try {
+            String query =
+                "SELECT dummy, nonexistent, phony FROM imaginarytable34521";
+            s2.execute(query);
+            System.out.println("\"" + query + "\" is expected to fail, " +
+                               "but it didn't.");
+        } catch (SQLException e) {
+            // should fail, but we don't care how
+        }
+
+        boolean isClosed = resultSet.isClosed();
+        if (isClosed != shouldBeClosed) {
+            System.out.println("autoCommitFailureClosesAllResultSets() " +
+                               "returned " + shouldBeClosed +
+                               ", but ResultSet is " +
+                               (isClosed ? "closed." : "not closed."));
+        }
+        resultSet.close();
+        s1.close();
+        s2.close();
     }
 
 	static private void dumpSQLExceptions (SQLException se) {