Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 52501 invoked from network); 8 Jun 2009 12:13:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Jun 2009 12:13:10 -0000 Received: (qmail 86378 invoked by uid 500); 8 Jun 2009 12:13:21 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 86340 invoked by uid 500); 8 Jun 2009 12:13:21 -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 86331 invoked by uid 99); 8 Jun 2009 12:13:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jun 2009 12:13:21 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jun 2009 12:13:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 04B8D23888D1; Mon, 8 Jun 2009 12:12:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: derby-commits@db.apache.org From: kristwaa@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090608121257.04B8D23888D1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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. + *

+ * 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. + *

+ * 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. *

* 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. *

* 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 CLOB value.