db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r908418 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/types/ impl/jdbc/
Date Wed, 10 Feb 2010 09:46:05 GMT
Author: kristwaa
Date: Wed Feb 10 09:46:05 2010
New Revision: 908418

URL: http://svn.apache.org/viewvc?rev=908418&view=rev
Log:
DERBY-4543: CLOB values incorrectly stored on disk using the old header format 

Aadded missing !-operator in EmbedPreparedStatement.
Replaced DD_VERSION_CURRENT with DD_VERSION_DERBY_10_5.
Renamed several methods and variables (stop using soft-upgrade mode term, use stream header
format instead).

Patch file: derby-4543-1a-clob_hdr_format_fix.diff


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java?rev=908418&r1=908417&r2=908418&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/ClobStreamHeaderGenerator.java
Wed Feb 10 09:46:05 2010
@@ -56,7 +56,8 @@
 
     /**
      * 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 @@
      */
     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 @@
     }
 
     /**
-     * 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 @@
      * @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 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 @@
      * @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 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,15 @@
     }
 
     /**
-     * Determines if the database being accessed is accessed in soft upgrade
-     * mode or not.
+     * 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 +256,7 @@
         } 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 +270,7 @@
             // 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/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java?rev=908418&r1=908417&r2=908418&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLChar.java Wed Feb 10 09:46:05
2010
@@ -3040,7 +3040,7 @@
      *      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/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java?rev=908418&r1=908417&r2=908418&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLClob.java Wed Feb 10 09:46:05
2010
@@ -616,7 +616,7 @@
      * <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
@@ -645,7 +645,7 @@
      * @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/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java?rev=908418&r1=908417&r2=908418&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java Wed Feb
10 09:46:05 2010
@@ -208,19 +208,18 @@
      * 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/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=908418&r1=908417&r2=908418&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
Wed Feb 10 09:46:05 2010
@@ -93,12 +93,13 @@
 	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 @@
             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 @@
 	}
 
     /**
-     * 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/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=908418&r1=908417&r2=908418&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java Wed Feb
10 09:46:05 2010
@@ -2930,11 +2930,10 @@
                     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