db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r544481 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Tue, 05 Jun 2007 13:24:14 GMT
Author: kahatlen
Date: Tue Jun  5 06:24:13 2007
New Revision: 544481

URL: http://svn.apache.org/viewvc?view=rev&rev=544481
Log:
DERBY-2702: Enable Clob locator support between NetworkServer and NetworkClient

Patch contributed by V. Narayanan.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java?view=diff&rev=544481&r1=544480&r2=544481
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java Tue Jun  5
06:24:13 2007
@@ -2189,7 +2189,7 @@
         //The code here has been disabled because the Lob implementations
         //have still not been completely converted to use locators. Once
         //the Lob implementations are completed then this code can be enabled.
-        if (locator != INVALID_LOCATOR && false) {
+        if (locator != INVALID_LOCATOR) {
             //A valid locator value has been obtained.
             clob = new org.apache.derby.client.am.Clob(this.agent_, locator);
         }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java?view=diff&rev=544481&r1=544480&r2=544481
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java Tue
Jun  5 06:24:13 2007
@@ -640,11 +640,8 @@
  
                 case java.sql.Types.CLOB:
                     lidAndLengths[i][0] = (resultSetMetaData.nullable_[i])
-                    // Locators for Clob has not yet been implemented
-//                            ? DRDAConstants.DRDA_TYPE_NLOBLOC
-//                            : DRDAConstants.DRDA_TYPE_LOBLOC;
-                            ? DRDAConstants.DRDA_TYPE_NLOBCMIXED
-                            : DRDAConstants.DRDA_TYPE_LOBCMIXED;
+                            ? DRDAConstants.DRDA_TYPE_NCLOBLOC
+                            : DRDAConstants.DRDA_TYPE_CLOBLOC;
                     lidAndLengths[i][1] = 4;
                     break;
             }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java?view=diff&rev=544481&r1=544480&r2=544481
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java
Tue Jun  5 06:24:13 2007
@@ -154,6 +154,10 @@
     
     public void setUp() 
         throws SQLException {
+        // Life span of Clob objects are limited by the transaction.  Need
+        // autocommit off so Clob objects survive closing of result set.
+        getConnection().setAutoCommit(false);
+
         clob = BlobClobTestSetup.getSampleClob(getConnection());
         
         //call the buildHashSetMethod to initialize the 
@@ -429,10 +433,10 @@
         String str2 = str1.substring(1,6);
         Reader r_2 = new java.io.StringReader(str2);
 
+        assertEquals(r_2,r_1);
+
         rs.close();
         st.close();
-
-        assertEquals(r_2,r_1);
     }
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java?view=diff&rev=544481&r1=544480&r2=544481
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
Tue Jun  5 06:24:13 2007
@@ -401,6 +401,10 @@
      */
     public void testSetClob()
             throws IOException, SQLException {
+        // Life span of Clob objects are limited by the transaction.  Need
+        // autocommit off so Clob objects survive execution of next statement.
+        getConnection().setAutoCommit(false);
+
         //insert default values into the table
         
         String str = "Test data for the Clob object";
@@ -440,34 +444,30 @@
      * Insert <code>Clob</code> without specifying length and read it back
      * for verification.
      *
-     * Beacuse we don't yet support <code>Connection.createClob</code> in the
-     * client driver, we must first insert data into the database and read back
-     * a <code>Clob</code> object. This object is then inserted into the
-     * database again.
+     * @throws IOException If an IOException during the close operation on the
+     *                     reader.
+     * @throws SQLException If an SQLException occurs.
      */
     public void testSetClobLengthless()
             throws IOException, SQLException {
-        // Insert test data.
-        String testString = "Test string for setCharacterStream\u1A00";
-        Reader reader = new StringReader(testString);
+        // Life span of Clob objects are the transaction.  Need autocommit off
+        // to have Clob objects survive execution of next statement.
+        getConnection().setAutoCommit(false);
+
+        //Create the Clob and insert data into it.
+        Clob insertClob = getConnection().createClob();
+        OutputStream os = insertClob.setAsciiStream(1);
+        os.write(BYTES);
+
+        //Insert the Clob created above into the
+        //database.
         psInsertClob.setInt(1, key);
-        psInsertClob.setCharacterStream(2, reader);
-        psInsertClob.execute();
-        reader.close();
-        // Must fetch Clob from database because we don't support
-        // Connection.createClob on the client yet.
-        psFetchClob.setInt(1, key);
-        ResultSet rs = psFetchClob.executeQuery();
-        assertTrue("No results retrieved", rs.next());
-        int secondKey = requestKey();
-        Clob insertClob = rs.getClob(1);
-        psInsertClob.setInt(1, secondKey);
         psInsertClob.setClob(2, insertClob);
         psInsertClob.execute();
 
         // Read back test data from database.
-        psFetchClob.setInt(1, secondKey);
-        rs = psFetchClob.executeQuery();
+        psFetchClob.setInt(1, key);
+        ResultSet rs = psFetchClob.executeQuery();
         assertTrue("No results retrieved", rs.next());
         Clob clobRetrieved = rs.getClob(1);
 
@@ -658,12 +658,18 @@
         ResultSet rs = psFetchClob.executeQuery();
         rs.next();
         Clob clobRetrieved = rs.getClob(1);
-        rs.close();
         
         String str_out = clobRetrieved.getSubString(1L,(int)clobRetrieved.length());
         
         assertEquals("Error in inserting data into the Clob object",str,str_out);
         psInsertClob.close();
+
+        //Since auto-commit is true in this test
+        //this will invalidate the clob object
+        //Hence closing the ResultSet after
+        //accessing the Clob object.
+        //follows the same pattern as testSetBinaryStream().
+        rs.close();
     }
 
     public void testSetCharacterStreamLengthless()
@@ -714,7 +720,6 @@
         ResultSet rs = psFetchClob.executeQuery();
         rs.next();
         Clob ClobRetrieved = rs.getClob(1);
-        rs.close();
         
         try {
             InputStream is_ret = ClobRetrieved.getAsciiStream();
@@ -726,6 +731,13 @@
             assertEquals("Error in inserting data into the Clob",BYTES[i],bytes1[i]);
         }
         psInsertClob.close();
+
+        //Since auto-commit is true in this test
+        //this will invalidate the clob object
+        //Hence closing the ResultSet after
+        //accessing the Clob object.
+        //follows the same pattern as testSetBinaryStream().
+        rs.close();
     }
 
     public void testSetAsciiStreamLengthless()

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java?view=diff&rev=544481&r1=544480&r2=544481
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
Tue Jun  5 06:24:13 2007
@@ -921,6 +921,10 @@
      */
     public void testUpdateClob()
     throws Exception {
+        // Life span of Clob objects are limited by the transaction.  Need
+        // autocommit off so Clob objects survive execution of next statement.
+        getConnection().setAutoCommit(false);
+
         //Byte array in which the returned bytes from
         //the Database after the update are stored. This
         //array is then checked to determine if it
@@ -982,6 +986,10 @@
 
     public void testUpdateClobLengthless()
             throws Exception {
+        // Life span of Clob objects are limited by the transaction.  Need
+        // autocommit off so Clob objects survive execution of next statement.
+        getConnection().setAutoCommit(false);
+
         Reader r1 = new java.io.StringReader(new String(BYTES1));
         // InputStream for insertion.
         Reader r2 = new java.io.StringReader(new String(BYTES2));
@@ -1214,6 +1222,10 @@
      */
     public void testUpdateClobStringParameterName()
     throws Exception {
+        // Life span of Clob objects are limited by the transaction.  Need
+        // autocommit off so Clob objects survive execution of next statement.
+        getConnection().setAutoCommit(false);
+
         //Byte array in which the returned bytes from
         //the Database after the update are stored. This
         //array is then checked to determine if it

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java?view=diff&rev=544481&r1=544480&r2=544481
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BlobClob4BlobTest.java
Tue Jun  5 06:24:13 2007
@@ -1230,65 +1230,89 @@
         rs.close();
         stmt.close();
         commit();
-        // no problem accessing this after commit since it is in memory
-        assertEquals("FAIL - can not access short clob after commit",
-                26, shortClob.length());
+        assertTrue("FAIL - shortClob is NULL", shortClob != null);
+        // this should give blob/clob unavailable exceptions on client
+        try {
+            shortClob.length();
+            //Check to see if we are running in the client
+            //and a SQLException has not been thrown.
+            if (usingDerbyNetClient()) {
+                //Should have thrown an SQLException in the
+                //Network Client.
+                fail("FAIL - should not be able to access Clob after commit");
+            }
+        } catch (SQLException e) {
+            //The same SQLState String BLOB_ACCESSED_AFTER_COMMIT
+            //is used for LOB's(Both Clob and Blob). Ensure that
+            //we get the expected exception by comparing the SQLState.
+            checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
+            //In the embedded clobs of small size are
+            //accessible after commit. Hence ensure that
+            //we are dealing with the Embedded side here.
+            assertTrue("FAIL - method should not fail when using embedded",
+                       usingDerbyNetClient());
+        }
 
         // these should all give blob/clob data unavailable exceptions
         try {
             clob.length();
-            if (usingEmbedded()) {
-                fail("FAIL - should not be able to access large log " +
-                        "after commit");
-            }
-        } catch (SQLException e) {
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after commit. Should have thrown
+            //an SQLException here.
+            fail("FAIL - should not be able to access large Clob after commit");
+        } catch (SQLException e) {
+            //The same SQLState String BLOB_ACCESSED_AFTER_COMMIT
+            //is used for LOB's(Both Clob and Blob). Ensure that
+            //we get the expected exception by comparing the SQLState.
             checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            assertTrue("FAIL - Derby Client and JCC should not get an " +
-                    "exception", usingEmbedded());
         }
         try {
             clob.getSubString(2,3);
-            if (usingEmbedded()) {
-                fail("FAIL - should not be able to access large log " +
-                        "after commit");
-            }
-        } catch (SQLException e) {
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after commit. Should have thrown
+            //an SQLException here.
+            fail("FAIL - should not be able to access large Clob after commit");
+        } catch (SQLException e) {
+            //The same SQLState String BLOB_ACCESSED_AFTER_COMMIT
+            //is used for LOB's(Both Clob and Blob). Ensure that
+            //we get the expected exception by comparing the SQLState.
             checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            assertTrue("FAIL - Derby Client and JCC should not get an " +
-                    "exception", usingEmbedded());
         }
         try {
             clob.getAsciiStream();
-            if (usingEmbedded()) {
-                fail("FAIL - should not be able to access large log " +
-                        "after commit");
-            }
-        } catch (SQLException e) {
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after commit. Should have thrown
+            //an SQLException here.
+            fail("FAIL - should not be able to access large Clob after commit");
+        } catch (SQLException e) {
+            //The same SQLState String BLOB_ACCESSED_AFTER_COMMIT
+            //is used for LOB's(Both Clob and Blob). Ensure that
+            //we get the expected exception by comparing the SQLState.
             checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            assertTrue("FAIL - Derby Client and JCC should not get an " +
-                    "exception", usingEmbedded());
         }
         try {
             clob.position("foo",2);
-            if (usingEmbedded()) {
-                fail("FAIL - should not be able to access large log " +
-                        "after commit");
-            }
-        } catch (SQLException e) {
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after commit. Should have thrown
+            //an SQLException here.
+            fail("FAIL - should not be able to access large Clob after commit");
+        } catch (SQLException e) {
+            //The same SQLState String BLOB_ACCESSED_AFTER_COMMIT
+            //is used for LOB's(Both Clob and Blob). Ensure that
+            //we get the expected exception by comparing the SQLState.
             checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            assertTrue("FAIL - Derby Client and JCC should not get an " +
-                    "exception", usingEmbedded());
         }
         try {
             clob.position(clob,2);
-            if (usingEmbedded()) {
-                fail("FAIL - should not be able to access large log " +
-                        "after commit");
-            }
-        } catch (SQLException e) {
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after commit. Should have thrown
+            //an SQLException here.
+            fail("FAIL - should not be able to access large Clob after commit");
+        } catch (SQLException e) {
+            //The same SQLState String BLOB_ACCESSED_AFTER_COMMIT
+            //is used for LOB's(Both Clob and Blob). Ensure that
+            //we get the expected exception by comparing the SQLState.
             checkException(BLOB_ACCESSED_AFTER_COMMIT, e);
-            assertTrue("FAIL - Derby Client and JCC should not get an " +
-                    "exception", usingEmbedded());
         }
     }
 
@@ -1317,58 +1341,77 @@
 
         try {
             long len = shortClob.length();
-            if (usingEmbedded()) {
-                fail("FAIL - should not be able to access large log " +
-                        "after commit");
-            }
-            assertEquals ("FAIL length mismatch", 26, len);
+            //Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after closing the
+            //connection. Should have thrown an SQLException here.
+            fail("FAIL - should not be able to access Clob after " +
+                    "Connection Close");
         }
         catch (SQLException e) {
+            //Ensure that we get the expected exception by comparing
+            //the SQLState.
             checkException(NO_CURRENT_CONNECTION, e);
-            assertTrue("FAIL - Derby Client and JCC should not get an " +
-                    "exception", usingEmbedded());
         }
 
         // these should all give blob/clob data unavailable exceptions
         try {
             clob.length();
-            if (usingEmbedded()) {
-                fail("FAIL - should not be able to access large lob " +
-                        "after the connection is closed");
-            }
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after Connection Close. Should
+            //have thrown an SQLException here.
+            fail("FAIL - should not be able to access large " +
+                    "Clob after Connection Close");
         } catch (SQLException e) {
+            //Ensure that we get the expected exception by comparing
+            //the SQLState.
             checkException(NO_CURRENT_CONNECTION, e);
-            assertTrue("FAIL - Derby Net and JCC should not get an exception",
-                    usingEmbedded());
         }
         try {
             clob.getSubString(2,3);
-            fail("FAIL - should not be able to access large lob " +
-                    "after the connection is closed");
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after Connection Close. Should
+            //have thrown an SQLException here.
+            fail("FAIL - should not be able to access large " +
+                    "Clob after Connection Close");
         } catch (SQLException e) {
+            //Ensure that we get the expected exception by comparing
+            //the SQLState.
             checkException(NO_CURRENT_CONNECTION, e);
         }
         try {
             clob.getAsciiStream();
-            fail("FAIL - should not be able to access large lob " +
-                    "after the connection is closed");
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after Connection Close. Should
+            //have thrown an SQLException here.
+            fail("FAIL - should not be able to access large " +
+                    "Clob after Connection Close");
         } catch (SQLException e) {
+            //Ensure that we get the expected exception by comparing
+            //the SQLState.
             checkException(NO_CURRENT_CONNECTION, e);
         }
         try {
             clob.position("foo",2);
-            if (usingEmbedded()) {
-                fail("FAIL - should not be able to access large lob " +
-                        "after the connection is closed");
-            }
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after Connection Close. Should
+            //have thrown an SQLException here.
+            fail("FAIL - should not be able to access large " +
+                    "Clob after Connection Close");
         } catch (SQLException e) {
+            //Ensure that we get the expected exception by comparing
+            //the SQLState.
             checkException(NO_CURRENT_CONNECTION, e);
         }
         try {
             clob.position(clob,2);
-            fail("FAIL - should not be able to access large lob " +
-                    "after the connection is closed");
+            //Large Clobs on the Embedded side and the NetworkClient
+            //side are not accessible after Connection Close. Should
+            //have thrown an SQLException here.
+            fail("FAIL - should not be able to access large " +
+                    "Clob after Connection Close");
         } catch (SQLException e) {
+            //Ensure that we get the expected exception by comparing
+            //the SQLState.
             checkException(NO_CURRENT_CONNECTION, e);
         }
     }
@@ -2623,16 +2666,13 @@
                     break;
                 columnSize += size;
             }
-            if (usingEmbedded()) {
-                fail("FAIL - should have got an IOException");
-            } else {
-                assertEquals("FAIL - wrong column size", 10000, columnSize);
-            }
+            fail("FAIL - should have got an IOException");
         } catch (java.io.IOException ioe) {
-            assertTrue("FAIL - only embedded should be this exception",
-                    usingEmbedded());
-            assertEquals("FAIL - wrong exception", "ERROR 40XD0: Container " +
-                    "has been closed.", ioe.getMessage());
+            if(usingEmbedded()) {
+                assertEquals("FAIL - wrong exception",
+                        "ERROR 40XD0: Container has been closed.",
+                        ioe.getMessage());
+            }
         }
 
         rollback();



Mime
View raw message