Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 25509 invoked from network); 4 Jul 2007 08:25:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jul 2007 08:25:12 -0000 Received: (qmail 85507 invoked by uid 500); 4 Jul 2007 08:25:15 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 85479 invoked by uid 500); 4 Jul 2007 08:25:15 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 85467 invoked by uid 99); 4 Jul 2007 08:25:15 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jul 2007 01:25:15 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jul 2007 01:25:11 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id C0C811A981A; Wed, 4 Jul 2007 01:24:51 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070704082451.C0C811A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 Clob.getCharacterStream(long,long) 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