db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r951363 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/iapi/types/ java/engine/org/apache/derby/impl/jdbc/
Date Fri, 04 Jun 2010 11:06:09 GMT
Author: kristwaa
Date: Fri Jun  4 11:06:09 2010
New Revision: 951363

URL: http://svn.apache.org/viewvc?rev=951363&view=rev
Log:
DERBY-4661: Reduce size of encoding buffer for short character values
DERBY-4543: CLOB values incorrectly stored on disk using the old header format

Merged fixes from trunk (revisions 908418 and 948069).

Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/CharStreamHeaderGenerator.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ReaderToUTF8Stream.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLClob.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StreamHeaderGenerator.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StringDataValue.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jun  4 11:06:09 2010
@@ -1 +1 @@
-/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,901165,901648,901760,903108,911315,915733,916075,916897,918359,921028,927430,946794,948045
+/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,901165,901648,901760,903108,908418,911315,915733,916075,916897,918359,921028,927430,946794,948045,948069

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/CharStreamHeaderGenerator.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/CharStreamHeaderGenerator.java?rev=951363&r1=951362&r2=951363&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/CharStreamHeaderGenerator.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/CharStreamHeaderGenerator.java
Fri Jun  4 11:06:09 2010
@@ -134,4 +134,13 @@ public final class CharStreamHeaderGener
             return 0;
         }
     }
+
+    /**
+     * Returns the maximum header length.
+     *
+     * @return Maximum header length in bytes.
+     */
+    public int getMaxHeaderLength() {
+        return 2;
+    }
 }

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java?rev=951363&r1=951362&r2=951363&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java
Fri Jun  4 11:06:09 2010
@@ -56,7 +56,8 @@ public final class ClobStreamHeaderGener
 
     /**
      * Reference to "owning" DVD, used to update it with information about
-     * whether the database is being accessed in soft upgrade mode or not.
+     * which header format should be used. This is currently only determined by
+     * consulting the data dictionary about the version.
      * <p>
      * This is an optimization to avoid having to consult the data dictionary
      * on every request to generate a header when a data value descriptor is
@@ -64,15 +65,15 @@ public final class ClobStreamHeaderGener
      */
     private final StringDataValue callbackDVD;
     /**
-     * {@code true} if database is being accessed in soft upgrade mode,
-     * {@code false} is not. If {@code null}, the mode will be determined by
-     * obtaining the database context through the context service.
+     * {@code true} if the database version is prior to 10.5, {@code false} if
+     * the version is 10.5 or newer. If {@code null}, the version will be
+     * determined by obtaining the database context through the context service.
      */
-    private Boolean inSoftUpgradeMode;
+    private Boolean isPreDerbyTenFive;
 
     /**
      * Creates a new generator that will use the context manager to determine
-     * if the database is being accessed in soft upgrade mode or not.
+     * which header format to use based on the database version.
      *
      * @param dvd the owning data value descriptor
      */
@@ -84,33 +85,34 @@ public final class ClobStreamHeaderGener
     }
 
     /**
-     * Creates a new generator for a database in the given mode.
+     * Creates a new generator using the specified header format.
      *
-     * @param inSoftUpgradeMode {@code true} if the database is being accessed
-     *      in soft upgrade mode, {@code false} if not
+     * @param isPreDerbyTenFive {@code true} if the database version is prior
+     *      to 10.5, {@code false} if the version is 10.5 or newer
      */
