org.apache.derbyTesting.functionTests.tests.jdbcapi
Class CallableTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.functionTests.tests.jdbcapi.CallableTest
All Implemented Interfaces:
junit.framework.Test

public class CallableTest
extends BaseJDBCTestCase

Test the CallableStatement interface.

This test converts the old derbynet/callable.java test to JUnit. It exercises the CallableStatement interface with various combinations of IN, OUT and INOUT registered parameters, SQL functions and procedures, and different data types.


Field Summary
private static java.lang.String NOT_IMPLEMENTED
           
private static java.lang.String[] ROUTINES
          Routines that should be created before the tests are run and dropped when the tests have finished.
private static java.lang.String[][] TABLES
          Tables that should be created before the tests are run and dropped when the tests have finished.
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
CallableTest(java.lang.String name)
          Creates a new CallableTest instance.
 
Method Summary
 void assertDecimalSameValue(java.lang.String message, java.lang.String expected_s, java.math.BigDecimal actual)
          Wrapper for BigDecimal compareTo.
private static junit.framework.Test baseSuite(java.lang.String name)
           
static void batchUpdateProc(int id, int id_newval)
          External code for the BATCH_UPDATE_PROC SQL procedure, which updates data in a table for a given id.
static void bigDecimalInAndOutProc(java.math.BigDecimal bd1, java.math.BigDecimal[] bdr1, java.math.BigDecimal bd2, java.math.BigDecimal[] bdr2, java.math.BigDecimal[] bdr3, java.math.BigDecimal[] bdr4, java.math.BigDecimal[] bdr5, java.math.BigDecimal[] bdr6, java.math.BigDecimal[] bdr7)
          External code for the BIGDECIMAL_IN_AND_OUT_PROC SQL procedure, which tests INT and OUT parameters with the BigDecimal data type.
static void manyTypesInAndOutProc(java.sql.Date dt, java.sql.Time t, java.sql.Timestamp ts, byte[] ba, java.sql.Date[] dtr, java.sql.Time[] tr, java.sql.Timestamp[] tsr, byte[][] bar)
          External code for the NON_NUMERIC_TYPES_IN_AND_OUT_PROC SQL procedure, which tests IN / OUT parameters with many non-numeric types.
static void manyTypesInAndOutProc(short s, int i, long l, float f, double d, java.math.BigDecimal bd, short[] sr, int[] ir, long[] lr, float[] fr, double[] dr, java.math.BigDecimal[] bdr)
          External code for the NUMERIC_TYPES_IN_AND_OUT_PROC SQL procedure, which tests IN and OUT parameters with many numeric types.
static void manyTypesInoutProc(short s1, short[] s2, int p1, int[] p2, long l1, long[] l2, float f1, float[] f2, double d1, double[] d2, java.sql.Time t1, java.sql.Time[] t2)
          External code for the MANY_TYPES_INOUT_PROC SQL procedure, which tests INOUT parameters with many types.
static int noInOneOutFunc()
          External code for the NO_IN_ONE_OUT_FUNC SQL function, which takes no parameters and returns the value 55.
 void norun_testSystemOutPrintlnProc()
          Calls a SQL procedure that outputs a message with System.out.println.
static void numericBoundariesProc(java.math.BigDecimal[] param1, java.math.BigDecimal[] param2, java.math.BigDecimal[] param3)
          External code for the NUMERIC_BOUNDARIES_PROC SQL procedure, which fetches max, min, and null values from a table with numeric columns.
static int oneInOneOutFunc(int p1)
          External code for the ONE_IN_ONE_OUT_FUNC SQL function, which squares the value of the input arg, then adds the input arg to that result.
 void setUp()
          Sets up the connection for a test case and clears all tables used in the test cases.
static junit.framework.Test suite()
           
static void systemOutPrintlnProc()
          External code for the SYSTEM_OUT_PRINTLN_PROC SQL procedure, which outputs a message to System out.
 void testIsolationLevelChangeAfterFunctionCall()
           
 void testManyTypesInoutProc()
          Calls a SQL procedure that takes INOUT parameters of various types.
 void testNoInOneOutFunc()
          Calls a SQL function that takes no input parameter and returns one output.
 void testNonNumericTypesInAndOutProc()
          Calls a SQL procedure that takes non-numeric IN and OUT parameters.
 void testOneInOneOutFunc()
          Calls a SQL function with one input parameter and one output.
 void testTwoInOneOutProc()
          Calls a SQL procedure with two input parameters and one output.
