db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r782600 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc: InternalClob.java StoreStreamClob.java TemporaryClob.java
Date Mon, 08 Jun 2009 12:12:56 GMT
Author: kristwaa
Date: Mon Jun  8 12:12:56 2009
New Revision: 782600

URL: http://svn.apache.org/viewvc?rev=782600&view=rev
Log:
DERBY-4241: Improve transition from read-only to writable Clob representation.
Added the new method InternalClob.getCharLengthIfKnown, which allows for
determining if the length of the Clob is known or not at the time of the method
invocation. If the length is unknown, it will not be calculated as this may be
an expensive operation.
This method was added to allow for performance optimizations, where the optimal
action depends on whether the character length is known or not.

Patch file: derby-4241-1a-InternalClob.getLengthIfKnown.diff


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/InternalClob.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/InternalClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/InternalClob.java?rev=782600&r1=782599&r2=782600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/InternalClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/InternalClob.java Mon Jun 
8 12:12:56 2009
@@ -49,6 +49,21 @@
     long getCharLength() throws IOException, SQLException;
 
     /**
+     * Gets the number of characters in the Clob if it is already known.
+     * <p>
+     * This method will not do any work to obtain the length if it isn't
+     * already known. Due to special handling of zero in the code, this method
+     * will return {@code -1} if a length of zero is cached internally.
+     * <p>
+     * If a positive value is returned, it is expected to be equal to the
+     * actual length of the Clob (i.e., no stale values must be returned).
+     *
+     * @return Number of characters in the Clob, or {@code -1} if the length is
+     *      currently unknown (not cached).
+     */
+    long getCharLengthIfKnown();
+
+    /**
      * Returns a stream serving the raw bytes of the Clob.
      * <p>
      * Note that it is up to the caller of this method to handle the issue of

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java?rev=782600&r1=782599&r2=782600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/StoreStreamClob.java Mon Jun
 8 12:12:56 2009
@@ -176,6 +176,17 @@
     }
 
     /**
+     * Returns the cached character count for the Clob, if any.
+     *
+     * @return The number of characters in the Clob, or {@code -1} if unknown.
+     */
+    public long getCharLengthIfKnown() {
+        checkIfValid();
+        // Treat a cached value of zero as a special case.
+        return (csd.getCharLength() == 0 ? -1 : csd.getCharLength());
+    }
+
+    /**
      * Returns a stream serving the raw bytes of this Clob.
      * <p>
      * Note that the stream returned is an internal stream, and it should not be

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java?rev=782600&r1=782599&r2=782600&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/TemporaryClob.java Mon Jun
 8 12:12:56 2009
@@ -330,6 +330,17 @@
     }
 
     /**
+     * Returns the cached character count for the Clob, if any.
+     *
+     * @return The number of characters in the Clob, or {@code -1} if unknown.
+     */
+    public synchronized long getCharLengthIfKnown() {
+        checkIfValid();
+        // Treat a cached value of zero as a special case.
+        return (cachedCharLength == 0 ? -1 : cachedCharLength);
+    }
+
+    /**
      * Returns the size of the Clob in bytes.
      *
      * @return Number of bytes in the <code>CLOB</code> value.



Mime
View raw message