com.interface21.jdbc.object
Class StoredProcedure

java.lang.Object
  |
  +--com.interface21.jdbc.object.RdbmsOperation
        |
        +--com.interface21.jdbc.object.StoredProcedure
All Implemented Interfaces:
InitializingBean

public abstract class StoredProcedure
extends RdbmsOperation

Superclass for object abstractions of RDBMS stored procedures. This class is abstract and its execute methods are protected, preventing use other than through a subclass that offers tighter typing.
The inherited sql property is the name of the stored procedure in the RDBMS. Note that JDBC 3.0 introduces named parameters, although the other features provided by this class are still necessary in JDBC 3.0.

Version:
$Id: StoredProcedure.java,v 1.6 2003/05/27 18:04:26 jhoeller Exp $
Author:
Rod Johnson

Inner Class Summary
static class StoredProcedure.OutputParameter
          Subclass of SqlParameter to represent an output parameter.
protected static interface StoredProcedure.ParameterMapper
          Implement this interface when parameters need to be customized based on the connection.
 
Fields inherited from class com.interface21.jdbc.object.RdbmsOperation
logger
 
Constructor Summary
protected StoredProcedure()
          Allow use as a bean
protected StoredProcedure(javax.sql.DataSource ds, java.lang.String name)
          Create a new object wrapper for a stored procedure.
 
Method Summary
protected  void compileInternal()
          Override of NOP RdbmsOperation.compileInternal() to ensure that the call string is up to date before invoking the RDBMS stored procedure.
 void declareParameter(SqlParameter p)
          Overridden method.
protected  java.util.Map execute(java.util.Map inParams)
          Execute the stored procedure.
protected  java.util.Map execute(StoredProcedure.ParameterMapper mapper)
          Execute the stored procedure.
protected  SQLExceptionTranslater getExceptionTranslater()
          Return the exception translater for this instance.
 boolean isFunction()
           
 void setExceptionTranslater(SQLExceptionTranslater exceptionTranslater)
          Set the exception translater used in this class.
 void setFunction(boolean isFunction)
          Sets the isFunction.
 
Methods inherited from class com.interface21.jdbc.object.RdbmsOperation
afterPropertiesSet, compile, getDataSource, getDeclaredParameters, getSql, isCompiled, setDataSource, setSql, setTypes, validateParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StoredProcedure

protected StoredProcedure()
Allow use as a bean

StoredProcedure

protected StoredProcedure(javax.sql.DataSource ds,
                          java.lang.String name)
Create a new object wrapper for a stored procedure.
Parameters:
ds - DataSource to use throughout the lifetime of this object to obtain connections
name - name of the stored procedure in the database.
Method Detail

setExceptionTranslater

public void setExceptionTranslater(SQLExceptionTranslater exceptionTranslater)
Set the exception translater used in this class. As in the JdbcTemplate class, this can be parameterized
See Also:
SQLExceptionTranslater

getExceptionTranslater

protected SQLExceptionTranslater getExceptionTranslater()
Return the exception translater for this instance. Create a default one for the specified DataSource if none set.

declareParameter

public void declareParameter(SqlParameter p)
                      throws InvalidDataAccessApiUsageException
Overridden method. Add a parameter. NB: Calls to addParameter must be made in the same order as they appear in the database's stored procedure parameter list. Names are purely used to help mapping
Overrides:
declareParameter in class RdbmsOperation
Parameters:
p - Parameter object (as defined in the Parameter inner class)

compileInternal

protected void compileInternal()
Override of NOP RdbmsOperation.compileInternal() to ensure that the call string is up to date before invoking the RDBMS stored procedure.
Overrides:
compileInternal in class RdbmsOperation
Following copied from class: com.interface21.jdbc.object.RdbmsOperation
Throws:
InvalidDataAccessApiUsageException - if the subclass hasn't been properly configured.

execute

protected java.util.Map execute(java.util.Map inParams)
Execute the stored procedure. Subclasses should define a strongly typed execute method (with a meaningful name) that invokes this method, populating the input map and extracting typed values from the output map. Subclass execute methods will often take domain objects as arguments and return values. Alternatively, they can return void.
Parameters:
inParams - map of input parameters, keyed by name as in parameter declarations. Output parameters need not (but can be) included in this map. It is legal for map entries to be null, and this will produce the correct behavior using a NULL argument to the stored procedure.
Returns:
map of output params, keyed by name as in parameter declarations. Output parameters will appear here, with their values after the stored procedure has been called.

execute

protected java.util.Map execute(StoredProcedure.ParameterMapper mapper)
                         throws InvalidDataAccessApiUsageException
Execute the stored procedure. All parameters must have been added before any calls are made to this method.
This method is provided as a more powerful alternative to the execute(Map) method for special cases where we need the Connection to populate the input map. We might need to do this to use proprietary features of the target database: for example, to use RDBMS-specific types.
Maps, using parameter names given in addParameter(), are used to hold input and output parameters.
Parameters:
mapper - Map of input parameters
Returns:
map of output parameters. In/out parameters will appear here, with their value after the stored procedure has been called.

isFunction

public boolean isFunction()
Returns:
boolean

setFunction

public void setFunction(boolean isFunction)
Sets the isFunction.
Parameters:
isFunction - The isFunction to set


Rod Johnson and Spring contributors 2001-2003.