public abstract class RdbmsOperation extends Object implements InitializingBean
This class and subclasses throw runtime exceptions, defined in the
Subclasses should set SQL and add parameters before invoking the
org.springframework.jdbc.core
package, which the classes
in this package use under the hood to perform raw JDBC operations).
compile()
method. The order in which parameters are added is
significant. The appropriate execute
or update
method can then be invoked.
SqlQuery
,
SqlUpdate
,
StoredProcedure
,
JdbcTemplate
Modifier and Type | Field and Description |
---|---|
protected Log |
logger
Logger available to subclasses
|
Constructor and Description |
---|
RdbmsOperation() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Ensures compilation if used in a bean factory.
|
protected boolean |
allowsUnusedParameters()
Return whether this operation accepts additional parameters that are
given but not actually used.
|
protected void |
checkCompiled()
Check whether this operation has been compiled already;
lazily compile it if not already compiled.
|
void |
compile()
Compile this query.
|
protected abstract void |
compileInternal()
Subclasses must implement this template method to perform their own compilation.
|
void |
declareParameter(SqlParameter param)
Declare a parameter for this operation.
|
protected List<SqlParameter> |
getDeclaredParameters()
Return a list of the declared
SqlParameter objects. |
String[] |
getGeneratedKeysColumnNames()
Return the column names of the auto generated keys.
|
JdbcTemplate |
getJdbcTemplate()
Return the JdbcTemplate object used by this object.
|
int |
getResultSetType()
Return whether statements will return a specific type of ResultSet.
|
String |
getSql()
Subclasses can override this to supply dynamic SQL if they wish,
but SQL is normally set by calling the setSql() method
or in a subclass constructor.
|
boolean |
isCompiled()
Is this operation "compiled"? Compilation, as in JDO,
means that the operation is fully configured, and ready to use.
|
boolean |
isReturnGeneratedKeys()
Return whether statements should be capable of returning
auto-generated keys.
|
boolean |
isUpdatableResults()
Return whether statements will return updatable ResultSets.
|
void |
setDataSource(DataSource dataSource)
Set the JDBC DataSource to obtain connections from.
|
void |
setFetchSize(int fetchSize)
Set the fetch size for this RDBMS operation.
|
void |
setGeneratedKeysColumnNames(String[] names)
Set the column names of the auto-generated keys.
|
void |
setJdbcTemplate(JdbcTemplate jdbcTemplate)
An alternative to the more commonly used setDataSource() when you want to
use the same JdbcTemplate in multiple RdbmsOperations.
|
void |
setMaxRows(int maxRows)
Set the maximum number of rows for this RDBMS operation.
|
void |
setParameters(SqlParameter[] parameters)
Add one or more declared parameters.
|
void |
setQueryTimeout(int queryTimeout)
Set the query timeout for statements that this RDBMS operation executes.
|
void |
setResultSetType(int resultSetType)
Set whether to use statements that return a specific type of ResultSet.
|
void |
setReturnGeneratedKeys(boolean returnGeneratedKeys)
Set whether prepared statements should be capable of returning
auto-generated keys.
|
void |
setSql(String sql)
Set the SQL executed by this operation.
|
void |
setTypes(int[] types)
Add anonymous parameters, specifying only their SQL types
as defined in the
java.sql.Types class. |
void |
setUpdatableResults(boolean updatableResults)
Set whether to use statements that are capable of returning
updatable ResultSets.
|
protected boolean |
supportsLobParameters()
Return whether BLOB/CLOB parameters are supported for this kind of operation.
|
protected void |
validateNamedParameters(Map<String,?> parameters)
Validate the named parameters passed to an execute method based on declared parameters.
|
protected void |
validateParameters(Object[] parameters)
Validate the parameters passed to an execute method based on declared parameters.
|
protected final Log logger
public void setJdbcTemplate(JdbcTemplate jdbcTemplate)
public JdbcTemplate getJdbcTemplate()
public void setDataSource(DataSource dataSource)
public void setFetchSize(int fetchSize)
Default is 0, indicating to use the driver's default.
JdbcTemplate.setFetchSize(int)
public void setMaxRows(int maxRows)
Default is 0, indicating to use the driver's default.
JdbcTemplate.setMaxRows(int)
public void setQueryTimeout(int queryTimeout)
Default is 0, indicating to use the JDBC driver's default.
Note: Any timeout specified here will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.
public void setResultSetType(int resultSetType)
resultSetType
- the ResultSet typeResultSet.TYPE_FORWARD_ONLY
,
ResultSet.TYPE_SCROLL_INSENSITIVE
,
ResultSet.TYPE_SCROLL_SENSITIVE
,
Connection.prepareStatement(String, int, int)
public int getResultSetType()
public void setUpdatableResults(boolean updatableResults)
public boolean isUpdatableResults()
public void setReturnGeneratedKeys(boolean returnGeneratedKeys)
public boolean isReturnGeneratedKeys()
public void setGeneratedKeysColumnNames(String[] names)
public String[] getGeneratedKeysColumnNames()
public void setSql(String sql)
public String getSql()
public void setTypes(int[] types) throws InvalidDataAccessApiUsageException
java.sql.Types
class.
Parameter ordering is significant. This method is an alternative
to the declareParameter(org.springframework.jdbc.core.SqlParameter)
method, which should normally be preferred.
types
- array of SQL types as defined in the
java.sql.Types
classInvalidDataAccessApiUsageException
- if the operation is already compiledpublic void declareParameter(SqlParameter param) throws InvalidDataAccessApiUsageException
The order in which this method is called is significant when using positional parameters. It is not significant when using named parameters with named SqlParameter objects here; it remains significant when using named parameters in combination with unnamed SqlParameter objects here.
param
- the SqlParameter to add. This will specify SQL type and (optionally)
the parameter's name. Note that you typically use the SqlParameter
class
itself here, not any of its subclasses.InvalidDataAccessApiUsageException
- if the operation is already compiled,
and hence cannot be configured furtherpublic void setParameters(SqlParameter[] parameters)
parameters
- Array containing the declared SqlParameter
objectsdeclaredParameters
protected List<SqlParameter> getDeclaredParameters()
SqlParameter
objects.public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
public final void compile() throws InvalidDataAccessApiUsageException
InvalidDataAccessApiUsageException
- if the object hasn't
been correctly initialized, for example if no DataSource has been providedpublic boolean isCompiled()
protected void checkCompiled()
Automatically called by validateParameters
.
protected void validateParameters(Object[] parameters) throws InvalidDataAccessApiUsageException
executeQuery()
or update()
method.parameters
- parameters supplied (may be null
)InvalidDataAccessApiUsageException
- if the parameters are invalidprotected void validateNamedParameters(Map<String,?> parameters) throws InvalidDataAccessApiUsageException
executeQuery()
or
update()
method.parameters
- parameter Map supplied. May be null
.InvalidDataAccessApiUsageException
- if the parameters are invalidprotected abstract void compileInternal() throws InvalidDataAccessApiUsageException
Subclasses can assume that SQL and a DataSource have been supplied.
InvalidDataAccessApiUsageException
- if the subclass hasn't been
properly configuredprotected boolean supportsLobParameters()
The default is true
.
protected boolean allowsUnusedParameters()
The default is false
.
StoredProcedure