db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r681697 - in /db/derby/code/branches/10.4/java: client/org/apache/derby/client/am/CallableLocatorProcedures.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Date Fri, 01 Aug 2008 13:59:07 GMT
Author: kristwaa
Date: Fri Aug  1 06:59:07 2008
New Revision: 681697

URL: http://svn.apache.org/viewvc?rev=681697&view=rev
Log:
DERBY-3799: NullPointerException when accessing a clob through a pooled connection.
Backported revision 681694 (derby-3799-1a-checkIfClosed.diff) from trunk.

Modified:
    db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java
    db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java

Modified: db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java?rev=681697&r1=681696&r2=681697&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java
(original)
+++ db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/CallableLocatorProcedures.java
Fri Aug  1 06:59:07 2008
@@ -113,7 +113,8 @@
         }
         
         try {
-            if (blobCreateLocatorCall == null) {
+            if (blobCreateLocatorCall == null ||
+                    !blobCreateLocatorCall.openOnClient_) {
                 blobCreateLocatorCall = connection.prepareCallX
                         ("? = CALL SYSIBM.BLOBCREATELOCATOR()",
                         java.sql.ResultSet.TYPE_FORWARD_ONLY,
@@ -164,7 +165,8 @@
      */
     void blobReleaseLocator(int locator) throws SqlException
     {
-        if (blobReleaseLocatorCall == null) {
+        if (blobReleaseLocatorCall == null ||
+                !blobReleaseLocatorCall.openOnClient_) {
             blobReleaseLocatorCall = connection.prepareCallX
                 ("CALL SYSIBM.BLOBRELEASELOCATOR(?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -200,7 +202,8 @@
                                     int searchLocator, 
                                     long fromPosition) throws SqlException
     {
-        if (blobGetPositionFromLocatorCall == null) {
+        if (blobGetPositionFromLocatorCall == null ||
+                !blobGetPositionFromLocatorCall.openOnClient_) {
             blobGetPositionFromLocatorCall = connection.prepareCallX
                 ("? = CALL SYSIBM.BLOBGETPOSITIONFROMLOCATOR(?, ?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -327,7 +330,8 @@
                                           int offset,
                                           int length) throws SqlException
     {
-        if (blobGetPositionFromBytesCall == null) {
+        if (blobGetPositionFromBytesCall == null ||
+                !blobGetPositionFromBytesCall.openOnClient_) {
             blobGetPositionFromBytesCall = connection.prepareCallX
                 ("? = CALL SYSIBM.BLOBGETPOSITIONFROMBYTES(?, ?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -371,7 +375,7 @@
      */
     long blobGetLength(int sourceLocator) throws SqlException
     {
-        if (blobGetLengthCall == null) {
+        if (blobGetLengthCall == null || !blobGetLengthCall.openOnClient_) {
             blobGetLengthCall = connection.prepareCallX
                 ("? = CALL SYSIBM.BLOBGETLENGTH(?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -421,7 +425,7 @@
     {
         if (forLength == 0) return new byte[0];
         
-        if (blobGetBytesCall == null) {
+        if (blobGetBytesCall == null || !blobGetBytesCall.openOnClient_) {
             blobGetBytesCall = connection.prepareCallX
                 ("? = CALL SYSIBM.BLOBGETBYTES(?, ?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -495,7 +499,7 @@
                       int forLength, 
                       byte[] bytes) throws SqlException
     {
-        if (blobSetBytesCall == null) {
+        if (blobSetBytesCall == null || !blobSetBytesCall.openOnClient_) {
             blobSetBytesCall = connection.prepareCallX
                 ("CALL SYSIBM.BLOBSETBYTES(?, ?, ?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -551,7 +555,7 @@
      */
     void blobTruncate(int sourceLocator, long length) throws SqlException
     {
-        if (blobTruncateCall == null) {
+        if (blobTruncateCall == null || !blobTruncateCall.openOnClient_) {
             blobTruncateCall = connection.prepareCallX
                 ("CALL SYSIBM.BLOBTRUNCATE(?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -590,7 +594,8 @@
         }
         
         try {
-            if (clobCreateLocatorCall == null) {
+            if (clobCreateLocatorCall == null ||
+                    !clobCreateLocatorCall.openOnClient_) {
                 clobCreateLocatorCall = connection.prepareCallX
                         ("? = CALL SYSIBM.CLOBCREATELOCATOR()",
                         java.sql.ResultSet.TYPE_FORWARD_ONLY,
@@ -641,7 +646,8 @@
      */
     void clobReleaseLocator(int locator) throws SqlException
     {
-        if (clobReleaseLocatorCall == null) {
+        if (clobReleaseLocatorCall == null ||
+                !clobReleaseLocatorCall.openOnClient_) {
             clobReleaseLocatorCall = connection.prepareCallX
                 ("CALL SYSIBM.CLOBRELEASELOCATOR(?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -760,7 +766,8 @@
                                            int offset,
                                            int length) throws SqlException
     {
-        if (clobGetPositionFromStringCall == null) {
+        if (clobGetPositionFromStringCall == null ||
+                !clobGetPositionFromStringCall.openOnClient_) {
             clobGetPositionFromStringCall = connection.prepareCallX
                 ("? = CALL SYSIBM.CLOBGETPOSITIONFROMSTRING(?, ?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -809,7 +816,8 @@
                                     int searchLocator, 
                                     long fromPosition) throws SqlException
     {
-        if (clobGetPositionFromLocatorCall == null) {
+        if (clobGetPositionFromLocatorCall == null ||
+                !clobGetPositionFromLocatorCall.openOnClient_) {
             clobGetPositionFromLocatorCall = connection.prepareCallX
                 ("? = CALL SYSIBM.CLOBGETPOSITIONFROMLOCATOR(?, ?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -843,7 +851,7 @@
      */
     long clobGetLength(int sourceLocator) throws SqlException
     {
-        if (clobGetLengthCall == null) {
+        if (clobGetLengthCall == null || !clobGetLengthCall.openOnClient_) {
             clobGetLengthCall = connection.prepareCallX
                 ("? = CALL SYSIBM.CLOBGETLENGTH(?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -893,7 +901,8 @@
     {
         if (forLength == 0) return "";
 
-        if (clobGetSubStringCall == null) {
+        if (clobGetSubStringCall == null ||
+                !clobGetSubStringCall.openOnClient_) {
             clobGetSubStringCall = connection.prepareCallX
                 ("? = CALL SYSIBM.CLOBGETSUBSTRING(?, ?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -969,7 +978,7 @@
                        int forLength, 
                        String string) throws SqlException
     {
-        if (clobSetStringCall == null) {
+        if (clobSetStringCall == null || !clobSetStringCall.openOnClient_) {
             clobSetStringCall = connection.prepareCallX
                 ("CALL SYSIBM.CLOBSETSTRING(?, ?, ?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 
@@ -1021,7 +1030,7 @@
      */
     void clobTruncate(int sourceLocator, long length) throws SqlException
     {
-        if (clobTruncateCall == null) {
+        if (clobTruncateCall == null || !clobTruncateCall.openOnClient_) {
             clobTruncateCall = connection.prepareCallX
                 ("CALL SYSIBM.CLOBTRUNCATE(?, ?)",
                  java.sql.ResultSet.TYPE_FORWARD_ONLY, 

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=681697&r1=681696&r2=681697&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Fri Aug  1 06:59:07 2008
@@ -148,6 +148,7 @@
         suite.addTest(new J2EEDataSourceTest("testPooledReuseOnClose"));
         suite.addTest(new J2EEDataSourceTest("testSchemaIsReset"));
         suite.addTest(new J2EEDataSourceTest("testSchemaIsResetWhenDeleted"));
+        suite.addTest(new J2EEDataSourceTest("testDerby3799"));
         return suite;
     }
 
@@ -236,6 +237,9 @@
                             "'org.apache.derbyTesting.functionTests.tests.jdbcapi.J2EEDataSourceTest."
+
                             getNestedMethodName() +
                     "'");
+                    s.execute("create table derby3799 (dClob clob)");
+                    s.executeUpdate("insert into derby3799 values (" +
+                            "'myLittleTestClob')");
                 }
             };
         }
@@ -2901,6 +2905,34 @@
     }
     
     /**
+     * Regression test for a NullPointerException when trying to use the LOB
+     * stored procedures after closing and then getting a new logical
+     * connection. The problem was that the LOB stored procedure objects on the
+     * server side were closed and not reprepared.
+     * See Jira issue DERBY-3799.
+     */
+    public void testDerby3799() throws SQLException {
+        ConnectionPoolDataSource cpDs =
+                J2EEDataSource.getConnectionPoolDataSource();
+        PooledConnection pc = cpDs.getPooledConnection();
+        // Get first logical connection.
+        Connection con1 = pc.getConnection();
+        Statement stmt = con1.createStatement();
+        ResultSet rs = stmt.executeQuery("select dClob from derby3799");
+        assertTrue(rs.next());
+        rs.getString(1);
+        rs.close();
+        con1.close();
+        // Get second logical connection.
+        Connection con2 = pc.getConnection();
+        stmt = con2.createStatement();
+        rs = stmt.executeQuery("select dClob from derby3799");
+        assertTrue(rs.next());
+        rs.getString(1); // NPE happened here.
+        con2.close();
+    }
+
+    /**
      * Tests for DERBY-1144
      * 
      * This test tests that holdability, autocomit, and transactionIsolation 



Mime
View raw message