db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r291045 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/ master/j9_13/ tests/jdbcapi/ tests/lang/ util/
Date Fri, 23 Sep 2005 00:08:42 GMT
Author: kmarsden
Date: Thu Sep 22 17:08:32 2005
New Revision: 291045

URL: http://svn.apache.org/viewcvs?rev=291045&view=rev
Log:
DERBY-453
Create a test wrapper to run tests using BigDecimal in J2ME/CDC/Foundation

This patch (derby_453_outparams_patch1.diff) changes tests.

* It enables the tests which use procedures in outparams.java to run in J2ME/CDC/FP. The following
tests have been enabled:
         - lang/lang/outparams.java
         - jdbcapi/batchUpdate.java
         - jdbcapi/StmtCloseFunTest.java


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Changes to outparams.java:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

* The methods 'takesBigDecimal' and 'returnsBigDecimal' are moved from outparams.java to a
new class outparams30.java. These methods use java.Math.BigDecimal class which is not available
in J2ME. This separation is needed because Connection.prepareCall looks at all the public
methods available in the specified class. If the class has any public method using BigDecimal,
it will fail in J2ME.

* For procedure names, outparams class will be used for J2ME and outparams30 for non-J2ME.

* Variables HAVE_BIGDECIMAL and CLASS_NAME are added to outparams.java. Depending on the availability
of BigDecimal class in the JVM, CLASS_NAME is initialized to outparams or outparams30. CLASS_NAME
is used in the create procedure SQL instead of "org.apache.derbyTesting.functionTests.tests.lang.outparams.".

* The content of the arrays 'outputMethods' and 'returnMethods' are also decided based on
value of HAVE_BIGDECIMAL. For J2ME, takesBigDecimal and returnsBigDecimal are removed from
these arrays. To minimize changes to the master file, the order of these arrays is kept same.
An if/else loop is used to determine which array will be used.

* callSetMethod, callSetObject and callGetMethod are changed to use wrapper methods in BigDecimalHandler
class. An additional parameter 'int paramType' is passed to callGetMethod. This is needed
because ParameterMetaData is not available in JSR19. A new array 'paramJDBCType' with the
JDBC types (java.sql.Types) for the corresponding methods is used to get the param type for
a method. When creating this array, I noticed that outputMethods and returnMethods do not
match. To make them match, a null value has been removed from outputMethods and outProcParam
arrays.
* testMisc method used returnsBigDecimal to check that a set cannot be called on an output
param. This check is independent of the type of output param and so returnsString is used
intstead.

* test5116 method uses a procedure with nested connection, which uses java.sql.Driver. This
is not available in JSR169. So this test is done only for non-JSR169 environments based on
value of HAVE_DRIVER_CLASS.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Changes to org.apache.derbyTesting.functionTests.util.BigDecimalHandler.java:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Added wrappers for following methods:
CallableStatement method getBigDecimal(int parameterIndex)
PreparedStatement method setBigDecimal(int parameterIndex,BigDecimal x)
PreparedStatement method setObject(int parameterIndex, Object x)

* Fixed the type conversions and moved it to an array, which is used in the method canConvertToDecimal.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Changes to master files:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* The master files for main and j9_13 are modified to use returnsBigDecimal instead of returnsString
in output for testMisc method. On comparing the two master files, they are identical. I think
the master file for j9_13 can be removed. I have not done it in this patch. Is it okay to
do this?

* Added a master file for j9_foundation. This is needed because of the following:
- takesBigDecimal and returnsBigDecimal methods are not in outputMethods/returnMehtods.
- The exception strings for type conversion and invalid character format are different because
of use of wrapper methods.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Changes to <testname>_app.properties:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Removed excludes for J2ME for following tests:
- lang/outparams.java
- jdbcapi/batchUpdate.java
- jdbcapi/StmtCloseFunTest.java

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Changes to tests which use procedures in outparams.java
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* jdbcapi/batchUpdate.java and jdbcapi/StmtCloseFunTest.java are modified to use outparams/outparams30
depending on value of HAVE_BIG_DECIMAL.

* jdbcapi/StmtCloseFunTest.java was using a deprecated constructor for java.sql.Date, which
is not available in JSR169. So the constructor java.sql.Date(long) is used instead.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Tests Run
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This patch changes tests only. I had run derbyall in J2SE and J2ME. 1 expected failure in
J2ME. But I made few changes before submitting this patch. After the changes, I ran the individual
tests successfully.
-------------------------------------------------------------------------
	Contributed by Deepa Remesh


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams30.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/outparams.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BigDecimalHandler.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/outparams.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/outparams.out?rev=291045&r1=291044&r2=291045&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/outparams.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/j9_13/outparams.out
Thu Sep 22 17:08:32 2005
@@ -6,7 +6,7 @@
 Expected exception SQL Exception: The parameter position '0' is out of range.  The number
