db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r677557 - in /db/derby/code/branches/10.4/java/engine/org/apache/derby/impl: jdbc/LOBStoredProcedure.java sql/catalog/DataDictionaryImpl.java
Date Thu, 17 Jul 2008 11:12:15 GMT
Author: kristwaa
Date: Thu Jul 17 04:12:14 2008
New Revision: 677557

URL: http://svn.apache.org/viewvc?rev=677557&view=rev
Log:
DERBY-3769: Make LOBStoredProcedure on the server side smarter about the read buffer size.
Merged revision 676912 (derby-3769-1b-buffer_size_adjustment.diff) from trunk.

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

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java?rev=677557&r1=677556&r2=677557&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/LOBStoredProcedure.java
Thu Jul 17 04:12:14 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/branches/10.4/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=677557&r1=677556&r2=677557&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Thu Jul 17 04:12:14 2008
@@ -80,7 +80,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;
@@ -135,11 +134,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.Properties;
@@ -154,6 +151,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.
@@ -10510,7 +10510,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");
         }
@@ -10689,7 +10690,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