db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r725620 - in /db/derby/code/branches/10.4/java: client/org/apache/derby/client/am/Clob.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Date Thu, 11 Dec 2008 08:47:56 GMT
Author: kristwaa
Date: Thu Dec 11 00:47:56 2008
New Revision: 725620

URL: http://svn.apache.org/viewvc?rev=725620&view=rev
Log:
DERBY-3978: Clob.truncate(long) in the client driver doesn't update the cached Clob length.
Backported revision 724657 (patches 1a and 2a) from trunk.

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

Modified: db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Clob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Clob.java?rev=725620&r1=725619&r2=725620&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Clob.java (original)
+++ db/derby/code/branches/10.4/java/client/org/apache/derby/client/am/Clob.java Thu Dec 11
00:47:56 2008
@@ -776,10 +776,10 @@
                     //procedure CLOBTRUNCATE to truncate this Lob.
                     agent_.connection_.locatorProcedureCall().
                             clobTruncate(locator_, len);
-                    //The Clob value has been
-                    //modified. Increment the
-                    //update count.
+                    // The Clob value has been modified.
+                    // Increment the update count and update the length.
                     incrementUpdateCount();
+                    setSqlLength(len);
                 }
                 else {
                     //The Lob is not locator enabled.

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java?rev=725620&r1=725619&r2=725620&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Thu Dec 11 00:47:56 2008
@@ -303,6 +303,96 @@
         executeTestPositionWithStringToken(token, prefix);
     }
 
+    /**
+     * Truncating a Clob to the current length should work.
+     */
+    public void testTruncateExactOnDisk()
+            throws IOException, SQLException {
+        long size = 33*1024+7;
+        insertDataWithToken("", size, 0, SET_CHARACTER_STREAM);
+        assertEquals(size, this.clob.length());
+        this.clob.truncate(size);
+        assertEquals(size, this.clob.length());
+    }
+
+    /**
+     * Truncating a Clob to the current length should work.
+     */
+    public void testTruncateExactInMemory()
+            throws IOException, SQLException {
+        long size = 33;
+        insertDataWithToken("", size, 0, SET_STRING);
+        assertEquals(size, this.clob.length());
+        this.clob.truncate(size);
+        assertEquals(size, this.clob.length());
+    }
+
+    /**
+     * Specify a position that is larger then the Clob length.
+     * <p>
+     * This operation should fail and raise an exception.
+     */
+    public void testTruncateTooLongOnDisk()
+            throws IOException, SQLException {
+        long size = 44*1024+8;
+        insertDataWithToken("", size, 0, SET_CHARACTER_STREAM);
+        try {
+            this.clob.truncate(size * 2);
+            fail("Truncate should have failed, position too large");
+        } catch (SQLException sqle) {
+            // See DERBY-3977
+            if (usingEmbedded()) {
+                assertSQLState("XJ076", sqle);
+            } else {
+                assertSQLState("XJ079", sqle);
+            }
+        }
+    }
+
+    /**
+     * Specify a position that is larger then the Clob length.
+     * <p>
+     * This operation should fail and raise an exception.
+     */
+    public void testTruncateTooLongInMemory()
+            throws IOException, SQLException {
+        long size = 44;
+        insertDataWithToken("", size, 0, SET_STRING);
+        try {
+            this.clob.truncate(size * 2);
+            fail("Truncate should have failed, position too large");
+        } catch (SQLException sqle) {
+            // See DERBY-3977
+            if (usingEmbedded()) {
+                assertSQLState("XJ076", sqle);
+            } else {
+                assertSQLState("XJ079", sqle);
+            }
+        }
+    }
+
+    /**
+     * Tests that the length of a Clob isn't cached in such a way that the
+     * length isn't updated after truncation.
+     */
+    public void testGetLengthAfterTruncate()
+            throws IOException, SQLException {
+        final long initialSize =87*1024-2;
+        final long truncateOnceSize = 85*1024+9;
+        final long truncateTwiceSize = 2*1024+17;
+        insertDataWithToken("", initialSize, 0, SET_ASCII_STREAM);
+        // Check initial length.
+        assertEquals(initialSize, clob.length());
+        clob.truncate(truncateOnceSize);
+        assertEquals(truncateOnceSize, clob.length());
+        // This should bring the Clob over into memory again.
+        clob.truncate(truncateTwiceSize);
+        assertEquals(truncateTwiceSize, clob.length());
+        // Truncate again, same length.
+        clob.truncate(truncateTwiceSize);
+        assertEquals(truncateTwiceSize, clob.length());
+    }
+
     /* Test ideas for more tests
      *
      * truncate:
@@ -446,6 +536,20 @@
         return total;
     }
 
+    /**
+     * Inserts data into the test Clob, referenced by {@code this.clob}.
+     *
+     * @param token a token to insert into the Clob, cannot be {@code null} but
+     *      the empty string is accepted
+     * @param pre number of characters to insert before the token, using the
+     *      repeating alphabet stream (latin lower-case)
+     * @param post number of characters to insert after the token, using the
+     *      repeating alphabet stream (latin lower-case)
+     * @param mode insertion mode; SET_STRING, SET_ASCII_STREAM or
+     *      SET_CHARACTER_STREAM
+     * @throws IOException if inserting data fails for some reason
+     * @throws SQLException if inserting data fails for some reason
+     */
     private void insertDataWithToken(String token, 
                                      long pre, long post, int mode)
             throws IOException, SQLException {



Mime
View raw message