The CallHandlerWithParameters<CAL> interface

You can customize how pureQuery handles the results from an SQL stored procedure CALL by using an implementation of the com.ibm.pdq.runtime.handlers.CallHandlerWithParameters<CAL> interface. pureQuery can use that implementation to create the object to be returned from the annotated or inline method that ran the CALL statement. Moreover, the implementation can carry out any additional processing that you might require, such as updating OUT and INOUT parameters.

The default pureQuery behavior with SQL stored procedure calls is to return the results in an instance of StoredProcedureResult. Additionally, by default pureQuery updates maps and beans that were passed to an annotated or inline method to represent OUT and INOUT parameters.

The CallHandlerWithParameters<T> interface has only one method:
T handleCall (CallableStatement cstmt, Object... parameters) throws SQLException

pureQuery calls the handleCall() method to create the object that is returned from an annotated or inline method. When pureQuery calls this method, it passes an object that implements the java.sql.CallableStatement interface, which it used to run the SQL CALL statement. pureQuery also passes parameters that you used to pass the values of the parameters in the CALL statement.

If you are creating an implementation of CallHandlerWithParameters<CAL>, implement this method to create and return an object of type <CAL> that represents the results of the stored procedure CALL. Some activities you might want to perform inside the handleCall() method are:
  • Use cstmt to access any ResultSet objects that are returned by the stored procedure, and possibly store part or all of the results in the object of type <CAL> that is returned by the method. See the Javadoc™ for your Java™ SDK for information about the java.sql.CallableStatement interface.
  • Use cstmt to access values returned by the OUT and INOUT parameters of the stored procedure and incorporate them into the resulting <CAL> object.
  • • Use cstmt to access values returned by the OUT and INOUT parameters of the stored procedure, and update the parameters that were passed into the annotated or inline method with the new values.

Using a CallHandlerWithParameters<CAL> object with annotated methods

There are two methods that you can use to call CallHandlerWithParameter objects from annotated methods.

Using a CallHandlerWithParameters<CAL> object with inline methods

You pass CallHandlerWithParameters<CAL> objects to this version of the overloaded call() method in the Data interface:

<CAL> T call(String sql, CallHandlerWithParameters<CAL> callHandlerWithParameters, Object... parameters)

Here is an example:

MyResultsBean spResults = db.call("{?1 = Call ADDEM (?1.added1, ?1.addend2, ?1.sum)}",
		new custom.GetAddEmResult_CallHandlerWithParameters(), int outVal, int inVal1, int inVal2, int inVal3)

Feedback