public class StoredProcExecutor extends Object implements BeanFactoryAware, InitializingBean
Constructor and Description |
---|
StoredProcExecutor(DataSource dataSource)
Constructor taking
DataSource from which the DB Connection can be
obtained. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Verifies parameters, sets the parameters on
SimpleJdbcCallOperations
and ensures the appropriate SqlParameterSourceFactory is defined
when ProcedureParameter are passed in. |
Map<String,Object> |
executeStoredProcedure()
Execute a Stored Procedure or Function - Use when no
Message is
available to extract ProcedureParameter values from it. |
Map<String,Object> |
executeStoredProcedure(Message<?> message)
Execute a Stored Procedure or Function - Use with
Message is
available to extract ProcedureParameter values from it. |
String |
getStoredProcedureName() |
String |
getStoredProcedureNameExpressionAsString() |
void |
setBeanFactory(BeanFactory beanFactory)
Allows to set the optional
BeanFactory which is used to add a
BeanResolver to the
StandardEvaluationContext . |
void |
setIgnoreColumnMetaData(boolean ignoreColumnMetaData)
For fully supported databases, the underlying
SimpleJdbcCall can
retrieve the parameter information for the to be invoked Stored Procedure
from the JDBC Meta-data. |
void |
setIsFunction(boolean isFunction)
Indicates whether a Stored Procedure or a Function is being executed.
|
void |
setJdbcCallOperationsCacheSize(int jdbcCallOperationsCacheSize)
Defines the maximum number of
SimpleJdbcCallOperations
A value of zero will disable the cache. |
void |
setProcedureParameters(List<ProcedureParameter> procedureParameters)
Custom Stored Procedure parameters that may contain static values
or Strings representing an
Expression . |
void |
setReturningResultSetRowMappers(Map<String,RowMapper<?>> returningResultSetRowMappers)
|
void |
setReturnValueRequired(boolean returnValueRequired)
Indicates the procedure's return value should be included in the results
returned.
|
void |
setSkipUndeclaredResults(boolean skipUndeclaredResults)
If this variable is set to
true then all results from a stored
procedure call that don't have a corresponding
SqlOutParameter
declaration will be bypassed. |
void |
setSqlParameters(List<SqlParameter> sqlParameters)
If you database system is not fully supported by Spring and thus obtaining
parameter definitions from the JDBC Meta-data is not possible, you must define
the
SqlParameter explicitly. |
void |
setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)
Provides the ability to set a custom
SqlParameterSourceFactory . |
void |
setStoredProcedureName(String storedProcedureName)
The name of the Stored Procedure or Stored Function to be executed.
|
void |
setStoredProcedureNameExpression(Expression storedProcedureNameExpression)
Using the
storedProcedureNameExpression the
Message can be used as source for the name of the
Stored Procedure or Stored Function. |
void |
setUsePayloadAsParameterSource(boolean usePayloadAsParameterSource)
If set to 'true', the payload of the Message will be used as a source for
providing parameters.
|
public StoredProcExecutor(DataSource dataSource)
DataSource
from which the DB Connection can be
obtained.dataSource
- used to create a SimpleJdbcCall
instance, must not be Nullpublic void afterPropertiesSet()
SimpleJdbcCallOperations
and ensures the appropriate SqlParameterSourceFactory
is defined
when ProcedureParameter
are passed in.afterPropertiesSet
in interface InitializingBean
public Map<String,Object> executeStoredProcedure()
Message
is
available to extract ProcedureParameter
values from it.public Map<String,Object> executeStoredProcedure(Message<?> message)
Message
is
available to extract ProcedureParameter
values from it.message
- A message.public void setIgnoreColumnMetaData(boolean ignoreColumnMetaData)
SimpleJdbcCall
can
retrieve the parameter information for the to be invoked Stored Procedure
from the JDBC Meta-data. However, if the used database does not support
meta data lookups or if you like to provide customized parameter definitions,
this flag can be set to 'true'. It defaults to 'false'.ignoreColumnMetaData
- true to ignore column metadata.public void setProcedureParameters(List<ProcedureParameter> procedureParameters)
Expression
.procedureParameters
- The parameters.public void setSqlParameters(List<SqlParameter> sqlParameters)
SqlParameter
explicitly.sqlParameters
- The parameters.public void setSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory)
SqlParameterSourceFactory
.
Keep in mind that if ProcedureParameter
are set explicitly and
you would like to provide a custom SqlParameterSourceFactory
,
then you must provide an instance of ExpressionEvaluatingSqlParameterSourceFactory
.
If not the SqlParameterSourceFactory will be replaced the default
ExpressionEvaluatingSqlParameterSourceFactory
.sqlParameterSourceFactory
- the parameter source factory.public String getStoredProcedureName()
public String getStoredProcedureNameExpressionAsString()
public void setStoredProcedureName(String storedProcedureName)
isFunction
is set to "true", then this
property specifies the Stored Function name.
Alternatively you can also specify the Stored Procedure name via
setStoredProcedureNameExpression(Expression)
.
E.g., that way you can specify the name of the Stored Procedure or Stored Function
through MessageHeaders
.storedProcedureName
- Must not be null and must not be emptysetStoredProcedureNameExpression(Expression)
public void setStoredProcedureNameExpression(Expression storedProcedureNameExpression)
storedProcedureNameExpression
the
Message
can be used as source for the name of the
Stored Procedure or Stored Function.
If isFunction
is set to "true", then this
property specifies the Stored Function name.
By providing a SpEL expression as value for this setter, a subset of the
original payload, a header value or any other resolvable SpEL expression
can be used as the basis for the Stored Procedure / Function.
For the Expression evaluation the full message is available as the root object.
For instance the following SpEL expressions (among others) are possible:
setStoredProcedureName(String)
storedProcedureNameExpression
- Must not be null.public void setUsePayloadAsParameterSource(boolean usePayloadAsParameterSource)
Message
will be available
as a source for parameters.
If no ProcedureParameter
are passed in, this property will default to
true
. This means that using a default BeanPropertySqlParameterSourceFactory
the bean properties of the payload will be used as a source for parameter
values for the to-be-executed Stored Procedure or Function.
However, if ProcedureParameter
s are passed in, then this property
will by default evaluate to false
. ProcedureParameter
allow for SpEl Expressions to be provided and therefore it is highly
beneficial to have access to the entire Message
.usePayloadAsParameterSource
- If false the entire Message
is used as parameter source.public void setIsFunction(boolean isFunction)
isFunction
- If set to true an Sql Function is executed rather than a Stored Procedure.public void setReturnValueRequired(boolean returnValueRequired)
returnValueRequired
- true to include the return value.public void setSkipUndeclaredResults(boolean skipUndeclaredResults)
true
then all results from a stored
procedure call that don't have a corresponding
SqlOutParameter
declaration will be bypassed.
E.g. Stored Procedures may return an update count value, even though your
Stored Procedure only declared a single result parameter. The exact behavior
depends on the used database.
The value is set on the underlying JdbcTemplate
.
Only few developers will probably ever like to process update counts, thus
the value defaults to true
.skipUndeclaredResults
- The boolean.public void setReturningResultSetRowMappers(Map<String,RowMapper<?>> returningResultSetRowMappers)
RowMapper
to convert the ResultSet
to meaningful objects.returningResultSetRowMappers
- The map may not be null and must not contain null values.public void setJdbcCallOperationsCacheSize(int jdbcCallOperationsCacheSize)
SimpleJdbcCallOperations
A value of zero will disable the cache. The default is 10.jdbcCallOperationsCacheSize
- Must not be negative.public void setBeanFactory(BeanFactory beanFactory)
BeanFactory
which is used to add a
BeanResolver
to the
StandardEvaluationContext
.
If not set this property defaults to null.setBeanFactory
in interface BeanFactoryAware
beanFactory
- If set must not be null.