db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r745202 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/types/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apache/derbyTesting/unitTests/store/
Date Tue, 17 Feb 2009 19:24:26 GMT
Author: rhillegas
Date: Tue Feb 17 19:24:26 2009
New Revision: 745202

URL: http://svn.apache.org/viewvc?rev=745202&view=rev
Log:
DERBY-2201: Allow scalar functions to return LOBs.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BitDataValue.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.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/SQLVarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiSignaturesTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringColumnVTI.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Recovery.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BitDataValue.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BitDataValue.java?rev=745202&r1=745201&r2=745202&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BitDataValue.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/BitDataValue.java Tue Feb
17 19:24:26 2009
@@ -21,6 +21,8 @@
 
 package org.apache.derby.iapi.types;
 
+import java.sql.Blob;
+
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.io.FormatableBitSet;
 
@@ -50,4 +52,10 @@
 				BitDataValue result)
 		throws StandardException;
 
+	/**
+	 * Stuff a BitDataValue with a Blob.
+	 */
+	public void setValue( Blob value )
+		throws StandardException;
+
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java?rev=745202&r1=745201&r2=745202&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactory.java Tue
Feb 17 19:24:26 2009
@@ -25,6 +25,8 @@
 
 import org.apache.derby.iapi.error.StandardException;
 
+import java.sql.Blob;
+import java.sql.Clob;
 import java.sql.Date;
 import java.sql.Time;
 import java.sql.Timestamp;
@@ -144,6 +146,17 @@
         BitDataValue            getBlobDataValue(byte[] value,
                                                                                         
       BitDataValue previous)
                                                         throws StandardException;
+
+        /**
+         * Get a SQL Blob with the given value.  A null argument means
+         * get a SQL null value.  Uses the previous value (if
+         * non-null) to hold the return value.
+         *
+         * @exception StandardException         Thrown on error
+         */
+        BitDataValue            getBlobDataValue(Blob value,
+                                                                                        
       BitDataValue previous)
+                                                        throws StandardException;
         // ------ BOOLEAN
         /**
          * Get a SQL boolean with the given value.  A null argument means get
@@ -227,6 +240,16 @@
         StringDataValue getClobDataValue(String value, StringDataValue previous) throws StandardException;
 
         /**
+         * Get a SQLClob object to represent a SQL CLOB  (UCS_BASIC)
+         * with the given value. A null argument means get a SQL NULL value.
+         * If previous is not null (Java reference) then it will be set
+         * to the value passed in and returned, otherwise a new SQLLongvarchar
+         * will be created and set to the value.
+         *
+         */
+        StringDataValue getClobDataValue(Clob value, StringDataValue previous) throws StandardException;
+
+        /**
          * Get a StringDataValue to represent a SQL LONG VARCHAR with the
          * passed in collationType. A null argument means get a SQL NULL value.
          * If previous is not null (Java reference) then it will be set

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java?rev=745202&r1=745201&r2=745202&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java
Tue Feb 17 19:24:26 2009
@@ -54,7 +54,10 @@
 import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.iapi.reference.SQLState;
 
+import java.sql.Blob;
+import java.sql.Clob;
 import java.sql.Date;
+import java.sql.SQLException;
 import java.sql.Time;
 import java.sql.Timestamp;
 
@@ -469,6 +472,14 @@
                 return previous;
         }
 
+        public BitDataValue getBlobDataValue(Blob value, BitDataValue previous)
+                        throws StandardException
+        {
+            if (previous == null) { return new SQLBlob(value); }
+            previous.setValue(value);
+            return previous;
+        }
+
         // CHAR
         public StringDataValue getCharDataValue(String value)
         {
@@ -581,6 +592,15 @@
                 return previous;
         }
         
+        public StringDataValue getClobDataValue(Clob value, StringDataValue previous) throws
StandardException
+        {
+            if (previous == null) { return new SQLClob(value); }
+            
+            previous.setValue(value);
+            return previous;
+        }
+
+    
         /**
          * Return a StringDataValue to represent a SQL CLOB
          * with the given collation re-using previous if not null.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java?rev=745202&r1=745201&r2=745202&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBinary.java Tue Feb 17
19:24:26 2009
@@ -49,6 +49,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 
+import java.sql.Blob;
 import java.sql.SQLException;
 import java.sql.PreparedStatement;
 import org.apache.derby.iapi.services.io.InputStreamUtil;
@@ -120,6 +121,11 @@
 	abstract int getMaxMemoryUsage();
 
 	 /*
+	 * value as a blob
+	 */
+    Blob _blobValue;
+    
+	 /*
 	 * object state
 	 */
 	byte[] dataValue;
