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 kr...@apache.org on 2008/12/09 11:24:19 UTC
svn commit: r724657 - in /db/derby/code/trunk/java:
client/org/apache/derby/client/am/Clob.java
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Author: kristwaa
Date: Tue Dec 9 02:24:18 2008
New Revision: 724657
URL: http://svn.apache.org/viewvc?rev=724657&view=rev
Log:
DERBY-3978: Clob.truncate(long) in the client driver doesn't update the cached Clob length.
Make the client driver update the length of the Clob when it has been truncated.Added a few tests.
Patch file: derby-3978-1a-regression_tests.diff, derby-3978-2a-update_length.diff
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java?rev=724657&r1=724656&r2=724657&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Clob.java Tue Dec 9 02:24:18 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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java?rev=724657&r1=724656&r2=724657&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java Tue Dec 9 02:24:18 2008
@@ -346,6 +346,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:
@@ -489,6 +579,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 {