db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r909415 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/types/ engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Fri, 12 Feb 2010 14:09:50 GMT
Author: rhillegas
Date: Fri Feb 12 14:09:49 2010
New Revision: 909415

URL: http://svn.apache.org/viewvc?rev=909415&view=rev
Log:
DERBY-4499: Fix bug which prevented us from using UDTs as output args in database procedures.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java?rev=909415&r1=909414&r2=909415&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataType.java Fri Feb 12 14:09:49
2010
@@ -358,6 +358,17 @@
 	 * Set the value of this DataValueDescriptor.
 	 * At DataType level just throws an error lower classes will override
 	 *
+	 * @param theValue	The Object value to set this DataValueDescriptor to
+	 */
+	public void setValue(Object theValue) throws StandardException
+	{
+		throwLangSetMismatch("java.lang.Object");
+	}
+
+	/**
+	 * Set the value of this DataValueDescriptor.
+	 * At DataType level just throws an error lower classes will override
+	 *
 	 * @param theValue	The BigDecimal value to set this DataValueDescriptor to
 	 */
 	public void setValue(String theValue) throws StandardException

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java?rev=909415&r1=909414&r2=909415&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueDescriptor.java Fri
Feb 12 14:09:49 2010
@@ -446,6 +446,15 @@
 	public void setValue(boolean theValue) throws StandardException;
 
 	/**
+	 * Set the value of this DataValueDescriptor to the given Object value
+	 *
+	 * @param theValue	The value to set this DataValueDescriptor to
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	public void setValue(Object theValue) throws StandardException;
+
+	/**
 	 * Set the value of this DataValueDescriptor.
 	 *
 	 * @param theValue	The byte value to set this DataValueDescriptor to

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java?rev=909415&r1=909414&r2=909415&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
Fri Feb 12 14:09:49 2010
@@ -1162,6 +1162,7 @@
 						DataTypeDescriptor paramdtd = sqlParamNode.getTypeServices();
 
 						boolean isNumericType = paramdtd.getTypeId().isNumericTypeId();
+						boolean isAnsiUDT = paramdtd.getTypeId().getBaseTypeId().isAnsiUDT();
 
 						// is the underlying type for the OUT/INOUT parameter primitive.
 						boolean isPrimitive = ((java.lang.reflect.Method) method).getParameterTypes()[i].getComponentType().isPrimitive();
@@ -1194,6 +1195,12 @@
 							mb.upCast("java.lang.Number");
 						}
 
+						// The value needs to be set thorugh the setValue(Object) method.
+						if (isAnsiUDT)
+						{
+							mb.upCast("java.lang.Object");
+						}
+
 						mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "setValue", "void", 1);
 
 						if (paramdtd.getTypeId().variableLength()) {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java?rev=909415&r1=909414&r2=909415&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
Fri Feb 12 14:09:49 2010
@@ -23,6 +23,7 @@
 
 import java.sql.SQLException;
 import java.sql.SQLWarning;
+import java.sql.CallableStatement;
 import java.sql.Connection;
 import java.sql.Statement;
 import java.sql.PreparedStatement;
@@ -164,6 +165,17 @@
     }
 
     /**
+     * Prepare a callable statement and report its sql text.
+     */
+    protected CallableStatement   chattyPrepareCall( Connection conn, String text )
+        throws SQLException
+    {
+        println( "Preparing callable statement:\n\t" + text );
+        
+        return conn.prepareCall( text );
+    }
+
+    /**
      * Assert that the statement text, when compiled, raises an exception
      */
     protected void    expectCompilationError( String sqlState, String query )

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java?rev=909415&r1=909414&r2=909415&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UDTTest.java
Fri Feb 12 14:09:49 2010
@@ -22,6 +22,7 @@
 package org.apache.derbyTesting.functionTests.tests.lang;
 
 import java.math.BigDecimal;
+import java.sql.CallableStatement;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ParameterMetaData;
@@ -1196,6 +1197,34 @@
              );
     }
 
+    /**
+     * <p>
+     * Verify that you can use UDTs as output parameters in database procedures.
+     * </p>
+     */
+    public void test_17_outputParameters() throws Exception
+    {
+        Connection conn = getConnection();
+
+        goodStatement( conn, "create type intArray_17 external name 'org.apache.derbyTesting.functionTests.tests.lang.IntArray'
language java\n" );
+        goodStatement
+            ( conn,
+              "create procedure changeIntArray_17\n" +
+              "( in newSize int, inout oldIntArray intArray_17 )\n" +
+              "language java parameter style java no sql\n" +
+              "external name 'org.apache.derbyTesting.functionTests.tests.lang.UDTTest.changeIntArray'\n"
);
+        
+        CallableStatement cs = chattyPrepareCall( conn, "call changeIntArray_17( ?, ? )"
);
+        cs.registerOutParameter( 2, java.sql.Types.JAVA_OBJECT );
+        cs.setInt( 1, 2 );
+        cs.setObject( 2,  new IntArray( new int[ 5 ] ) );
+        cs.execute();
+        Object obj = cs.getObject( 2 );
+        cs.close();
+
+        assertEquals( "[ 0, 0 ]", obj.toString() );
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // PROCEDURES AND FUNCTIONS
@@ -1205,12 +1234,11 @@
     public static void oneArgPriceProc( Price price1 ) {}
     public static void twoArgPriceProc( Price price1, Price price2 ) {}
 
-    public static void changeCurrencyCode( String newCurrencyCode, Price[] price )
+    public static void changeIntArray( int newSize, IntArray[] array )
     {
-        Price oldPrice = price[ 0 ];
-        Price newPrice = new Price( newCurrencyCode, oldPrice.amount, oldPrice.timeInstant
);
+        IntArray newArray = new IntArray( new int[ newSize ] );
 
-        price[ 0 ] = newPrice;
+        array[ 0 ] = newArray;
     }
 
     public static HashMap makeHashMap() { return new HashMap(); }



Mime
View raw message