@@ -154,10 +160,25 @@
 		dataValue = val;
 	}
 
+	SQLBinary(Blob val)
+	{
+		setValue( val );
+	}
+
+   
 
 	public final void setValue(byte[] theValue)
 	{
 		dataValue = theValue;
+        _blobValue = null;
+		stream = null;
+		streamValueLength = -1;
+	}
+
+	public final void setValue(Blob theValue)
+	{
+		dataValue = null;
+        _blobValue = theValue;
 		stream = null;
 		streamValueLength = -1;
 	}
@@ -188,7 +209,7 @@
 	/**
 	 * @exception StandardException		Thrown on error
 	 */
-	public final InputStream	getStream()
+	public final InputStream	getStream() throws StandardException
 	{
 		return (stream);
 	}
@@ -206,14 +227,23 @@
 	{
 		try
 		{
-			if ((dataValue == null) && (stream != null)) {
-        
+			if ((dataValue == null) && (_blobValue != null) )
+            {
+                dataValue = _blobValue.getBytes( 1L,  getBlobLength() );
+                
+                _blobValue = null;
+ 				stream = null;
+				streamValueLength = -1;
+            }
+			else if ((dataValue == null) && (stream != null) )
+            {
 				if (stream instanceof FormatIdInputStream) {
 					readExternal((FormatIdInputStream) stream);
 				}
 				else {
 					readExternal(new FormatIdInputStream(stream));
 				}
+                _blobValue = null;
  				stream = null;
 				streamValueLength = -1;
 
@@ -223,9 +253,24 @@
 		{
 			throwStreamingIOException(ioe);
 		}
+		catch (SQLException se) { throw StandardException.plainWrapException( se ); }
+
 		return dataValue;
 	}
 	
+     /**
+      * Return a JDBC Blob. Only implemented to support DERBY-2201.
+      */
+    public Object getObject()
+        throws StandardException
+    {
+        // the generated code for the DERBY-2201 codepath expects to get a Blob
+        // back.
+
+        if ( _blobValue != null ) { return _blobValue; }
+        else { return super.getObject(); }
+    }
+    
 	/**
 	 * length in bytes
 	 *
@@ -233,7 +278,8 @@
 	 */
 	public final int	getLength() throws StandardException
 	{
-		if (stream != null) {
+        if ( _blobValue != null ) { return getBlobLength(); }
+		else if (stream != null) {
 			if (streamValueLength != -1)
 				return streamValueLength;
 			else if (stream instanceof Resetable){
@@ -284,7 +330,7 @@
 	 */
 	public final boolean isNull()
 	{
-		return (dataValue == null) && (stream == null);
+		return (dataValue == null) && (stream == null) && (_blobValue == null);
 	}
 
 	/** 
@@ -295,8 +341,47 @@
 	 */
 	public final void writeExternal(ObjectOutput out) throws IOException
 	{
+        if ( _blobValue != null )
+        {
+            writeBlob(  out );
+            return;
+        }
+        int len = dataValue.length;
+
+        writeLength( out, len );
+		out.write(dataValue, 0, dataValue.length);
+	}
+
+	/** 
+		Serialize a blob using the 8.1 encoding. Not called if null.
 
-		int len = dataValue.length;
+	 * @exception IOException		io exception
+	 */
+	private void writeBlob(ObjectOutput out) throws IOException
+	{
+        try {
+            int                 len = getBlobLength();
+            InputStream         is = _blobValue.getBinaryStream();
+            
+            writeLength( out, len );
+
+            for ( int i = 0; i < len; i++ )
+            {
+                out.write( is.read() );
+            }
+        }
+        catch (StandardException se) { throw new IOException( se.getMessage() ); }
+        catch (SQLException se) { throw new IOException( se.getMessage() ); }
+    }
+    
+	/** 
+		Write the length if
+		using the 8.1 encoding.
+
+	 * @exception IOException		io exception
+	 */
+    private void writeLength( ObjectOutput out, int len ) throws IOException
+    {
 		if (len <= 31)
 		{
 			out.write((byte) (0x80 | (len & 0xff)));
@@ -312,8 +397,7 @@
 			out.writeInt(len);
 
 		}
-		out.write(dataValue, 0, dataValue.length);
-	}
+    }
 
 	/** 
 	 * delegated to bit 
@@ -327,6 +411,7 @@
 		// stream is set by previous use.  Track 3794.
 		stream = null;
 		streamValueLength = -1;
+        _blobValue = null;
 
 
 		int len = SQLBinary.readBinaryLength(in);
@@ -347,6 +432,7 @@
 		// stream is set by previous use.  Track 3794.
 		stream = null;
 		streamValueLength = -1;
+        _blobValue = null;
 
 		int len = SQLBinary.readBinaryLength(in);
 
@@ -451,6 +537,7 @@
 	public final void restoreToNull()
 	{
 		dataValue = null;
+        _blobValue = null;
 		stream = null;
 		streamValueLength = -1;
 	}
@@ -532,8 +619,14 @@
 	 */
 	public final Object cloneObject()
 	{
-		if (stream == null)
-			return getClone();
+        if ( _blobValue != null )
+        {
+            SQLBinary self = (SQLBinary) getNewNull();
+            self.setValue(_blobValue);
+            return self;
+        }
+		if (stream == null) { return getClone(); }
+        
 		SQLBinary self = (SQLBinary) getNewNull();
 		self.setValue(stream, streamValueLength);
 		return self;
@@ -582,6 +675,7 @@
 	public final void setStream(InputStream newStream)
 	{
 		this.dataValue = null;
+        _blobValue = null;
 		this.stream = newStream;
 		streamValueLength = -1;
 	}
@@ -613,6 +707,7 @@
 	public final void setValue(InputStream theStream, int valueLength)
 	{
 		dataValue = null;
+        _blobValue = null;
 		stream = theStream;
 		this.streamValueLength = valueLength;
 	}
@@ -623,6 +718,7 @@
 		{
 			SQLBinary theValueBinary = (SQLBinary) theValue;
 			dataValue = theValueBinary.dataValue;
+            _blobValue = theValueBinary._blobValue;
 			stream = theValueBinary.stream;
 			streamValueLength = theValueBinary.streamValueLength;
 		}
@@ -1027,7 +1123,8 @@
 	{
 		// stream length checking occurs at the JDBC layer
 		int variableLength = -1;
-		if (stream == null)
+        if ( _blobValue != null ) { variableLength = -1; }
+		else if (stream == null)
 		{
 			if (dataValue != null)
 				variableLength = dataValue.length;
@@ -1052,7 +1149,7 @@
 	{
 		if (dataValue == null)
 		{
-			if (stream == null)
+			if ((stream == null) && (_blobValue == null) )
 			{
 				return "NULL";
 			}
@@ -1060,7 +1157,7 @@
 			{
 				if (SanityManager.DEBUG)
 					SanityManager.THROWASSERT(
-						"value is null, stream is not null");
+						"value is null, stream or blob is not null");
 				return "";
 			}
 		}
@@ -1169,4 +1266,21 @@
 
         return (getTypeName() + ":Length=" + getLength());
     }
+
+    private int getBlobLength() throws StandardException
+    {
+        try {
+            long   maxLength = Integer.MAX_VALUE;
+            long   length = _blobValue.length();
+            if ( length > Integer.MAX_VALUE )
+            {
+                throw StandardException.newException
+                    ( SQLState.BLOB_TOO_LARGE_FOR_CLIENT, Long.toString( length ), Long.toString(
maxLength ) );
+            }
+
+            return (int) length;
+        }
+        catch (SQLException se) { throw StandardException.plainWrapException( se ); }
+    }
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.java?rev=745202&r1=745201&r2=745202&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLBlob.java Tue Feb 17 19:24:26
2009
@@ -58,6 +58,11 @@
 			super(val);
         }
 	
+	public SQLBlob(Blob val)
+        {
+			super(val);
+        }
+	
 	public String getTypeName()
         {
 			return TypeId.BLOB_NAME;

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=745202&r1=745201&r2=745202&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 Tue Feb 17 19:24:26
2009
@@ -62,6 +62,8 @@
 import java.io.IOException;
 import java.io.UTFDataFormatException;
 import java.io.EOFException;
+import java.io.Reader;
+import java.sql.Clob;
 import java.sql.Date;
 import java.sql.ResultSet;
 import java.sql.PreparedStatement;
@@ -83,7 +85,7 @@
 SQLChar may be used directly by any code when it is guaranteed
 that the required collation is UCS_BASIC, e.g. system columns.
 <p>
-The state may be in char[], a String, or an unread stream, depending
+The state may be in char[], a String, a Clob, or an unread stream, depending
 on how the datatype was created.  
 <p>
 Stream notes:
@@ -178,6 +180,11 @@
     private CollationKey cKey; 
 
     /**
+     * The value as a user-created Clob
+     */
+    protected Clob _clobValue;
+    
+    /**
      * The value as a stream in the on-disk format.
      */
     InputStream stream;
@@ -203,6 +210,11 @@
         value = val;
     }
 
+    public SQLChar(Clob val)
+    {
+        setValue( val );
+    }
+
     /**************************************************************************
      * Private/Protected methods of This class:
      **************************************************************************
@@ -533,6 +545,7 @@
         this.rawLength = -1;
         this.stream = newStream;
         cKey = null;
+        _clobValue = null;
     }
 
     public void loadStream() throws StandardException
@@ -546,7 +559,8 @@
      */
     public Object   getObject() throws StandardException
     {
-        return getString();
+        if ( _clobValue != null ) { return _clobValue; }
+        else { return getString(); }
     }
 
     /**
@@ -585,6 +599,7 @@
      * @exception StandardException     Thrown on error
      */
     public int getLength() throws StandardException {
+        if ( _clobValue != null ) { return getClobLength(); }
         if (rawLength != -1)
             return rawLength;
         if (stream != null) {
@@ -665,6 +680,14 @@
                     cKey = null;
                 }
 
+            } else if (_clobValue != null) {
+
+                try {
+                    value = _clobValue.getSubString( 1L, getClobLength() );
+                    _clobValue = null;
+                }
+                catch (SQLException se) { throw StandardException.plainWrapException( se
); }
+                
             } else if (stream != null) {
 
                 // data stored as a stream
@@ -750,7 +773,7 @@
     */
     public boolean isNull()
     {
-        return ((value == null) && (rawLength == -1) && (stream == null));
+        return ((value == null) && (rawLength == -1) && (stream == null)
&& (_clobValue == null));
     }
 
     /**
@@ -809,6 +832,16 @@
         if (SanityManager.DEBUG)
             SanityManager.ASSERT(!isNull());
 
+        //
+        // This handles the case that a CHAR or VARCHAR value was populated from
+        // a user Clob.
+        //
+        if ( _clobValue != null )
+        {
+            writeClobUTF( out );
+            return;
+        }
+        
         String lvalue = null;
         char[] data = null;
 
@@ -851,7 +884,7 @@
         // Generate the header, write it to the destination stream, write the
         // user data and finally write an EOF-marker is required.
         header.generateInto(out, utflen);
-        writeUTF(out, strlen, isRaw);
+        writeUTF(out, strlen, isRaw, null );
         header.writeEOF(out, utflen);
     }
 
@@ -862,10 +895,11 @@
      * @param strLen string length of the value
      * @param isRaw {@code true} if the source is {@code rawData}, {@code false}
      *      if the source is {@code value}
+     * @param characterReader Reader from _clobValue if it exists
      * @throws IOException if writing to the destination stream fails
      */
     private final void writeUTF(ObjectOutput out, int strLen,
-                                final boolean isRaw)
+                                final boolean isRaw, Reader characterReader)
             throws IOException {
         // Copy the source reference into a local variable (optimization).
         final char[] data = isRaw ? rawData : null;
@@ -873,7 +907,11 @@
 
         // Iterate through the value and write it as modified UTF-8.
         for (int i = 0 ; i < strLen ; i++) {
-            int c = isRaw ? data[i] : lvalue.charAt(i);
+            int c;
+
+            if ( characterReader != null ) { c = characterReader.read(); }
+            else { c = isRaw ? data[i] : lvalue.charAt(i); }
+            
             if ((c >= 0x0001) && (c <= 0x007F))
             {
                 out.write(c);
@@ -904,18 +942,38 @@
             SanityManager.ASSERT(!isNull());
             SanityManager.ASSERT(stream == null, "Stream not null!");
         }
-        boolean isRaw = rawLength >= 0;
-        // Assume isRaw, update afterwards if required.
-        int strLen = rawLength;
-        if (!isRaw) {
-            strLen = value.length();
+
+        boolean  isUserClob = ( _clobValue != null );
+
+        try {
+
+            boolean isRaw = rawLength >= 0;
+            // Assume isRaw, update afterwards if required.
+            int strLen = rawLength;
+            if (!isRaw) {
+                if ( isUserClob ) { strLen = rawGetClobLength(); }
+                else { strLen = value.length(); }
+            }
+            // Generate the header and invoke the encoding routine.
+            StreamHeaderGenerator header = getStreamHeaderGenerator();
+            int toEncodeLen = header.expectsCharCount() ? strLen : -1;
+            header.generateInto(out, toEncodeLen);
+
+            Reader characterReader = null;
+            if ( isUserClob ) { characterReader = _clobValue.getCharacterStream(); }
+            
+            writeUTF(out, strLen, isRaw, characterReader );
+            header.writeEOF(out, toEncodeLen);
+            
+            if ( isUserClob ) { characterReader.close(); }
+        }
+        catch (SQLException se)
+        {
+            IOException ioe = new IOException( se.getMessage() );
+            ioe.initCause( se );
+
+            throw ioe;
         }
-        // Generate the header and invoke the encoding routine.
-        StreamHeaderGenerator header = getStreamHeaderGenerator();
-        int toEncodeLen = header.expectsCharCount() ? strLen : -1;
-        header.generateInto(out, toEncodeLen);
-        writeUTF(out, strLen, isRaw);
-        header.writeEOF(out, toEncodeLen);
     }
 
     /**
@@ -1268,10 +1326,11 @@
      */
     public Object cloneObject()
     {
-        if (stream == null)
-            return getClone();
+        if ((stream == null) && (_clobValue == null)) {  return getClone(); }
+        
         SQLChar self = (SQLChar) getNewNull();
         self.copyState(this);
+
         return self;
     }
 
@@ -1343,11 +1402,22 @@
 
 
 
+    public void setValue(Clob theValue)
+    {
+        stream = null;
+        rawLength = -1;
+        cKey = null;
+        value = null;
+
+        _clobValue = theValue;
+    }
+
     public void setValue(String theValue)
     {
         stream = null;
         rawLength = -1;
         cKey = null;
+        _clobValue = null;
 
         value = theValue;
     }
@@ -1585,6 +1655,16 @@
     protected void setFrom(DataValueDescriptor theValue) 
         throws StandardException 
     {
+        if ( theValue instanceof SQLChar )
+        {
+            SQLChar that = (SQLChar) theValue;
+
+            if ( that._clobValue != null )
+            {
+                setValue( that._clobValue );
+                return;
+            }
+        }
         setValue(theValue.getString());
     }
 
@@ -1719,7 +1799,7 @@
         /*
         ** If the input is NULL, nothing to do.
         */
-        if (getString() == null)
+        if ( (_clobValue == null ) && (getString() == null) )
         {
             return;
         }
@@ -2929,6 +3009,7 @@
         this.rawLength = other.rawLength;
         this.cKey = other.cKey;
         this.stream = other.stream;
+        this._clobValue = other._clobValue;
         this.localeFinder = localeFinder;
     }
 
@@ -2965,4 +3046,29 @@
     public void setSoftUpgradeMode(Boolean inSoftUpgradeMode) {
         // Ignore this for CHAR, VARCHAR and LONG VARCHAR.
     }
+    
+    private int getClobLength() throws StandardException
+    {
+        try {
+            return rawGetClobLength();
+        }
+        catch (SQLException se) { throw StandardException.plainWrapException( se ); }
+    }
+
+    private int rawGetClobLength() throws SQLException
+    {
+        long   maxLength = Integer.MAX_VALUE;
+        long   length = _clobValue.length();
+        if ( length > Integer.MAX_VALUE )
+        {
+            StandardException se = StandardException.newException
+                ( SQLState.BLOB_TOO_LARGE_FOR_CLIENT, Long.toString( length ), Long.toString(
maxLength ) );
+
+            throw new SQLException( se.getMessage() );
+        }
+
+        return (int) length;
+    }
+
+
 }

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=745202&r1=745201&r2=745202&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 Tue Feb 17 19:24:26
2009
@@ -160,6 +160,11 @@
 		super(val);
 	}
 
+	public SQLClob(Clob val)
+	{
+		super(val);
+	}
+
 	/*
 	 * DataValueDescriptor interface
 	 */
@@ -176,11 +181,6 @@
 	** that CLOB is towards the root, not at the leaf.
 	*/
 
-	public Object	getObject() throws StandardException
-	{
-		throw dataTypeConversion("java.lang.Object");
-	}
-
 	public boolean	getBoolean() throws StandardException
 	{
 		throw dataTypeConversion("boolean");

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLVarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLVarchar.java?rev=745202&r1=745201&r2=745202&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLVarchar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/SQLVarchar.java Tue Feb 17
19:24:26 2009
@@ -21,6 +21,7 @@
 
 package org.apache.derby.iapi.types;
 
+import java.sql.Clob;
 import java.text.RuleBasedCollator;
 
 import org.apache.derby.iapi.types.DataTypeDescriptor;
@@ -128,6 +129,11 @@
 		super(val);
 	}
 
+	public SQLVarchar(Clob val)
+	{
+		super(val);
+	}
+
 	/**
 	 * Normalization method - this method may be called when putting
 	 * a value into a SQLVarchar, for example, when inserting into a SQLVarchar

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=745202&r1=745201&r2=745202&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 Tue Feb
17 19:24:26 2009
@@ -21,6 +21,8 @@
 
 package org.apache.derby.iapi.types;
 
+import java.sql.Clob;
+
 import org.apache.derby.iapi.error.StandardException;
 
 import java.text.RuleBasedCollator;
@@ -234,4 +236,11 @@
      */
     public CharacterStreamDescriptor getStreamWithDescriptor()
             throws StandardException;
+
+
+	/**
+	 * Stuff a StringDataValue with a Clob.
+	 */
+	public void setValue( Clob value )
+		throws StandardException;
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiSignaturesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiSignaturesTest.java?rev=745202&r1=745201&r2=745202&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiSignaturesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AnsiSignaturesTest.java
Tue Feb 17 19:24:26 2009
@@ -363,21 +363,19 @@
             ( "timestamp_Timestamp_Timestamp", "timestamp", new String[] { "timestamp" },
"timestamp('1962-09-23 03:23:34.234')", "1962-09-23 03:23:34.234" );
     }
 
-    // FIXME
-    //    public  void    test_clob_Clob_String()
-    //        throws Exception
-    //    {
-    //        declareAndRunFunction
-    //            ( "clob_Clob_String", "clob", new String[] { "varchar( 10 )" }, "'3'",
"3" );
-    //    }
-
-    // FIXME
-    //    public  void    test_blob_Blob_String()
-    //        throws Exception
-    //    {
-    //        declareAndRunFunction
-    //            ( "blob_Blob_String", "blob", new String[] { "varchar( 10 )" }, "'3'",
"3" );
-    //    }
+    public  void    test_clob_Clob_String()
+        throws Exception
+    {
+        declareAndRunFunction
+            ( "clob_Clob_String", "clob", new String[] { "varchar( 10 )" }, "'3'", "3" );
+    }
+
+    public  void    test_blob_Blob_String()
+        throws Exception
+    {
+        declareAndRunFunction
+            ( "blob_Blob_String", "blob", new String[] { "varchar( 10 )" }, "'3'", "33" );
+    }
 
     ///////////////////////////////////////////////////////////////////////////////////
     //

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringColumnVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringColumnVTI.java?rev=745202&r1=745201&r2=745202&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringColumnVTI.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/StringColumnVTI.java
Tue Feb 17 19:24:26 2009
@@ -83,7 +83,13 @@
             return new ByteArrayInputStream( _bytes );
         }
         
-        public	byte[]	getBytes( long position, int length ) { return _bytes; }
+        public	byte[]	getBytes( long position, int length )
+        {
+            byte[]  result = new byte[ length ];
+            System.arraycopy( _bytes, ((int) position) - 1, result, 0, length );
+            
+            return result;
+        }
         
         public	long	length()
         {
@@ -171,7 +177,7 @@
         
         public	String	getSubString( long position, int length )
         {
-            return _contents.substring( (int) position, length );
+            return _contents.substring( ((int) position) - 1, length );
         }
 		
         public	long	length()

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Recovery.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Recovery.java?rev=745202&r1=745201&r2=745202&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Recovery.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Recovery.java
Tue Feb 17 19:24:26 2009
@@ -742,10 +742,10 @@
 
 			RecordHandle rh = t_util.t_insert(page, row);
 
-			DataValueDescriptor col0 = new SQLChar(null);
+			DataValueDescriptor col0 = new SQLChar((String)null);
 			DataValueDescriptor col1 = new SQLChar(REC_001);
 			DataValueDescriptor col2 = new SQLChar(REC_002);
-			DataValueDescriptor col3 = new SQLChar(null);
+			DataValueDescriptor col3 = new SQLChar((String)null);
 
 			if (page.updateFieldAtSlot(page.FIRST_SLOT_NUMBER, 0, col0, null) == null ||
 				page.updateFieldAtSlot(page.FIRST_SLOT_NUMBER, 1, col1, null) == null ||



Mime
View raw message