db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r720472 - /db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java
Date Tue, 25 Nov 2008 11:49:23 GMT
Author: kristwaa
Date: Tue Nov 25 03:49:22 2008
New Revision: 720472

URL: http://svn.apache.org/viewvc?rev=720472&view=rev
Log:
DERBY-2822: Add caching of store stream length in StoreStreamClob, if appropriate.
Backported revision 708912 (derby-2822-1b-cacheCharLength.diff) from trunk.

Modified:
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java?rev=720472&r1=720471&r2=720472&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java
Tue Nov 25 03:49:22 2008
@@ -65,6 +65,14 @@
      */
     //@GuardedBy("synchronizationObject")
     private final PositionedStoreStream positionedStoreStream;
+    /**
+     * The cached length of the store stream in number of characters.
+     * A value of {@code 0} means the length is unknown, and zero is an invalid
+     * length for a store stream Clob. It is set to zero because that is the
+     * value encoded as length in the store stream (on disk format) when the
+     * length is unknown or cannot be represented.
+     */
+    private long cachedCharLength = 0;
     /** The connection (child) this Clob belongs to. */
     private final ConnectionChild conChild;
     /** Object used for synchronizing access to the store stream. */
@@ -134,17 +142,21 @@
     public long getCharLength()
             throws SQLException {
         checkIfValid();
-        synchronized (this.synchronizationObject) {
-            this.conChild.setupContextStack();
-            try {
-                return UTF8Util.skipUntilEOF(
-                                new BufferedInputStream(getRawByteStream()));
-            } catch (Throwable t) {
-                throw noStateChangeLOB(t);
-            } finally {
-                this.conChild.restoreContextStack();
+        if (this.cachedCharLength == 0) {
+            // Decode the stream to find the length.
+            synchronized (this.synchronizationObject) {
+                this.conChild.setupContextStack();
+                try {
+                    this.cachedCharLength = UTF8Util.skipUntilEOF(
+                            new BufferedInputStream(getRawByteStream()));
+                } catch (Throwable t) {
+                    throw noStateChangeLOB(t);
+                } finally {
+                    this.conChild.restoreContextStack();
+                }
             }
         }
+        return this.cachedCharLength;
     }
 
     /**



Mime
View raw message