static void twoInOneOutProc(int p1, int p2, int[] p3)
          External code for the TWO_IN_ONE_OUT_PROC SQL procedure, which sets the value of the third arg to the sum of the first two.
static void updateLongVarbinaryProc(byte[] in_param)
          External code for the UPDATE_LONGVARBINARY_PROC SQL procedure, which sets the value of the Long varbinary column in the LONGVARBINARY_TABLE table given the input parameter.
 void xtestBatchUpdate()
          Batches up calls to a SQL procedure that updates a value in a table.
 void xtestBatchUpdateError()
          Batches up many calls to a SQL procedure that updates a value in a table.
 void xtestBigDecimalInAndOutProc()
          Calls a SQL procedure with BigDecimal IN and OUT parameters.
 void xtestNumericBoundariesProc()
          Calls a SQL procedure that populates OUT parameters with minimum, maximum, and null values fetched from a table with numeric columns.
 void xtestNumericTypesInAndOutProc()
          Calls a SQL procedure that takes numeric IN and OUT parameters.
 void xtestRegUserDefOutParameterError()
          Tries to register a user-defined OUT parameter, which isn't supported and is expected to throw a "not implemented" exception.
 void xtestUpdateLongBinaryProc()
          Calls a SQL procedure that updates a long varbinary column.
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NOT_IMPLEMENTED

private static final java.lang.String NOT_IMPLEMENTED
See Also:
Constant Field Values

ROUTINES

private static final java.lang.String[] ROUTINES
Routines that should be created before the tests are run and dropped when the tests have finished.


TABLES

private static final java.lang.String[][] TABLES
Tables that should be created before the tests are run and dropped when the tests have finished. The first element in each row is the name of the table and the second element is the SQL text that creates it.

Constructor Detail

CallableTest

public CallableTest(java.lang.String name)
Creates a new CallableTest instance.

Parameters:
name - name of the test
Method Detail

suite

public static junit.framework.Test suite()

baseSuite

private static junit.framework.Test baseSuite(java.lang.String name)

setUp

public void setUp()
           throws java.sql.SQLException
Sets up the connection for a test case and clears all tables used in the test cases.

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.sql.SQLException

testTwoInOneOutProc

public void testTwoInOneOutProc()
                         throws java.sql.SQLException
Calls a SQL procedure with two input parameters and one output.

Throws:
java.sql.SQLException

testOneInOneOutFunc

public void testOneInOneOutFunc()
                         throws java.sql.SQLException
Calls a SQL function with one input parameter and one output.

Throws:
java.sql.SQLException

testNoInOneOutFunc

public void testNoInOneOutFunc()
                        throws java.sql.SQLException
Calls a SQL function that takes no input parameter and returns one output.

Throws:
java.sql.SQLException

testIsolationLevelChangeAfterFunctionCall

public void testIsolationLevelChangeAfterFunctionCall()
                                               throws java.sql.SQLException
Throws:
java.sql.SQLException

norun_testSystemOutPrintlnProc

public void norun_testSystemOutPrintlnProc()
                                    throws java.sql.SQLException
Calls a SQL procedure that outputs a message with System.out.println. Converted from the original test, but initially disabled because of the message output to system out. Easily enabled by changing method name to remove the initial "norun_" (the name becomes testSystemOutPrintlnProc).

Throws:
java.sql.SQLException

xtestNumericTypesInAndOutProc

public void xtestNumericTypesInAndOutProc()
                                   throws java.sql.SQLException
Calls a SQL procedure that takes numeric IN and OUT parameters. Excluded from JSR169/j2ME, which doesn't support get/set BigDecimal yet.

Throws:
java.sql.SQLException

testNonNumericTypesInAndOutProc

public void testNonNumericTypesInAndOutProc()
                                     throws java.sql.SQLException
Calls a SQL procedure that takes non-numeric IN and OUT parameters.

Throws:
java.sql.SQLException

testManyTypesInoutProc

public void testManyTypesInoutProc()
                            throws java.sql.SQLException
Calls a SQL procedure that takes INOUT parameters of various types.

Throws:
java.sql.SQLException

xtestRegUserDefOutParameterError

public void xtestRegUserDefOutParameterError()
                                      throws java.sql.SQLException
Tries to register a user-defined OUT parameter, which isn't supported and is expected to throw a "not implemented" exception. DERBY-1184 fixed the behavior in the Derby Network Client to throw an exception; however, DB2 Client behavior is incorrect, so the suite excludes this test when run with DB2 Client.

Throws:
java.sql.SQLException

xtestUpdateLongBinaryProc

public void xtestUpdateLongBinaryProc()
                               throws java.sql.SQLException
Calls a SQL procedure that updates a long varbinary column. Uses DriverManager, so this test requires JDBC 2 DriverManager support.

Throws:
java.sql.SQLException

xtestBatchUpdate

public void xtestBatchUpdate()
                      throws java.sql.SQLException
Batches up calls to a SQL procedure that updates a value in a table. Uses DriverManager and Batch calls, so requires JDBC 2 support.

Throws:
java.sql.SQLException

xtestBatchUpdateError

public void xtestBatchUpdateError()
                           throws java.sql.SQLException
Batches up many calls to a SQL procedure that updates a value in a table. All calls should succeed, except for one that should fail with a check constraint violation. Uses DriverManager and Batch calls, so requires JDBC 2 support.

Throws:
java.sql.SQLException

xtestNumericBoundariesProc

public void xtestNumericBoundariesProc()
                                throws java.sql.SQLException
Calls a SQL procedure that populates OUT parameters with minimum, maximum, and null values fetched from a table with numeric columns. Pre-history: long, long ago this test was added to exercise a problem with converting BigDecimal to packed decimal, which left the Network Server cpu bound. Excluded from environments than don't have JDBC 2 DriverManager. Excluded from JSR169/j2ME, which doesn't support get/set BigDecimal yet.

Throws:
java.sql.SQLException

xtestBigDecimalInAndOutProc

public void xtestBigDecimalInAndOutProc()
                                 throws java.sql.SQLException
Calls a SQL procedure with BigDecimal IN and OUT parameters. Excluded from JSR169/j2ME, which doesn't support get/set BigDecimal yet.

Throws:
java.sql.SQLException

assertDecimalSameValue

public void assertDecimalSameValue(java.lang.String message,
                                   java.lang.String expected_s,
                                   java.math.BigDecimal actual)
Wrapper for BigDecimal compareTo. Called by the xtestBigDecimalInAndOutProc, xtestNumericTypesInAndOutProc, and xtestNumericBoundariesProc, methods.


oneInOneOutFunc

public static int oneInOneOutFunc(int p1)
External code for the ONE_IN_ONE_OUT_FUNC SQL function, which squares the value of the input arg, then adds the input arg to that result.

Parameters:
p1 - integer input argument to be used in calculation

twoInOneOutProc

public static void twoInOneOutProc(int p1,
                                   int p2,
                                   int[] p3)
External code for the TWO_IN_ONE_OUT_PROC SQL procedure, which sets the value of the third arg to the sum of the first two.

Parameters:
p1 - integer input parameter to be used in calculation
p2 - integer input parameter to be used in calculation
p3 - integer output parameter that stores result of the calculation

noInOneOutFunc

public static int noInOneOutFunc()
External code for the NO_IN_ONE_OUT_FUNC SQL function, which takes no parameters and returns the value 55.


systemOutPrintlnProc

public static void systemOutPrintlnProc()
External code for the SYSTEM_OUT_PRINTLN_PROC SQL procedure, which outputs a message to System out.


updateLongVarbinaryProc

public static void updateLongVarbinaryProc(byte[] in_param)
                                    throws java.sql.SQLException
External code for the UPDATE_LONGVARBINARY_PROC SQL procedure, which sets the value of the Long varbinary column in the LONGVARBINARY_TABLE table given the input parameter.

Parameters:
in_param - input parameter to be used for database update
Throws:
java.sql.SQLException - if a database error occurs

numericBoundariesProc

public static void numericBoundariesProc(java.math.BigDecimal[] param1,
                                         java.math.BigDecimal[] param2,
                                         java.math.BigDecimal[] param3)
                                  throws java.sql.SQLException
