You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2012/10/16 20:25:12 UTC

svn commit: r1398914 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/types/ testing/org/apache/derbyTesting/functionTests/tests/lang/

Author: rhillegas
Date: Tue Oct 16 18:25:11 2012
New Revision: 1398914

URL: http://svn.apache.org/viewvc?rev=1398914&view=rev
Log:
DERBY-5951: Supply missing CLOB instantiator.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.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/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java?rev=1398914&r1=1398913&r2=1398914&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java Tue Oct 16 18:25:11 2012
@@ -21,6 +21,8 @@
 
 package org.apache.derby.iapi.types;
 
+import java.sql.Clob;
+
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
@@ -66,6 +68,16 @@ class CollatorSQLClob extends SQLClob im
         setCollator(collatorForCharacterDatatypes);
 	}
 
+    /**
+     * Create SQL CLOB value initially set to value that
+     * performs collation according to collatorForCharacterDatatypes 
+     */
+	CollatorSQLClob(Clob val, RuleBasedCollator collatorForCharacterDatatypes)
+	{
+		super(val);
+        setCollator(collatorForCharacterDatatypes);
+	}
+
 	/**
 	 * Set the RuleBasedCollator for this instance of CollatorSQLClob. It will
 	 * be used to do the collation.
@@ -136,7 +148,7 @@ class CollatorSQLClob extends SQLClob im
 	 */
 	public DataValueDescriptor getNewNull()
 	{
-		CollatorSQLClob result = new CollatorSQLClob(null,
+		CollatorSQLClob result = new CollatorSQLClob((String) null,
 				holderForCollationSensitiveInfo.getCollatorForCollation());
 		return result;
 	}

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=1398914&r1=1398913&r2=1398914&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 Oct 16 18:25:11 2012
@@ -244,6 +244,18 @@ public interface DataValueFactory
                 int collationType) throws StandardException;
 
         /**
+         * Get a StringDataValue to represent a SQL CLOB 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
+         * to the value passed in and returned, otherwise a new StringDataValue
+         * will be created and set to the value.
+         * If collationType is equal to StringDataValue.COLLATION_TYPE_UCS_BASIC
+         * then the call is the equivalent of the overload without collationType.
+         */
+        StringDataValue getClobDataValue(Clob value, StringDataValue previous,
+                int collationType) throws StandardException;
+
+        /**
          * Get a User-defined data value with the given value and type name.
          * A null argument means get a SQL null value.  The second arg uses
          * the previous value (if non-null) hold the return value.

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=1398914&r1=1398913&r2=1398914&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 Oct 16 18:25:11 2012
@@ -519,6 +519,22 @@ abstract class DataValueFactoryImpl impl
             return previous;
         }
 
+        public StringDataValue getClobDataValue(Clob value,
+                StringDataValue previous, int collationType)
+            throws StandardException
+        {
+            if (collationType == StringDataValue.COLLATION_TYPE_UCS_BASIC)
+                return getClobDataValue(value, previous);
+            
+            if (previous == null)
+            {
+                return new CollatorSQLClob(value,
+                        getCharacterCollator(collationType));
+            }
+            
+            previous.setValue(value);
+            return previous;
+        }
     
         /**
          * Return a StringDataValue to represent a SQL CLOB

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?rev=1398914&r1=1398913&r2=1398914&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java Tue Oct 16 18:25:11 2012
@@ -21,6 +21,7 @@
 
 package org.apache.derbyTesting.functionTests.tests.lang;
 
+import java.sql.Clob;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
@@ -37,6 +38,8 @@ import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.derby.iapi.types.HarmonySerialClob;
+
 import org.apache.derbyTesting.functionTests.tests.jdbcapi.BatchUpdateTest;
 import org.apache.derbyTesting.functionTests.tests.jdbcapi.DatabaseMetaDataTest;
 import org.apache.derbyTesting.functionTests.tests.nist.NistScripts;
@@ -2150,4 +2153,34 @@ public void testMissingCollatorSupport()
 		  : Decorator.territoryCollatedDatabase(suite, locale);
   }
 
+    /**
+     * Test for an overload which was missing.
+     */
+    public void test_5951() throws Exception
+    {
+        Statement s = createStatement();
+        
+        ResultSet rs = null;
+        s.execute("CREATE TABLE derby5951( a clob )");
+        s.execute
+            (
+             "create function makeClob( contents varchar( 32672 ) ) returns clob\n" +
+             "language java parameter style java no sql deterministic\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.CollationTest.makeClob'\n"
+             );
+        s.executeUpdate("INSERT INTO derby5951 VALUES( makeClob( 'a' ) )");
+        rs = s.executeQuery("select * from derby5591");
+        JDBC.assertFullResultSet(rs,
+                                 new String[][] {{"a"}});
+        
+        s.executeUpdate("DROP TABLE derby5591");
+        s.executeUpdate("DROP function makeClob");
+    }
+
+   /** Clob-creating function */
+    public  static  Clob    makeClob( String contents ) throws Exception
+    {
+        return new HarmonySerialClob( contents );
+    }
+
 }