of parameters for this prepared  statement is '2'.
 Expected exception SQL Exception: Return output parameters cannot be set.
 Expected exception SQL Exception: Return output parameters cannot be set.
-Expected exception on setBigDecimal() on a return output param: SQL Exception: Return output
parameters cannot be set.
+Expected exception on setString() on a return output param: SQL Exception: Return output
parameters cannot be set.
 Expected exception on prepare of '? = call returnsNothing()': SQL Exception: 'RETURNSNOTHING'
is not recognized as a function or procedure.
 ==============================================
 TESTING NULLS

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out?rev=291045&r1=291044&r2=291045&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
Thu Sep 22 17:08:32 2005
@@ -6,7 +6,7 @@
 Expected exception SQL Exception: The parameter position '0' is out of range.  The number
of parameters for this prepared  statement is '2'.
 Expected exception SQL Exception: Return output parameters cannot be set.
 Expected exception SQL Exception: Return output parameters cannot be set.
-Expected exception on setBigDecimal() on a return output param: SQL Exception: Return output
parameters cannot be set.
+Expected exception on setString() on a return output param: SQL Exception: Return output
parameters cannot be set.
 Expected exception on prepare of '? = call returnsNothing()': SQL Exception: 'RETURNSNOTHING'
is not recognized as a function or procedure.
 ==============================================
 TESTING NULLS

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java?rev=291045&r1=291044&r2=291045&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest.java
Thu Sep 22 17:08:32 2005
@@ -31,11 +31,27 @@
 import java.sql.Types;
 import java.util.GregorianCalendar;
 import org.apache.derby.iapi.reference.JDBC20Translation;
