|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.object.RdbmsOperation
An "RDBMS operation" is a multithreaded, reusable object representing a query, update or stored procedure. An RDBMS operation is not a command, as a command isn't reusable. However, execute methods may take commands as arguments. Subclasses should be Java beans, allowing easy configuration.
Root of the JDBC object hierarchy, as described in Chapter 9 of Expert One-On-One J2EE Design and Development by Rod Johnson (Wrox, 2002).
This class and subclasses throw runtime exceptions, defined in the org.springframework.dao package (and as thrown by the org.springframework.jdbc.core package, which the classes in this package use to perform raw JDBC actions).
Subclasses should set SQL and add parameters before invoking the compile() method. The order in which parameters are added is significant. The appropriate execute or update method can then be invoked.
compile()
,
org.springframework.dao
,
org.springframework.jdbc.core
Field Summary | |
protected Log |
logger
|
Constructor Summary | |
RdbmsOperation()
|
Method Summary | |
void |
afterPropertiesSet()
Ensures compilation if used in a bean factory. |
void |
compile()
Compile this query. |
protected abstract void |
compileInternal()
Subclasses must implement to perform their own compilation. |
void |
declareParameter(SqlParameter param)
Declare a parameter. |
protected List |
getDeclaredParameters()
Return a list of the declared SqlParameter objects. |
String[] |
getGeneratedKeysColumnNames()
Return the column names of the auto generated keys. |
protected JdbcTemplate |
getJdbcTemplate()
Return the JdbcTemplate object used by this object. |
protected 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"? |
protected boolean |
isReturnGeneratedKeys()
Return whether statements should be capable of returning auto-generated keys. |
protected boolean |
isUpdatableResults()
Return whether statements will return updatable ResultSets. |
void |
setDataSource(DataSource dataSource)
Set the JDBC DataSource to obtain connections from. |
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. |
protected 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. |
protected void |
setUpdatableResults(boolean updatableResults)
Set whether to use statements that are capable of returning updatable ResultSets. |
protected boolean |
supportsLobParameters()
Return whether BLOB or CLOB parameters are supported for this kind of operation. |
protected void |
validateParameters(Object[] parameters)
Validate the parameters passed to an execute method based on declared parameters. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final Log logger
Constructor Detail |
public RdbmsOperation()
Method Detail |
public void setDataSource(DataSource dataSource)
public void setJdbcTemplate(JdbcTemplate jdbcTemplate)
jdbcTemplate
- protected JdbcTemplate getJdbcTemplate()
protected void setResultSetType(int resultSetType)
resultSetType
- the ResultSet typeResultSet.TYPE_FORWARD_ONLY
,
ResultSet.TYPE_SCROLL_INSENSITIVE
,
ResultSet.TYPE_SCROLL_SENSITIVE
protected int getResultSetType()
protected void setUpdatableResults(boolean updatableResults)
protected boolean isUpdatableResults()
public void setReturnGeneratedKeys(boolean returnGeneratedKeys)
protected 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
Parameter ordering is significant. This method is an alternative to the declareParameter() method, which should normally be preferred.
types
- array of SQL types as defined in the
java.sql.Types class
InvalidDataAccessApiUsageException
- if the operation is already compiledpublic void declareParameter(SqlParameter param) throws InvalidDataAccessApiUsageException
param
- SqlParameter to add. This will specify SQL type and (optionally)
the parameter's name.
InvalidDataAccessApiUsageException
- if the operation is already compiled,
and hence cannot be configured furtherprotected List getDeclaredParameters()
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 provided.protected abstract void compileInternal() throws InvalidDataAccessApiUsageException
InvalidDataAccessApiUsageException
- if the subclass
hasn't been properly configured.public boolean isCompiled()
protected void validateParameters(Object[] parameters) throws InvalidDataAccessApiUsageException
parameters
- parameters supplied. May be null.
InvalidDataAccessApiUsageException
- if the parameters are invalidprotected boolean supportsLobParameters()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |