db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r676912 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl: jdbc/LOBStoredProcedure.java sql/catalog/DataDictionaryImpl.java
Date Tue, 15 Jul 2008 13:29:50 GMT
Author: kristwaa
Date: Tue Jul 15 06:29:50 2008
New Revision: 676912

URL: http://svn.apache.org/viewvc?rev=676912&view=rev
Log:
DERBY-3769: Make LOBStoredProcedure on the server side smarter about the read buffer size.
Adjust amount of data to fetch (and thus read) if it is greater then the maximum allowed return
length of the LOB stored procedures (width of VARBINARY/VARCHAR).
Reading/fetching more data caused the stream position to be advanced too far and resulted
in a stream reset followed by skipping of data until at the correct position again.
Patch file: derby-3769-1b-buffer_size_adjustment.diff

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java?rev=676912&r1=676911&r2=676912&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java Tue
Jul 15 06:29:50 2008
@@ -27,6 +27,7 @@
 import java.sql.SQLException;
 
 import org.apache.derby.iapi.jdbc.EngineLOB;
+import org.apache.derby.iapi.reference.Limits;
 import org.apache.derby.iapi.reference.SQLState;
 
 /**
@@ -36,6 +37,15 @@
 public class LOBStoredProcedure {
 
     /**
+     * The maximum length of the data returned from the LOB stored procedures.
+     * <p>
+     * This value is currently dictated by the maximum length of
+     * VARCHAR/VARBINARY, because these are the return types of the stored
+     * procedures.
+     */
+    public static final int MAX_RETURN_LENGTH = Limits.DB2_VARCHAR_MAXWIDTH;
+
+    /**
      * Creates a new empty Clob and registers it in the HashMap in the
      * Connection and returns the locator value corresponding to this Clob.
      * @return an integer that maps to the Clob value created.
@@ -128,19 +138,26 @@
     }
 
     /**
-     * returns the String starting from pos and of len length
-     * from the LOB corresponding to LOCATOR.
+     * Returns the {@code String} starting from {@code pos} and consisting of
+     * up to {@code len} consecutive characters from the {@code Clob}
+     * corresponding to {@code LOCATOR}.
+     *
      * @param LOCATOR an integer that represents the LOCATOR used
      *                to retrieve an instance of the LOB.
      * @param pos a long that represents the position from which
      *            the substring begins.
-     * @param len an integer that represents the length of the substring.
-     * @return the substring conforming to the indexes we requested for from
-     *         inside the LOB.
+     * @param len an integer representing the maximum length of the substring.
+     *      The value will be reduced to the maximum allowed return length if
+     *      required (see {@link #MAX_RETURN_LENGTH}).
+     * @return A substring from the {@code Clob} starting at the given position,
+     *      not longer than {@code len} characters.
      * @throws SQLException
      */
     public static String CLOBGETSUBSTRING(int LOCATOR,
         long pos, int len) throws SQLException {
+        // Don't read more than what we can represent as a VARCHAR.
+        // See DERBY-3769.
+        len = Math.min(len, MAX_RETURN_LENGTH);
         return getClobObjectCorrespondingtoLOCATOR(LOCATOR).getSubString(pos, len);
     }
 
@@ -275,22 +292,30 @@
     }
 
     /**
-     * Returns the Byte array containing the bytes starting from pos and
-     * of length len
+     * Reads up to len bytes from the associated {@code Blob} and returns a
+     * byte array containing the bytes read.
+     * <p>
+     * Note that a smaller number of bytes than requested might be returned. The
+     * number of bytes returned can be found by checking the length of the
+     * returned byte array.
      *
      * @param LOCATOR the locator value of the Blob from which the byte array
      *                needs to be retrieved.
-     * @param len the length of the byte array that needs to be retrieved from
-     *            pos
+     * @param len the maximum number of bytes to read. The value will be
+     *      reduced to the maximum allowed return length if required
+     *      (see {@link #MAX_RETURN_LENGTH}).
      * @param pos the position from which the bytes from the Blob need to be
      *            retrieved.
-     * @return a byte array containing the bytes stating from pos and
-     *         of length len.
+     * @return A byte array containing the bytes read, starting from position
+     *      {@code pos} in the {@code Blob}.
      * @throws SQLException
      *
      */
     public static byte[] BLOBGETBYTES(int LOCATOR, long pos, int len)
     throws SQLException {
+        // Don't read more than what we can represent as a VARBINARY.
+        // See DERBY-3769.
+        len = Math.min(len, MAX_RETURN_LENGTH);
         return getBlobObjectCorrespondingtoLOCATOR(LOCATOR).getBytes(pos, len);
     }
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=676912&r1=676911&r2=676912&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Tue Jul 15 06:29:50 2008
@@ -81,7 +81,6 @@
 import org.apache.derby.iapi.types.SQLChar;
 import org.apache.derby.iapi.types.SQLVarchar;
 import org.apache.derby.iapi.types.StringDataValue;
-import org.apache.derby.iapi.types.TypeId;
 import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.DataValueDescriptor;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
@@ -136,11 +135,9 @@
 import org.apache.derby.iapi.services.locks.CompatibilitySpace;
 import org.apache.derby.iapi.services.locks.ShExLockable;
 import org.apache.derby.iapi.services.locks.ShExQual;
-import org.apache.derby.iapi.util.StringUtil;
 import org.apache.derby.iapi.util.IdUtil;
 
 import java.util.Calendar;
-import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Hashtable;
 import java.util.HashMap;
@@ -157,6 +154,9 @@
 
 import java.sql.Types;
 
+// LOBStoredProcedure is imported only to get hold of a constant.
+import org.apache.derby.impl.jdbc.LOBStoredProcedure;
+
 /**
  * Standard database implementation of the data dictionary
  * that stores the information in the system catlogs.
@@ -11050,7 +11050,8 @@
                 0,
                 RoutineAliasInfo.CONTAINS_SQL,
                 DataTypeDescriptor.getCatalogType(
-                    Types.VARCHAR, Limits.DB2_VARCHAR_MAXWIDTH),
+                    Types.VARCHAR,
+                    LOBStoredProcedure.MAX_RETURN_LENGTH),
                 tc,
                 "org.apache.derby.impl.jdbc.LOBStoredProcedure");
         }
@@ -11229,7 +11230,8 @@
                 0,
                 RoutineAliasInfo.CONTAINS_SQL,
                 DataTypeDescriptor.getCatalogType(
-                    Types.VARBINARY, Limits.DB2_VARCHAR_MAXWIDTH),
+                    Types.VARBINARY,
+                    LOBStoredProcedure.MAX_RETURN_LENGTH),
                 tc,
                 "org.apache.derby.impl.jdbc.LOBStoredProcedure");
         }



Mime
View raw message