+import org.apache.derbyTesting.functionTests.util.BigDecimalHandler;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
 
 public class StmtCloseFunTest {
     
-
+	private static boolean HAVE_BIG_DECIMAL;
+	private static String CLASS_NAME;
+	
+	//Get the class name to be used for the procedures
+	//outparams - J2ME; outparams30 - non-J2ME
+	static{
+		if(BigDecimalHandler.representation != BigDecimalHandler.BIGDECIMAL_REPRESENTATION)
+			HAVE_BIG_DECIMAL = false;
+		else
+			HAVE_BIG_DECIMAL = true;
+		if(HAVE_BIG_DECIMAL)
+			CLASS_NAME = "org.apache.derbyTesting.functionTests.tests.lang.outparams30.";
+		else
+			CLASS_NAME = "org.apache.derbyTesting.functionTests.tests.lang.outparams.";
+	}
+	
 	static private boolean isDerbyNet = false;
 
     public static void main(String[] args) {
@@ -301,7 +317,7 @@
 		   	*/
 		   	ps.setInt(1, 420);
 		   	ps.setFloat(2, (float)12.21);
-		   	ps.setDate(3, new Date(1971, 1, 10));
+		   	ps.setDate(3, new Date(870505200000L));
 		   	ps.setString(4, "China");
 		   	ps.executeUpdate();
 		   	ps.close();
@@ -320,13 +336,13 @@
 			catch(SQLException e) { }
 
 			try {
-				ps.setDate(3, new Date(1975, 11, 15));
+				ps.setDate(3, new Date(870505200000L));
 				System.out.println("Prepared Statement Test failed");
 			}
 			catch(SQLException e) { }
 
 			try {
-				ps.setDate(3, new Date(1975, 11, 15), new GregorianCalendar());
+				ps.setDate(3, new Date(870505200000L), new GregorianCalendar());
 				System.out.println("Prepared Statement Test failed");
 			}
 			catch(SQLException e) { }
@@ -541,7 +557,7 @@
 				Statement s = conn.createStatement();
 
 				s.execute("CREATE PROCEDURE takesString(OUT P1 VARCHAR(40), IN P2 INT) " +
-						"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.takesString'"
+
+						"EXTERNAL NAME '" + CLASS_NAME + "takesString'" +
 						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest_app.properties?rev=291045&r1=291044&r2=291045&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StmtCloseFunTest_app.properties
Thu Sep 22 17:08:32 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.math.BigDecimal
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate.java?rev=291045&r1=291044&r2=291045&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate.java
Thu Sep 22 17:08:32 2005
@@ -35,8 +35,25 @@
 
 import org.apache.derby.tools.ij;
 import org.apache.derby.tools.JDBCDisplayUtil;
+import org.apache.derbyTesting.functionTests.util.BigDecimalHandler;
 
 public class batchUpdate { 
+	
+	private static boolean HAVE_BIG_DECIMAL;
+	private static String CLASS_NAME;
+	
+	//Get the class name to be used for the procedures
+	//outparams - J2ME; outparams30 - non-J2ME
+	static{
+		if(BigDecimalHandler.representation != BigDecimalHandler.BIGDECIMAL_REPRESENTATION)
+			HAVE_BIG_DECIMAL = false;
+		else
+			HAVE_BIG_DECIMAL = true;
+		if(HAVE_BIG_DECIMAL)
+			CLASS_NAME = "org.apache.derbyTesting.functionTests.tests.lang.outparams30.";
+		else
+			CLASS_NAME = "org.apache.derbyTesting.functionTests.tests.lang.outparams.";
+	}
 
 	public static void main(String[] args) {
 		boolean		passed = true;
@@ -1518,7 +1535,7 @@
 		Statement s = conn.createStatement();
 
 		s.execute("CREATE PROCEDURE takesString(OUT P1 VARCHAR(40), IN P2 INT) " +
-				"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.takesString'"
+
+				"EXTERNAL NAME '" + CLASS_NAME + "takesString'" +
 				" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
   	CallableStatement cs = conn.prepareCall("call takesString(?,?)");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate_app.properties?rev=291045&r1=291044&r2=291045&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/batchUpdate_app.properties
Thu Sep 22 17:08:32 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.math.BigDecimal
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams.java?rev=291045&r1=291044&r2=291045&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams.java
Thu Sep 22 17:08:32 2005
@@ -26,48 +26,119 @@
 import java.io.PrintStream;
 import java.math.BigInteger;
 import java.math.BigDecimal;
+import org.apache.derbyTesting.functionTests.util.BigDecimalHandler;
 
 public class outparams
 {
- 
-	static final String outputMethods[] =
-	{
-		"takesNothing",
-
-		null, 
-	
-		null,
-		null,
-	
-		"takesShortPrimitive",
-		null,
-	
-		"takesIntegerPrimitive",
-		null,
-	
-		"takesLongPrimitive",
-		null,
-	
-		"takesFloatPrimitive",
-		null,
-	
-		"takesDoublePrimitive",
-		null,
-	
-		"takesBigDecimal",
 	
-		"takesByteArray",
-		
-		"takesString",
-		
-		"takesDate",
-		
-		"takesTimestamp",
-	
-		"takesTime",
+	private static boolean HAVE_BIG_DECIMAL;
+	private static boolean HAVE_DRIVER_CLASS;
+	private static String CLASS_NAME;
+	
+	//Get the class name to be used for the procedures
+	//outparams - J2ME; outparams30 - non-J2ME
+	static{
+		if(BigDecimalHandler.representation != BigDecimalHandler.BIGDECIMAL_REPRESENTATION)
+			HAVE_BIG_DECIMAL = false;
+		else
+			HAVE_BIG_DECIMAL = true;
+		if(HAVE_BIG_DECIMAL)
+			CLASS_NAME = "org.apache.derbyTesting.functionTests.tests.lang.outparams30.";
+		else
+			CLASS_NAME = "org.apache.derbyTesting.functionTests.tests.lang.outparams.";
+	}
 	
-		null
-	};
+	static{
+		try{
+			Class.forName("java.sql.Driver");
+			HAVE_DRIVER_CLASS = true;
+		}
+		catch(ClassNotFoundException e){
+			//Used for JSR169
+			HAVE_DRIVER_CLASS = false;
+		}
+	}
+	
+	static String[] outputMethods;
+	//Get the array to be used based on HAVE_BIG_DECIMAL
+	static{
+		if(HAVE_BIG_DECIMAL){
+			outputMethods = new String[] {
+									"takesNothing",
+							
+									null, 
+								
+									null,
+																	
+									"takesShortPrimitive",
+									null,
+								
+									"takesIntegerPrimitive",
+									null,
+								
+									"takesLongPrimitive",
+									null,
+								
+									"takesFloatPrimitive",
+									null,
+								
+									"takesDoublePrimitive",
+									null,
+								
+									"takesBigDecimal",
+								
+									"takesByteArray",
+									
+									"takesString",
+									
+									"takesDate",
+									
+									"takesTimestamp",
+								
+									"takesTime",
+								
+									null
+								};
+		}
+		else{
+			outputMethods = new String[] {
+									"takesNothing",
+							
+									null, 
+								
+									null,
+																	
+									"takesShortPrimitive",
+									null,
+								
+									"takesIntegerPrimitive",
+									null,
+								
+									"takesLongPrimitive",
+									null,
+								
+									"takesFloatPrimitive",
+									null,
+								
+									"takesDoublePrimitive",
+									null,
+								
+									null,
+								
+									"takesByteArray",
+									
+									"takesString",
+									
+									"takesDate",
+									
+									"takesTimestamp",
+								
+									"takesTime",
+								
+									null
+								};			
+		}
+	}
 
 	// parameter types for outputMethods.
 	private static final String[] outputProcParam =
@@ -77,8 +148,7 @@
 		null, 
 	
 		null,
-		null,
-	
+			
 		"SMALLINT", // "takesShortPrimitive",
 		null,
 	
@@ -108,46 +178,87 @@
 	
 		null
 	};
-
-	
-	static final String returnMethods[] =
-	{
-		"returnsNothing",
-
-		null,
-		null,
-	
-		"returnsShortP",
-		null,
-	
-		"returnsIntegerP",
-		null,
-	
-		"returnsLongP",
-		null,
-	
-		"returnsFloatP",
-		null,
-	
-		"returnsDoubleP",
-		null,
-	
-		"returnsBigDecimal",
-	
-		"returnsByteArray",
-		
-		"returnsString",
-		
-		"returnsDate",
 		
-		"returnsTimestamp",
-	
-		"returnsTime",
+	static String returnMethods[];
+	//Get the array to be used based on HAVE_BIG_DECIMAL
+	static{
+		if(HAVE_BIG_DECIMAL){
+			returnMethods = new String[] 	{
+									"returnsNothing",
+				
+									null,
+									null,
+								
+									"returnsShortP",
+									null,
+								
+									"returnsIntegerP",
+									null,
+								
+									"returnsLongP",
+									null,
+								
+									"returnsFloatP",
+									null,
+								
+									"returnsDoubleP",
+									null,
+								
+									"returnsBigDecimal",
+								
+									"returnsByteArray",
+									
+									"returnsString",
+									
+									"returnsDate",
+									
+									"returnsTimestamp",
+								
+									"returnsTime",
+								
+									null
+								};
+		}
+		else{
+			returnMethods = new String[] 	{
+									"returnsNothing",
+				
+									null,
+									null,
+								
+									"returnsShortP",
+									null,
+								
+									"returnsIntegerP",
+									null,
+								
+									"returnsLongP",
+									null,
+								
+									"returnsFloatP",
+									null,
+								
+									"returnsDoubleP",
+									null,
+								
+									null,
+								
+									"returnsByteArray",
+									
+									"returnsString",
+									
+									"returnsDate",
+									
+									"returnsTimestamp",
+								
+									"returnsTime",
+								
+									null
+								};
+		}
+	}
 	
-		null
-	};
-
-	static final String[] returnMethodType =
+	static String[] returnMethodType =
 	{
 		null, // "returnsNothing",
 
@@ -184,6 +295,44 @@
 		null, // "returnsBigInteger"
 	};
 	
+	//JDBC type (java.sql.Types) corresponding to the methods
+	static int[] paramJDBCType =
+	{
+		Types.NULL, // "returnsNothing",
+
+		Types.NULL, // "returnsBytePrimitive",
+		Types.NULL, // "returnsByte",
+	
+		Types.SMALLINT, // "returnsShortPrimitive",
+		Types.NULL, // "returnsShort",
+	
+		Types.INTEGER, // "returnsIntegerPrimitive",
+		Types.NULL, // "returnsInteger",
+	
+		Types.BIGINT, // "returnsLongPrimitive",
+		Types.NULL, // "returnsLong",
+	
+		Types.REAL, // "returnsFloatPrimitive",
+		Types.NULL, // "returnsFloat",
+	
+		Types.DOUBLE, // "returnsDoublePrimitive",
+		Types.NULL, // "returnsDouble",
+	
+		Types.NUMERIC, // "returnsBigDecimal",
+	
+		Types.VARBINARY, // "returnsByteArray",
+		
+		Types.VARCHAR, // "returnsString",
+		
+		Types.DATE, // "returnsDate",
+		
+		Types.TIMESTAMP, // "returnsTimestamp",
+	
+		Types.TIME, // "returnsTime",
+	
+		Types.NULL, // "returnsBigInteger"
+	};	
+	
 	static final int types[] =
 	{
 		Types.BIT,
@@ -255,7 +404,9 @@
 		testReturnTypes(conn);
 		testOtherOutputType(conn);
 		testManyOut(conn);
-		test5116(conn);
+		//Uses a procedure with nested connection - Cannot be tested with JSR169
+		if(HAVE_DRIVER_CLASS)
+			test5116(conn);
 	}
 
 	private static void testMisc(Connection conn) throws Throwable
@@ -267,7 +418,7 @@
 		Statement scp = conn.createStatement();
 
 		scp.execute("CREATE PROCEDURE takesString(OUT P1 VARCHAR(40), IN P2 INT) " +
-						"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.takesString'"
+
+						"EXTERNAL NAME '" + CLASS_NAME + "takesString'" +
 						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 		CallableStatement cs = conn.prepareCall("call takesString(?,?)");
@@ -368,27 +519,27 @@
 		cs.close();
 		scp.execute("DROP PROCEDURE takesString");
 
-		scp.execute("CREATE FUNCTION returnsBigDecimal(P2 INT) RETURNS DECIMAL(10,2) " +
-						"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.returnsBigDecimal'"
+
+		scp.execute("CREATE FUNCTION returnsString(P2 INT) RETURNS VARCHAR(40) " +
+						"EXTERNAL NAME '" + CLASS_NAME + "returnsString'" +
 						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 		// return output params -- cannot do set on return output param
-		cs = conn.prepareCall("? = call returnsBigDecimal(?)");
+		cs = conn.prepareCall("? = call returnsString(?)");
 		try
 		{
-			cs.setBigDecimal(1, new BigDecimal(1d));
-			System.out.println("ERROR: setBigDecimal() on return output parameter succeeded");
+			cs.setString(1, new String("test"));
+			System.out.println("ERROR: setString() on return output parameter succeeded");
 		}
 		catch (SQLException se)
 		{
-			System.out.println("Expected exception on setBigDecimal() on a return output param: "+se);
+			System.out.println("Expected exception on setString() on a return output param: "+se);
 		}
 		cs.close();
-		scp.execute("DROP FUNCTION returnsBigDecimal");
+		scp.execute("DROP FUNCTION returnsString");
 
 		// lets try ? = call syntax on a call that doesn't return anything
 		
 		scp.execute("CREATE PROCEDURE returnsNothing() " +
-						"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.returnsNothing'"
+
+						"EXTERNAL NAME '" + CLASS_NAME + "returnsNothing'" +
 						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 		try
 		{
@@ -413,7 +564,7 @@
 		Statement scp = conn.createStatement();
 
 		scp.execute("CREATE PROCEDURE testNullBug4317(IN P1 VARCHAR(10)) " +
-						"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.testNullBug4317'"
+
+						"EXTERNAL NAME '" + CLASS_NAME + "testNullBug4317'" +
 						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 
@@ -454,7 +605,7 @@
 		Statement scp = conn.createStatement();
 
 		scp.execute("CREATE FUNCTION returnsIntegerP(P1 INT) RETURNS INTEGER " +
-						"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.returnsIntegerP'"
+
+						"EXTERNAL NAME '" + CLASS_NAME + "returnsIntegerP'" +
 						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 
@@ -515,19 +666,19 @@
 				{
 
 					scp.execute("CREATE PROCEDURE " + methodName + "(INOUT P1 " + outputProcParam[method]
+ ", IN P2 INT) " +
-						"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams." + methodName
+
+						"EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
 						"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 
 					if (method%2 == 0)
-						str = "call "+methodName+"(?,?)";
-					else
 						str = "{call "+methodName+"(?,?)}";
+					else
+						str = "call "+methodName+"(?,?)";
 				}
 				else
 				{
 					scp.execute("CREATE PROCEDURE " + methodName + "() " +
-						"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams." + methodName
+
+						"EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
 						"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 					str = "{call "+methodName+"()}";
 				}
@@ -604,7 +755,7 @@
 						StringBuffer getbuf = new StringBuffer();
 						try
 						{
-							callGetMethod(cs, 1, types[getType], getbuf);
+							callGetMethod(cs, 1, types[getType], paramJDBCType[method], getbuf);
 						}
 						catch (SQLException se)
 						{
@@ -649,19 +800,19 @@
 			{
 
 				scp.execute("CREATE PROCEDURE " + methodName + "(INOUT P1 " + outputProcParam[method]
+ ", IN P2 INT) " +
-					"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams." + methodName
+
+					"EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
 					"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 
 				if (method%2 == 0)
-					str = "call "+methodName+"(?,?)";
-				else
 					str = "{call "+methodName+"(?,?)}";
+				else
+					str = "call "+methodName+"(?,?)";
 			}
 			else
 			{
 				scp.execute("CREATE PROCEDURE " + methodName + "() " +
-					"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams." + methodName
+
+					"EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
 					"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 				str = "{call "+methodName+"()}";
 			}
@@ -721,7 +872,7 @@
 					StringBuffer getbuf = new StringBuffer();
 					try
 					{
-						callGetMethod(cs, 1, types[getType], getbuf);
+						callGetMethod(cs, 1, types[getType], Types.OTHER , getbuf);
 					}
 					catch (SQLException se)
 					{
@@ -760,7 +911,7 @@
 			{
 
 				scf.execute("CREATE PROCEDURE " + methodName + "()" +
-					" EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams." + methodName
+
+					" EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
 					"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 
@@ -772,7 +923,7 @@
 			{
 
 				scf.execute("CREATE FUNCTION " + methodName + "(P1 INT) RETURNS " + returnMethodType[method]
+
-					" EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams." + methodName
+
+					" EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
 					"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 				dropRoutine = "DROP FUNCTION " + methodName;
 
@@ -837,7 +988,7 @@
 					StringBuffer getbuf = new StringBuffer();
 					try
 					{
-						callGetMethod(cs, 1, types[getType], getbuf);
+						callGetMethod(cs, 1, types[getType], paramJDBCType[method], getbuf);
 					}
 					catch (SQLException se)
 					{
@@ -902,8 +1053,7 @@
 			case Types.DECIMAL:
 			case Types.NUMERIC:
 				strbuf.append("setObject("+arg+", 666.666)");
-				BigDecimal bd = new BigDecimal("666.666");
-				cs.setObject(arg, bd);
+				BigDecimalHandler.setObjectString(cs,arg,"666.666");
 				break;
 
 			case Types.CHAR:
@@ -990,8 +1140,7 @@
 			case Types.DECIMAL:
 			case Types.NUMERIC:
 				strbuf.append("setBigDecimal("+arg+", 666.666)");
-				BigDecimal bd = new BigDecimal("666.666");
-				cs.setBigDecimal(arg, bd);
+				BigDecimalHandler.setBigDecimalString(cs,arg,"666.666");
 				break;
 
 			case Types.CHAR:
@@ -1035,7 +1184,7 @@
 		}	
 	}
 
-	private static void callGetMethod(CallableStatement cs, int arg, int type, StringBuffer
strbuf) throws Throwable
+	private static void callGetMethod(CallableStatement cs, int arg, int type, int paramType
,StringBuffer strbuf) throws Throwable
 	{
 		switch (type)	
 		{
@@ -1079,8 +1228,7 @@
 			case Types.DECIMAL:
 			case Types.NUMERIC:
 				strbuf.append("getBigDecimal("+arg+") = ");
-				BigDecimal bd = cs.getBigDecimal(arg);
-				strbuf.append(bd == null ? "null" : bd.toString());
+				strbuf.append(BigDecimalHandler.getBigDecimalString(cs,arg,paramType));
 				break;
 
 			case Types.CHAR:
@@ -1289,12 +1437,6 @@
 		outparam[0] = new Boolean(true);
 	}
 
-	public static void takesBigDecimal(BigDecimal[] outparam, int type)
-	{
-		outparam[0] = (outparam[0] == null ? new BigDecimal("33") : outparam[0].add(outparam[0]));
-		outparam[0].setScale(4, BigDecimal.ROUND_DOWN);
-	}
-
 	public static void takesByteArray(byte[][] outparam, int type)
 	{
 		byte[] myarray = new byte[16];
@@ -1391,12 +1533,6 @@
 		return new Double(666);
 	}
 
-
-	public static BigDecimal returnsBigDecimal(int type)
-	{
-		return new BigDecimal(666d);
-	}
-
 	public static byte[] returnsByteArray(int type)
 	{
 		byte[] myarray = new byte[16];
@@ -1441,14 +1577,14 @@
 			"(OUT I1 INT, OUT I2 INT, OUT I3 INT, OUT I4 INT, OUT I5 INT, "+
 			"OUT V1 VARCHAR(40), OUT V2 VARCHAR(40), OUT V3 VARCHAR(40), OUT V4 VARCHAR(40), OUT V5
VARCHAR(40)) "+
 
-			"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.output' NO
SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
+			"EXTERNAL NAME '" + CLASS_NAME + "output' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 
 		scp.execute("CREATE PROCEDURE OP_INOUT " +
 			"(INOUT I1 INT, INOUT I2 INT, INOUT I3 INT, INOUT I4 INT, INOUT I5 INT, " +
 			"INOUT V1 VARCHAR(40), INOUT V2 VARCHAR(40), INOUT V3 VARCHAR(40), INOUT V4 VARCHAR(40),
INOUT V5 VARCHAR(40)) " +
 
-			"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.output' NO
SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
+			"EXTERNAL NAME '" + CLASS_NAME + "output' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 
 		CallableStatement csOut_cs = conn.prepareCall("CALL OP_OUT(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
@@ -1583,7 +1719,7 @@
     "PRIMARY KEY ( AIID ) )");
 
 		stmt.execute("CREATE PROCEDURE doInsertion(IN P1 VARCHAR(2) FOR BIT DATA) " +
-						"EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.outparams.doInsertion'"
+
+						"EXTERNAL NAME '" + CLASS_NAME + "doInsertion'" +
 						" MODIFIES SQL DATA LANGUAGE JAVA PARAMETER STYLE JAVA");
 
 		CallableStatement cs = conn.prepareCall("call doInsertion (?)");

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams30.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams30.java?rev=291045&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams30.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams30.java
Thu Sep 22 17:08:32 2005
@@ -0,0 +1,48 @@
+/*
+
+Derby - Class org.apache.derbyTesting.functionTests.tests.lang.outparams30
+
+Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+*/
+
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.math.BigDecimal;
+
+/**
+ * outparams30 contains java procedures using java.math.BigDecimal.
+ * These are moved to this class to enable tests using other procedures
+ * in outparams.java to run in J2ME/CDC/FP.
+ *   
+ * @author deepa
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class outparams30 extends outparams {
+	
+	public static void takesBigDecimal(BigDecimal[] outparam, int type)
+	{
+		outparam[0] = (outparam[0] == null ? new BigDecimal("33") : outparam[0].add(outparam[0]));
+		outparam[0].setScale(4, BigDecimal.ROUND_DOWN);
+	}
+	
+	public static BigDecimal returnsBigDecimal(int type)
+	{
+		return new BigDecimal(666d);
+	}
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams30.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams_app.properties?rev=291045&r1=291044&r2=291045&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/outparams_app.properties
Thu Sep 22 17:08:32 2005
@@ -1,5 +1,2 @@
-#Exclude for J2ME/Foundation - test requires java.math.BigDecimal
-runwithfoundation=false
-
 usedefaults=true
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BigDecimalHandler.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BigDecimalHandler.java?rev=291045&r1=291044&r2=291045&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BigDecimalHandler.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BigDecimalHandler.java
Thu Sep 22 17:08:32 2005
@@ -21,6 +21,9 @@
 package org.apache.derbyTesting.functionTests.util;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.math.BigDecimal;
 
 /**
  *  BigDecimalHandler provides wrappers for JDBC API methods which use BigDecimal.
@@ -33,9 +36,9 @@
  */
 public class BigDecimalHandler {
 	
-	static int representation;
-	static final int STRING_REPRESENTATION = 1;
-	static final int BIGDECIMAL_REPRESENTATION = 2;
+	public static int representation;
+	public static final int STRING_REPRESENTATION = 1;
+	public static final int BIGDECIMAL_REPRESENTATION = 2;
 	
 	static{
 		try{
@@ -48,6 +51,24 @@
 		}
 	}
 	
+	//Type conversions supported by ResultSet getBigDecimal method - JDBC3.0 Table B-6 
+	private static final int[] bdConvertibleTypes = 
+	{	java.sql.Types.TINYINT,
+		java.sql.Types.SMALLINT,
+		java.sql.Types.INTEGER,
+		java.sql.Types.BIGINT,
+		java.sql.Types.REAL,
+		java.sql.Types.FLOAT,
+		java.sql.Types.DOUBLE,
+		java.sql.Types.DECIMAL,
+		java.sql.Types.NUMERIC,
+		java.sql.Types.BIT,
+		//java.sql.Types.BOOLEAN,	//Not supported in jdk13
+		java.sql.Types.CHAR,
+		java.sql.Types.VARCHAR,
+		java.sql.Types.LONGVARCHAR
+	};
+	
 	/** This method is a wrapper for the ResultSet method getBigDecimal(int columnIndex).
 	 * 
 	 * @param rs ResultSet 
@@ -66,7 +87,8 @@
 				break;
 			case STRING_REPRESENTATION:
 				bigDecimalString = rs.getString(columnIndex);
-				if((bigDecimalString != null) && !canConvertToDecimal(rs,columnIndex))
+				int columnType= rs.getMetaData().getColumnType(columnIndex);
+				if((bigDecimalString != null) && !canConvertToDecimal(columnType))
 					throw new SQLException("Invalid data conversion. Method not called.");
 				break;
 			default:	
@@ -95,7 +117,8 @@
 				break;
 			case STRING_REPRESENTATION:
 				bigDecimalString = rs.getString(columnName);
-				if((bigDecimalString != null) && !canConvertToDecimal(rs,columnIndex))
+				int columnType= rs.getMetaData().getColumnType(columnIndex);
+				if((bigDecimalString != null) && !canConvertToDecimal(columnType))
 					throw new SQLException("Invalid data conversion. Method not called.");
 				break;
 			default:	
@@ -168,6 +191,80 @@
 		return objectString;
 	}
 	
+	/** This method is a wrapper for the CallableStatement method getBigDecimal(int parameterIndex).
+	 * The wrapper method needs the parameterType as an input since ParameterMetaData is not
available in JSR169.
+	 * 
+	 * @param cs CallableStatement 
+	 * @param parameterIndex Parameter Index
+	 * @param parameterType Parameter Type
+	 * @return String value of getXXX(parameterIndex)method on the CallableStatement
+	 * @throws SQLException
+	 */
+	public static String getBigDecimalString(CallableStatement cs, int parameterIndex, int parameterType)
throws SQLException{
+		String bigDecimalString = null;
+		
+		switch(representation){
+			case BIGDECIMAL_REPRESENTATION:
+				//Call toString() only for non-null values, else return null
+				if(cs.getBigDecimal(parameterIndex) != null)
+					bigDecimalString = cs.getBigDecimal(parameterIndex).toString();
+				break;
+			case STRING_REPRESENTATION:
+				bigDecimalString = cs.getString(parameterIndex);
+				if((bigDecimalString != null) && !canConvertToDecimal(parameterType))
+					throw new SQLException("Invalid data conversion. Method not called.");
+				break;
+			default:	
+				new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
+		}
+		return bigDecimalString;
+	}	
+
+	/** This method is a wrapper for the PreparedStatement method setBigDecimal(int parameterIndex,BigDecimal
x)
+	 * 
+	 * @param ps PreparedStatement 
+	 * @param parameterIndex Parameter Index
+	 * @param bdString String to be used in setXXX method
+	 * @throws SQLException
+	 */
+	public static void setBigDecimalString(PreparedStatement ps, int parameterIndex, String
bdString) throws SQLException{
+		
+		switch(representation){
+			case BIGDECIMAL_REPRESENTATION:
+				ps.setBigDecimal(parameterIndex,new BigDecimal(bdString));
+				break;
+			case STRING_REPRESENTATION:
+				//setString is used since setBigDecimal is not available in JSR169
+				//If bdString cannot be converted to short,int or long, this will throw
+				//"Invalid character string format exception" 
+				ps.setString(parameterIndex,bdString);
+				break;
+			default:	
+				new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
+		}
+	}
+	
+	/** This method is a wrapper for the PreparedStatement method setObject(int parameterIndex,
Object x) 
+	 * 
+	 * @param ps PreparedStatement 
+	 * @param parameterIndex Parameter Index
+	 * @param bdString String to be used in setObject method
+	 * @throws SQLException
+	 */
+	public static void setObjectString(PreparedStatement ps, int parameterIndex, String objectString)
throws SQLException{
+		
+		switch(representation){
+			case BIGDECIMAL_REPRESENTATION:
+				ps.setObject(parameterIndex,new BigDecimal(objectString));
+				break;
+			case STRING_REPRESENTATION:
+				ps.setObject(parameterIndex,objectString);
+				break;
+			default:	
+				new Exception("Failed: Invalid Big Decimal representation").printStackTrace();
+		}
+	}	
+	
 	/** This method checks that the SQL type can be converted to Decimal
 	 * 
 	 * @param rs ResultSet
@@ -175,20 +272,17 @@
 	 * @return true if the SQL type is convertible to DECIMAL, false otherwise.
 	 * @throws SQLException
 	 */
-	protected static boolean canConvertToDecimal(ResultSet rs,int columnIndex) throws SQLException{
-		int columnType= rs.getMetaData().getColumnType(columnIndex);
-		if(columnType == java.sql.Types.BIGINT || 
-		   columnType == java.sql.Types.DECIMAL || 
-		   columnType == java.sql.Types.DOUBLE || 
-		   columnType == java.sql.Types.FLOAT || 
-		   columnType == java.sql.Types.INTEGER || 
-		   columnType == java.sql.Types.NUMERIC || 
-		   columnType == java.sql.Types.REAL || 
-		   columnType == java.sql.Types.SMALLINT || 
-		   columnType == java.sql.Types.TINYINT){
-			return true;
+	protected static boolean canConvertToDecimal(int type) throws SQLException{
+		boolean  canConvert = false;
+		
+		for (int bdType = 0; bdType < bdConvertibleTypes.length; bdType++){
+			if(type == bdConvertibleTypes[bdType]){
+				canConvert = true;
+				break;
+			}
 		}
-		return false;
+		
+		return canConvert;
 	}
 	
 }



Mime
View raw message