External code for the NUMERIC_BOUNDARIES_PROC SQL procedure, which fetches max, min, and null values from a table with numeric columns.

Parameters:
param1 - output parameter that returns maxcol value
param2 - output parameter that returns mincol value
param3 - output parameter that returns nulcol value
Throws:
java.sql.SQLException - if a database error occurs

bigDecimalInAndOutProc

public static void bigDecimalInAndOutProc(java.math.BigDecimal bd1,
                                          java.math.BigDecimal[] bdr1,
                                          java.math.BigDecimal bd2,
                                          java.math.BigDecimal[] bdr2,
                                          java.math.BigDecimal[] bdr3,
                                          java.math.BigDecimal[] bdr4,
                                          java.math.BigDecimal[] bdr5,
                                          java.math.BigDecimal[] bdr6,
                                          java.math.BigDecimal[] bdr7)
External code for the BIGDECIMAL_IN_AND_OUT_PROC SQL procedure, which tests INT and OUT parameters with the BigDecimal data type.

Parameters:
bd1 - input parameter
bdr1 - output parameter set to bd1 * bd2
bd2 - input parameter
bdr2 - output parameter set to bd1 + bd2
bdr3 - output parameter set to a fixed value
bdr4 - output parameter set to a fixed value
bdr5 - output parameter set to a fixed value
bdr6 - output parameter set to a fixed value
bdr7 - output parameter set to a fixed value

manyTypesInAndOutProc

public static void manyTypesInAndOutProc(short s,
                                         int i,
                                         long l,
                                         float f,
                                         double d,
                                         java.math.BigDecimal bd,
                                         short[] sr,
                                         int[] ir,
                                         long[] lr,
                                         float[] fr,
                                         double[] dr,
                                         java.math.BigDecimal[] bdr)
External code for the NUMERIC_TYPES_IN_AND_OUT_PROC SQL procedure, which tests IN and OUT parameters with many numeric types. Also tests method overload for manyTypesInAndOutProc.

Parameters:
s - short input parameter
i - int input parameter
l - long input parameter
f - float input parameter
d - double input parameter
bd - BigDecimal input parameter
sr - short output parameter
ir - int output parameter
lr - long output parameter
fr - float output parameter
dr - double output parameter
bdr - BigDecimal output parameter

manyTypesInAndOutProc

public static void manyTypesInAndOutProc(java.sql.Date dt,
                                         java.sql.Time t,
                                         java.sql.Timestamp ts,
                                         byte[] ba,
                                         java.sql.Date[] dtr,
                                         java.sql.Time[] tr,
                                         java.sql.Timestamp[] tsr,
                                         byte[][] bar)
External code for the NON_NUMERIC_TYPES_IN_AND_OUT_PROC SQL procedure, which tests IN / OUT parameters with many non-numeric types. Also tests method overload for manyTypesInAndOutProc.

Parameters:
dt - date input parameter
t - time input parameter
ts - timestamp input parameter
ba - byte input parameter
dtr - date output parameter
tr - time output parameter
tsr - timestamp output parameter
bar - byte output parameter

manyTypesInoutProc

public static void manyTypesInoutProc(short s1,
                                      short[] s2,
                                      int p1,
                                      int[] p2,
                                      long l1,
                                      long[] l2,
                                      float f1,
                                      float[] f2,
                                      double d1,
                                      double[] d2,
                                      java.sql.Time t1,
                                      java.sql.Time[] t2)
External code for the MANY_TYPES_INOUT_PROC SQL procedure, which tests INOUT parameters with many types.

Parameters:
s1 - short input parameter
s2 - short output parameter
p1 - int input parameter
p2 - int output parameter
l1 - long input parameter
l2 - long output parameter
f1 - float input parameter
f2 - float output parameter
d1 - double input parameter
d2 - double output parameter
t1 - time input parameter
t2 - time output parameter

batchUpdateProc

public static void batchUpdateProc(int id,
                                   int id_newval)
                            throws java.sql.SQLException
External code for the BATCH_UPDATE_PROC SQL procedure, which updates data in a table for a given id. Called by xtestBatchUpdateProc.

Parameters:
id - Id to be updated
id_newval - New value to which the id should be updated
Throws:
java.sql.SQLException - if a database error occurs

Built on Wed 2009-11-25 18:43:31-0800, from revision 884373

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.