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 ka...@apache.org on 2007/07/04 09:39:27 UTC

svn commit: r553111 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/

Author: kahatlen
Date: Wed Jul  4 00:39:26 2007
New Revision: 553111

URL: http://svn.apache.org/viewvc?view=rev&rev=553111
Log:
DERBY-2891: Clob.getCharacterStream(long,long) ignores position
parameter for large (>32k) CLOBs

Fixed hard-coded start position in ClobUpdatableReader's constructor.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java?view=diff&rev=553111&r1=553110&r2=553111
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java Wed Jul  4 00:39:26 2007
@@ -87,30 +87,9 @@
      * @throws SQLException
      */
     ClobUpdatableReader (EmbedClob clob) throws IOException, SQLException {
-        this.clob = clob;
-        this.conChild = clob;
         // A subset of the Clob has not been requested.
-        // Hence set maxPos to infinity (or as close as we get).
-        this.maxPos = Long.MAX_VALUE;
-
-        InternalClob internalClob = clob.getInternalClob();
-        materialized = internalClob.isWritable();        
-        if (materialized) {
-            long byteLength = internalClob.getByteLength();
-            this.stream = internalClob.getRawByteStream();
-            init ((LOBInputStream)stream, 0);
-        } else {
-            if (SanityManager.DEBUG) {
-                SanityManager.ASSERT(internalClob instanceof StoreStreamClob,
-                        "Wrong type of internal clob representation: " +
-                        internalClob.toString());
-            }
-            // Since this representation is read-only, the stream never has to
-            // update itself, until the Clob representation itself has been
-            // changed. That even will be detected by {@link #updateIfRequired}.
-            this.streamReader = internalClob.getReader(1L);
-            this.pos = 0L;
-        }
+        // Hence set length to infinity (or as close as we get).
+        this(clob, 0L, Long.MAX_VALUE);
     }
     
     /**
@@ -148,8 +127,8 @@
             // Since this representation is read-only, the stream never has to
             // update itself, until the Clob representation itself has been
             // changed. That even will be detected by {@link #updateIfRequired}.
-            this.streamReader = internalClob.getReader(1L);
-            this.pos = 0L;
+            this.streamReader = internalClob.getReader(pos + 1);
+            this.pos = pos;
         }
     }
         

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java?view=diff&rev=553111&r1=553110&r2=553111
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java Wed Jul  4 00:39:26 2007
@@ -80,8 +80,8 @@
         Connection con = getConnection();
         Statement stmt = con.createStatement();
         stmt.execute("create table BLOBCLOB (ID int primary key, " +
-                                            "BLOBDATA blob(1k)," + 
-                                            "CLOBDATA clob(1k))");
+                                            "BLOBDATA blob," +
+                                            "CLOBDATA clob)");
         stmt.execute("insert into BLOBCLOB VALUES " +
                 "(" + ID_NULLVALUES + ", null, null)");
         // Actual data is inserted in the getSample* methods.

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=553111&r1=553110&r2=553111
==============================================================================
--- 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 Wed Jul  4 00:39:26 2007
@@ -411,6 +411,45 @@
     }
 
     /**
+     * Test that <code>Clob.getCharacterStream(long,long)</code> works on CLOBs
+     * that are streamed from store. (DERBY-2891)
+     */
+    public void testGetCharacterStreamLongOnLargeClob() throws Exception {
+        getConnection().setAutoCommit(false);
+
+        // create large (>32k) clob that can be read from store
+        final int size = 33000;
+        StringBuilder sb = new StringBuilder(size);
+        for (int i = 0; i < size; i += 10) {
+            sb.append("1234567890");
+        }
+
+        final int id = BlobClobTestSetup.getID();
+        PreparedStatement ps = prepareStatement(
+            "insert into blobclob(id, clobdata) values (?,cast(? as clob))");
+        ps.setInt(1, id);
+        ps.setString(2, sb.toString());
+        ps.executeUpdate();
+        ps.close();
+
+        Statement s = createStatement();
+        ResultSet rs = s.executeQuery(
+            "select clobdata from blobclob where id = " + id);
+        assertTrue(rs.next());
+        Clob c = rs.getClob(1);
+
+        // request a small region of the clob
+        BufferedReader r = new BufferedReader(c.getCharacterStream(4L, 3L));
+        assertEquals("456", r.readLine());
+
+        r.close();
+        c.free();
+        rs.close();
+        s.close();
+        rollback();
+    }
+
+    /**
      * Tests the exceptions thrown by the getCharacterStream
      * (long pos, long length) for the following conditions
      * a) pos <= 0