Portlet Factory, Version 6.1.2


 

About writing custom JDBC set/type-cast methods for stored procedure output parameters

If you specify a "Custom" JDBC type-cast for an output parameter of the SQL statement, include in your model a method that will perform the type-casting of the parameter for the builder.

Such a custom method must take the following parameters and return void:

BuilderName

A string parameter that contains the name of the SQL Statement builder that is calling the method to perform a custom type-cast. You can define one method for each custom type-cast you have defined, or you can bundle all of your type-casts together and use this input to identify which specific type-cast to apply when called by the builder.

statement

An object parameter that is the actual JDBC PreparedStatement or CallableStatement that was created by the builder and is being prepared for execution. The method is responsible for setting the output type of the positional parameter indicated by the position parameter.

position

This integer parameter identifies the positional parameter in the SQL statement for which the type-cast is to be performed.

operation

This new string parameter is used to specify whether the method is being called to "cast" an output parameter of an stored procedure call, or to "set" the output parameter's value.

The following Java code sample is the body of a custom type-cast method for an output parameter. In this example we do not need to differentiate between SQL Statement builders, so we ignore the BuilderName input. The statement parameter is cast into a JDBC CallableStatement. Then the type of the statement's positional parameter denoted by the position parameter of the method is set:

{ try CallableStatement stpCall = (CallableStatement) statement; if( stpCall != null ) if( "set".equals( operation ) ) stpCall.setInt( position, 100 ); else if( "cast".equals( operation ) ) stpCall.registerOutParameter( position, Types.NUMERIC ); catch( SQLException e ) throw new WebAppRuntimeException( e );
}

Parent topic: SQL Statement builder


Library | Support |