db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r601044 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbcapi/AutoGenJDBC30Test.java junit/JDBC.java
Date Tue, 04 Dec 2007 19:15:14 GMT
Author: djd
Date: Tue Dec  4 11:15:13 2007
New Revision: 601044

URL: http://svn.apache.org/viewvc?rev=601044&view=rev
Log:
Add JDBC.assertGeneratedKeyResultSet() to verify the type and concurrency of ResultSets returned
by Statement.getGeneratedKeys. Add a commented out test case in AutoGenJDBC30Test.java that
shows the bug DERBY-3249.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java?rev=601044&r1=601043&r2=601044&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/AutoGenJDBC30Test.java
Tue Dec  4 11:15:13 2007
@@ -395,6 +395,18 @@
         assertEquals("Key value after ps.executeUpdate()", 4, keyval);
 
         ps.close();
+        
+        /*
+        DERBY-3249 - Returned generated key result sets have the wrong
+        concurrency. Test should be expanded to handle all concurrencies/types.
+        
+        // Test the type of the Statement object does not affect the
+        // type of the generated key ResultSet (checked in getKeyValue)
+        s = this.createStatement(ResultSet.CONCUR_UPDATABLE, ResultSet.TYPE_SCROLL_INSENSITIVE);
+        s.execute(sql, Statement.RETURN_GENERATED_KEYS);
+        keyval = getKeyValue(s.getGeneratedKeys());
+        assertEquals("Key value after s.execute()", 5, keyval);
+        */
     }
 
 
@@ -1438,7 +1450,8 @@
     public void verifyNullKey (String description, ResultSet r) 
         throws SQLException
     {
-        assertNotNull(description, r);
+        JDBC.assertGeneratedKeyResultSet(description, r);
+
         int i = 0;
         while(r.next())
         {
@@ -1456,7 +1469,8 @@
      */
     public int getKeyValue (ResultSet r) throws SQLException
     {
-        assertNotNull("ResultSet is NULL", r);
+        JDBC.assertGeneratedKeyResultSet("AutoGenJDBC30Test.getKeyValue", r);
+        
         int i = 0;
         int retval = 0;
         while(r.next())

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java?rev=601044&r1=601043&r2=601044&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBC.java Tue Dec  4 11:15:13
2007
@@ -510,6 +510,40 @@
         
     }
     
+    /**
+     * Assert that a ResultSet representing generated keys is non-null
+     * and of the correct type. This method leaves the ResultSet
+     * open and does not fetch any date from it.
+     * 
+     * @param description For assert messages
+     * @param keys ResultSet returned from getGeneratedKeys().
+     * @throws SQLException
+     */
+    public static void assertGeneratedKeyResultSet(
+            String description, ResultSet keys) throws SQLException
+    {
+        
+        Assert.assertNotNull(description, keys);
+        
+        // Requirements from section 13.6 JDBC 4 specification
+        Assert.assertEquals(
+                description + 
+                " - Required CONCUR_READ_ONLY for generated key result sets",
+                ResultSet.CONCUR_READ_ONLY, keys.getConcurrency());
+        
+        int type = keys.getType();
+        if ( (type != ResultSet.TYPE_FORWARD_ONLY) &&
+             (type != ResultSet.TYPE_SCROLL_INSENSITIVE))
+        {
+            Assert.fail(description +
+                    " - Invalid type for generated key result set" + type);
+        }
+        
+        
+
+    }
+    
+    
 	/**
 	 * Drain a single ResultSet by reading all of its
 	 * rows and columns. Each column is accessed using



Mime
View raw message