| java.lang.Object | ||
| ↳ | org.springframework.jdbc.support.JdbcAccessor | |
| ↳ | org.springframework.orm.ibatis.SqlMapClientTemplate | |
Helper class that simplifies data access via the iBATIS
com.ibatis.sqlmap.client.SqlMapClient API, converting checked
SQLExceptions into unchecked DataAccessExceptions, following the
org.springframework.dao exception hierarchy.
Uses the same SQLExceptionTranslator
mechanism as JdbcTemplate.
The main method of this class executes a callback that implements a data access action. Furthermore, this class provides numerous convenience methods that mirror com.ibatis.sqlmap.client.SqlMapExecutor's execution methods.
It is generally recommended to use the convenience methods on this template for plain query/insert/update/delete operations. However, for more complex operations like batch updates, a custom SqlMapClientCallback must be implemented, usually as anonymous inner class. For example:
getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
executor.update("insertSomething", "myParamValue");
executor.update("insertSomethingElse", "myOtherParamValue");
executor.executeBatch();
return null;
}
});
The template needs a SqlMapClient to work on, passed in via the "sqlMapClient"
property. A Spring context typically uses a SqlMapClientFactoryBean
to build the SqlMapClient. The template an additionally be configured with a
DataSource for fetching Connections, although this is not necessary if a
DataSource is specified for the SqlMapClient itself (typically through
SqlMapClientFactoryBean's "dataSource" property).
execute(SqlMapClientCallback) setSqlMapClient(SqlMapClient)setDataSource(DataSource)setExceptionTranslator(SQLExceptionTranslator)setDataSource(DataSource)|
[Expand]
Inherited Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jdbc.support.JdbcAccessor
| |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Create a new SqlMapClientTemplate.
| |||||||||||
Create a new SqlMapTemplate.
| |||||||||||
Create a new SqlMapTemplate.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Eagerly initialize the exception translator, if demanded,
creating a default one for the specified DataSource if none set.
| |||||||||||
Convenience method provided by Spring: execute a delete operation
with an automatic check that the delete affected the given required
number of rows.
| |||||||||||
Execute the given data access action on a SqlMapExecutor.
| |||||||||||
This method is deprecated.
as of Spring 3.0 - not really needed anymore with generic
execute(SqlMapClientCallback method
| |||||||||||
This method is deprecated.
as of Spring 3.0 - not really needed anymore with generic
execute(SqlMapClientCallback method
| |||||||||||
If no DataSource specified, use SqlMapClient's DataSource.
| |||||||||||
Return the iBATIS Database Layer SqlMapClient that this template works with.
| |||||||||||
Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.
| |||||||||||
Convenience method provided by Spring: execute an update operation
with an automatic check that the update affected the given required
number of rows.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.jdbc.support.JdbcAccessor
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.InitializingBean
| |||||||||||
From interface
org.springframework.orm.ibatis.SqlMapClientOperations
| |||||||||||
Create a new SqlMapClientTemplate.
Create a new SqlMapTemplate.
| sqlMapClient | iBATIS SqlMapClient that defines the mapped statements |
|---|
Create a new SqlMapTemplate.
| dataSource | JDBC DataSource to obtain connections from |
|---|---|
| sqlMapClient | iBATIS SqlMapClient that defines the mapped statements |
Eagerly initialize the exception translator, if demanded, creating a default one for the specified DataSource if none set.
Convenience method provided by Spring: execute a delete operation with an automatic check that the delete affected the given required number of rows.
| statementName | the name of the mapped statement |
|---|---|
| parameterObject | the parameter object |
| requiredRowsAffected | the number of rows that the delete is required to affect |
| DataAccessException |
|---|
Execute the given data access action on a SqlMapExecutor.
| action | callback object that specifies the data access action |
|---|
null| DataAccessException | in case of SQL Maps errors |
|---|
This method is deprecated.
as of Spring 3.0 - not really needed anymore with generic
execute(SqlMapClientCallback method
Execute the given data access action on a SqlMapExecutor, expecting a List result.
| action | callback object that specifies the data access action |
|---|
| DataAccessException | in case of SQL Maps errors |
|---|
This method is deprecated.
as of Spring 3.0 - not really needed anymore with generic
execute(SqlMapClientCallback method
Execute the given data access action on a SqlMapExecutor, expecting a Map result.
| action | callback object that specifies the data access action |
|---|
| DataAccessException | in case of SQL Maps errors |
|---|
If no DataSource specified, use SqlMapClient's DataSource.
Return the iBATIS Database Layer SqlMapClient that this template works with.
| DataAccessException |
|---|
| DataAccessException |
|---|
| DataAccessException |
|---|
| DataAccessException |
|---|
| DataAccessException |
|---|
| DataAccessException |
|---|
| DataAccessException |
|---|
| DataAccessException |
|---|
Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.
Convenience method provided by Spring: execute an update operation with an automatic check that the update affected the given required number of rows.
| statementName | the name of the mapped statement |
|---|---|
| parameterObject | the parameter object |
| requiredRowsAffected | the number of rows that the update is required to affect |
| DataAccessException |
|---|