-    public ClobStreamHeaderGenerator(boolean inSoftUpgradeMode) {
-        // Do not try to determine if we are in soft upgrade mode, use the
-        // specified value for it.
+    public ClobStreamHeaderGenerator(boolean isPreDerbyTenFive) {
+        // Do not try to determine the version through the cottext service, use
+        // the specified value instead.
         this.callbackDVD = null;
-        this.inSoftUpgradeMode = Boolean.valueOf(inSoftUpgradeMode);
+        this.isPreDerbyTenFive = Boolean.valueOf(isPreDerbyTenFive);
     }
 
     /**
      * Tells if the header encodes a character or byte count.
      * <p>
      * Currently the header expects a character count if the header format is
-     * 10.5 (or newer), and a byte count if we are accessing a database in
-     * soft upgrade mode.
+     * 10.5 (or newer), and a byte count if we are accessing a database created
+     * by a version prior to 10.5.
      *
-     * @return {@code false} if in soft upgrade mode, {@code true} if not.
+     * @return {@code false} if a byte count is expected (prior to 10.5),
+     *      {@code true} if a character count is expected (10.5 and newer).
      */
     public boolean expectsCharCount() {
-        if (callbackDVD != null && inSoftUpgradeMode == null) {
-            determineMode();
+        if (callbackDVD != null && isPreDerbyTenFive == null) {
+            determineHeaderFormat();
         }
-        // Expect byte count if in soft upgrade mode, char count otherwise.
-        return !inSoftUpgradeMode.booleanValue();
+        // Expect byte count if older than 10.5, char count otherwise.
+        return !isPreDerbyTenFive.booleanValue();
     }
 
     /**
@@ -123,11 +125,11 @@ public final class ClobStreamHeaderGener
      * @return The number of bytes written into the buffer.
      */
     public int generateInto(byte[] buf, int offset, long valueLength) {
-        if (callbackDVD != null && inSoftUpgradeMode == null) {
-            determineMode();
+        if (callbackDVD != null && isPreDerbyTenFive == null) {
+            determineHeaderFormat();
         }
         int headerLength = 0;
-        if (inSoftUpgradeMode == Boolean.FALSE) {
+        if (isPreDerbyTenFive == Boolean.FALSE) {
             // Write a 10.5 stream header format.
             // Assume the length specified is a char count.
             if (valueLength >= 0){
@@ -159,11 +161,11 @@ public final class ClobStreamHeaderGener
      */
     public int generateInto(ObjectOutput out, long valueLength)
             throws IOException {
-        if (callbackDVD != null && inSoftUpgradeMode == null) {
-            determineMode();
+        if (callbackDVD != null && isPreDerbyTenFive == null) {
+            determineHeaderFormat();
         }
         int headerLength = 0;
-        if (inSoftUpgradeMode == Boolean.FALSE) {
+        if (isPreDerbyTenFive == Boolean.FALSE) {
             // Write a 10.5 stream header format.
             headerLength = 5;
             // Assume the length specified is a char count.
@@ -195,10 +197,10 @@ public final class ClobStreamHeaderGener
      * @return Number of bytes written (zero or more).
      */
     public int writeEOF(byte[] buffer, int offset, long valueLength) {
-        if (callbackDVD != null && inSoftUpgradeMode == null) {
-            determineMode();
+        if (callbackDVD != null && isPreDerbyTenFive == null) {
+            determineHeaderFormat();
         }
-        if (!inSoftUpgradeMode.booleanValue()) {
+        if (!isPreDerbyTenFive.booleanValue()) {
             if (valueLength < 0) {
                 System.arraycopy(DERBY_EOF_MARKER, 0,
                                  buffer, offset, DERBY_EOF_MARKER.length);
@@ -221,10 +223,10 @@ public final class ClobStreamHeaderGener
      */
     public int writeEOF(ObjectOutput out, long valueLength)
             throws IOException {
-        if (callbackDVD != null && inSoftUpgradeMode == null) {
-            determineMode();
+        if (callbackDVD != null && isPreDerbyTenFive == null) {
+            determineHeaderFormat();
         }
-        if (!inSoftUpgradeMode.booleanValue()) {
+        if (!isPreDerbyTenFive.booleanValue()) {
             if (valueLength < 0) {
                 out.write(DERBY_EOF_MARKER);
                 return DERBY_EOF_MARKER.length;
@@ -237,10 +239,24 @@ public final class ClobStreamHeaderGener
     }
 
     /**
-     * Determines if the database being accessed is accessed in soft upgrade
-     * mode or not.
+     * Returns the maximum header length.
+     *
+     * @return Maximum header length in bytes.
+     */
+    public int getMaxHeaderLength() {
+        return 5;
+    }
+
+    /**
+     * Determines which header format to use.
+     * <p>
+     * <em>Implementation note:</em> The header format is determined by
+     * consulting the data dictionary throught the context service. If there is
+     * no context, the operation will fail.
+     *
+     * @throws IllegalStateException if there is no context
      */
-    private void determineMode() {
+    private void determineHeaderFormat() {
         DatabaseContext dbCtx = (DatabaseContext)
                 ContextService.getContext(DatabaseContext.CONTEXT_ID);
         if (dbCtx == null) {
@@ -249,7 +265,7 @@ public final class ClobStreamHeaderGener
         } else {
             DataDictionary dd = dbCtx.getDatabase().getDataDictionary();
             try {
-                inSoftUpgradeMode = Boolean.valueOf(!dd.checkVersion(
+                isPreDerbyTenFive = Boolean.valueOf(!dd.checkVersion(
                         DataDictionary.DD_VERSION_DERBY_10_5, null));
             } catch (StandardException se) {
                 // This should never happen as long as the second argument
@@ -263,7 +279,7 @@ public final class ClobStreamHeaderGener
             // being accessed in. It is assumed that a DVD is only shared
             // within a single database, i.e. the mode doesn't change during
             // the lifetime of the DVD.
-            callbackDVD.setSoftUpgradeMode(inSoftUpgradeMode);
+            callbackDVD.setStreamHeaderFormat(isPreDerbyTenFive);
         }
     }
 }

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ReaderToUTF8Stream.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ReaderToUTF8Stream.java?rev=951363&r1=951362&r2=951363&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ReaderToUTF8Stream.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/ReaderToUTF8Stream.java
Fri Jun  4 11:06:09 2010
@@ -51,6 +51,8 @@ public final class ReaderToUTF8Stream
 
     /** Constant indicating the first iteration of {@code fillBuffer}. */
     private final static int FIRST_READ = Integer.MIN_VALUE;
+    /** Buffer space reserved for one 3 byte encoded char and the EOF marker. */
+    private final static int READ_BUFFER_RESERVATION = 6;
     /**
      * Constant indicating that no mark is set in the stream, or that the read
      * ahead limit of the mark has been exceeded.
@@ -58,10 +60,11 @@ public final class ReaderToUTF8Stream
     private final static int MARK_UNSET_OR_EXCEEDED = -1;
     /**
      * Buffer to hold the data read from stream and converted to the modified
-     * UTF-8 format. The initial size is 32 KB, but it may grow if the
+     * UTF-8 format. The initial size is dependent on whether the data value
+     * length is known (limited upwards to 32 KB), but it may grow if
      * {@linkplain #mark(int)} is invoked.
      */
-    private byte[] buffer = new byte[32*1024];
+    private byte[] buffer;
 	private int boff;
     private int blen = -1;
     /** Stream mark, set through {@linkplain #mark(int)}. */
@@ -83,7 +86,7 @@ public final class ReaderToUTF8Stream
      * Number of characters to truncate from this stream.
      * The SQL standard allows for truncation of trailing spaces for CLOB,
      * VARCHAR and CHAR. If zero, no characters are truncated, unless the
-     * stream length execeeds the maximum length of the column we are inserting
+     * stream length exceeds the maximum length of the column we are inserting
      * into.
      */
     private final int charsToTruncate;
@@ -124,11 +127,13 @@ public final class ReaderToUTF8Stream
                               String typeName,
                               StreamHeaderGenerator headerGenerator) {
         this.reader = new LimitReader(appReader);
-        reader.setLimit(valueLength);
         this.charsToTruncate = numCharsToTruncate;
         this.valueLength = valueLength;
         this.typeName = typeName;
         this.hdrGen = headerGenerator;
+
+        int absValueLength = Math.abs(valueLength);
+        reader.setLimit(absValueLength);
         if (SanityManager.DEBUG) {
             // Check the type name
             // The national types (i.e. NVARCHAR) are not used/supported.
@@ -138,6 +143,17 @@ public final class ReaderToUTF8Stream
                     typeName.equals(TypeId.CLOB_NAME)) ||
                     typeName.equals(TypeId.LONGVARCHAR_NAME));
         }
+        // Optimization for small values, where we reduce the memory
+        // requirement during encoding/insertion.
+        // Be conservative, assume three bytes per char.
+        int bz = 32*1024; // 32 KB default
+        if (absValueLength < bz / 3) {
+            // Enforce a minimum size of the buffer, otherwise read may loop
+            // indefinitely (must enter for loop in fillBuffer to detect EOF).
+            bz = hdrGen.getMaxHeaderLength() +
+                    Math.max(READ_BUFFER_RESERVATION, absValueLength * 3 +3);
+        }
+        buffer = new byte[bz];
     }
 
     /**
@@ -167,7 +183,6 @@ public final class ReaderToUTF8Stream
             throw new IllegalArgumentException("Maximum length for a capped " +
                     "stream cannot be negative: " + maximumLength);
         }
-        reader.setLimit(maximumLength);
     }
 
     /**
@@ -325,7 +340,7 @@ public final class ReaderToUTF8Stream
         if (mark >= 0) {
             // Add 6 bytes reserved for one 3 byte character encoding and the
             // 3 byte Derby EOF marker (see encoding loop further down).
-            int spaceRequired = readAheadLimit + 6;
+            int spaceRequired = readAheadLimit + READ_BUFFER_RESERVATION;
             if (mark + spaceRequired > buffer.length) {
                 if (blen != -1) {
                     // Calculate the new offset, as we may have to shift bytes
@@ -347,7 +362,7 @@ public final class ReaderToUTF8Stream
 
 		// 6! need to leave room for a three byte UTF8 encoding
 		// and 3 bytes for our special end of file marker.
-		for (; off <= buffer.length - 6; )
+        for (; off <= buffer.length - READ_BUFFER_RESERVATION; )
 		{
 			int c = reader.read();
 			if (c < 0) {
@@ -558,7 +573,7 @@ public final class ReaderToUTF8Stream
      */
     public void reset()
             throws IOException {
-        // Throw execption if the stream has been closed implicitly or
+        // Throw exception if the stream has been closed implicitly or
         // explicitly.
         if (buffer == null) {
             throw new EOFException(MessageService.getTextMessage

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.java?rev=951363&r1=951362&r2=951363&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLChar.java Fri Jun
 4 11:06:09 2010
@@ -3044,7 +3044,7 @@ readingLoop:
      *      in soft upgrade mode, {@code false} if not, and {@code null} if
      *      unknown
      */
-    public void setSoftUpgradeMode(Boolean inSoftUpgradeMode) {
+    public void setStreamHeaderFormat(Boolean inSoftUpgradeMode) {
         // Ignore this for CHAR, VARCHAR and LONG VARCHAR.
     }
     

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLClob.java?rev=951363&r1=951362&r2=951363&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLClob.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLClob.java Fri Jun
 4 11:06:09 2010
@@ -56,10 +56,6 @@ import java.util.Calendar;
 public class SQLClob
 	extends SQLVarchar
 {
-
-    /** The maximum number of bytes used by the stream header. */
-    private static final int MAX_STREAM_HEADER_LENGTH = 5;
-
     /** The header generator used for 10.4 (or older) databases. */
     private static final StreamHeaderGenerator TEN_FOUR_CLOB_HEADER_GENERATOR =
             new ClobStreamHeaderGenerator(true);
@@ -69,6 +65,14 @@ public class SQLClob
             new ClobStreamHeaderGenerator(false);
 
     /**
+     * The maximum number of bytes used by the stream header.
+     * <p>
+     * Use the length specified by the ten five header generator.
+     */
+    private static final int MAX_STREAM_HEADER_LENGTH =
+            TEN_FIVE_CLOB_HEADER_GENERATOR.getMaxHeaderLength();
+
+    /**
      * The descriptor for the stream. If there is no stream this should be
      * {@code null}, which is also true if the descriptor hasen't been
      * constructed yet.
@@ -577,7 +581,7 @@ public class SQLClob
      * <p>
      * <em>NOTE</em>: To guarantee a successful generation, one of the following
      * two conditions must be met at header or EOF generation time:
-     * <ul> <li>{@code setSoftUpgradeMode} has been invoked before the header
+     * <ul> <li>{@code setStreamHeaderFormat} has been invoked before the header
      *          generator was obtained.</li>
      *      <li>There is context at generation time, such that the mode can be
      *          determined by obtaining the database context and by consulting
@@ -606,7 +610,7 @@ public class SQLClob
      * @param inSoftUpgradeMode {@code TRUE} if the database is accessed in
      *      soft upgrade mode, {@code FALSE} is not, or {@code null} if unknown
      */
-    public void setSoftUpgradeMode(Boolean inSoftUpgradeMode) {
+    public void setStreamHeaderFormat(Boolean inSoftUpgradeMode) {
         this.inSoftUpgradeMode = inSoftUpgradeMode;
     }
 

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StreamHeaderGenerator.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StreamHeaderGenerator.java?rev=951363&r1=951362&r2=951363&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StreamHeaderGenerator.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StreamHeaderGenerator.java
Fri Jun  4 11:06:09 2010
@@ -86,4 +86,11 @@ public interface StreamHeaderGenerator {
      * @throws IOException if writing to the destination stream fails
      */
     int writeEOF(ObjectOutput out, long valueLength) throws IOException;
+
+    /**
+     * Returns the maximum length of the header.
+     *
+     * @return Max header length in bytes.
+     */
+    int getMaxHeaderLength();
 }

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StringDataValue.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StringDataValue.java?rev=951363&r1=951362&r2=951363&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StringDataValue.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/StringDataValue.java
Fri Jun  4 11:06:09 2010
@@ -208,19 +208,18 @@ public interface StringDataValue extends
      * Note that the generator may fail to generate a header if there is no
      * context at the time the header is asked for, and the mode hasn't been
      * set explicitly.
-     * @see #setSoftUpgradeMode
+     * @see #setStreamHeaderFormat
      */
     public StreamHeaderGenerator getStreamHeaderGenerator();
 
     /**
-     * Tells the data value descriptor whether the database is being accessed
-     * in soft upgrade mode or not.
+     * Tells the data value descriptor which CLOB stream header format to use.
      *
-     * @param inSoftUpgradeMode {@code true} if the database is being accessed
-     *      in soft upgrade mode, {@code false} if not, and {@code null} if
-     *      unknown
+     * @param usePreTenFiveHdrFormat {@code true} if the database accessed is
+     *      prior to version 10.5, {@code false} if the version is 10.5 or
+     *      newer, and {@code null} if unknown at this time
      */
-    public void setSoftUpgradeMode(Boolean inSoftUpgradeMode);
+    public void setStreamHeaderFormat(Boolean usePreTenFiveHdrFormat);
 
     /**
      * Returns a descriptor for the input stream for this data value.

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=951363&r1=951362&r2=951363&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
Fri Jun  4 11:06:09 2010
@@ -93,12 +93,13 @@ public abstract class EmbedPreparedState
 	protected PreparedStatement	preparedStatement;
 	private Activation			activation;
     /**
-     * Tells if we're accessing a database in soft upgrade mode or not.
+     * Tells which header format to use when writing CLOBs into the store.
      * <p>
-     * This is lazily set if we need it.
-     * @see #isSoftUpgraded()
+     * This is lazily set if we need it, and there are currently only two
+     * valid header formats to choose between.
+     * @see #usePreTenFiveHdrFormat()
      */
-    private Boolean inSoftUpgradeMode;
+    private Boolean usePreTenFiveHdrFormat;
         
         private BrokeredConnectionControl bcc=null;
 
@@ -743,7 +744,7 @@ public abstract class EmbedPreparedState
             ReaderToUTF8Stream utfIn;
             final StringDataValue dvd = (StringDataValue)
                     getParms().getParameter(parameterIndex -1);
-            dvd.setSoftUpgradeMode(isSoftUpgraded());
+            dvd.setStreamHeaderFormat(usePreTenFiveHdrFormat());
             // Need column width to figure out if truncation is needed
             DataTypeDescriptor dtd[] = preparedStatement
                     .getParameterTypes();
@@ -809,21 +810,23 @@ public abstract class EmbedPreparedState
 	}
 
     /**
-     * Tells if the database being accessed is soft upgraded or not.
+     * Determines which header format to use for CLOBs when writing them to
+     * the store.
      *
-     * @return {@code true} if database is soft upgraded, {@code false} if not.
+     * @return {@code true} if the pre Derby 10.5 header format is to be used,
+     *      {@code false} if the new header format can be used (10.5 or newer)
      * @throws StandardException if obtaining the access mode fails
      */
-    private Boolean isSoftUpgraded()
+    private Boolean usePreTenFiveHdrFormat()
             throws StandardException {
-        // Determine if we are accessing a soft upgraded database or not.
+        // Determine the version of the database we are accessing.
         // This is required to write the correct stream header format for Clobs.
-        if (inSoftUpgradeMode == null) {
-            inSoftUpgradeMode = Boolean.valueOf(
-                lcc.getDataDictionary().checkVersion(
-                    DataDictionary.DD_VERSION_CURRENT, null));
+        if (usePreTenFiveHdrFormat == null) {
+            usePreTenFiveHdrFormat = Boolean.valueOf(
+                !lcc.getDataDictionary().checkVersion(
+                    DataDictionary.DD_VERSION_DERBY_10_5, null));
         }
-        return inSoftUpgradeMode;
+        return usePreTenFiveHdrFormat;
     }
 
     /**

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=951363&r1=951362&r2=951363&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
Fri Jun  4 11:06:09 2010
@@ -2929,11 +2929,10 @@ public abstract class EmbedResultSet ext
                     getDVDforColumnToBeUpdated(columnIndex, updateMethodName);
             // In the case of updatable result sets, we cannot guarantee that a
             // context is pushed when the header needs to be generated. To fix
-            // this, tell the DVD/generator whether we are running in soft
-            // upgrade mode or not.
-            dvd.setSoftUpgradeMode(Boolean.valueOf(
+            // this, tell the DVD/generator which header format to use.
+            dvd.setStreamHeaderFormat(Boolean.valueOf(
                     !getEmbedConnection().getDatabase().getDataDictionary().
-                    checkVersion(DataDictionary.DD_VERSION_CURRENT, null)));
+                    checkVersion(DataDictionary.DD_VERSION_DERBY_10_5, null)));
             ReaderToUTF8Stream utfIn;
             int usableLength = DataValueDescriptor.UNKNOWN_LOGICAL_LENGTH;
             if (!lengthLess) {



Mime
View raw message