db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r553123 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/
Date Wed, 04 Jul 2007 08:24:51 GMT
Author: kahatlen
Date: Wed Jul  4 01:24:50 2007
New Revision: 553123

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

Merged fix from trunk (revision 553111).

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

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java?view=diff&rev=553123&r1=553122&r2=553123
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java
Wed Jul  4 01:24:50 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/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java?view=diff&rev=553123&r1=553122&r2=553123
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobClobTestSetup.java
Wed Jul  4 01:24:50 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/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java?view=diff&rev=553123&r1=553122&r2=553123
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ClobTest.java
Wed Jul  4 01:24:50 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



Mime
View raw message