public class SqlMapClientTemplate extends org.springframework.jdbc.support.JdbcAccessor implements SqlMapClientOperations
SqlMapClient
API, converting checked
SQLExceptions into unchecked DataAccessExceptions, following the
org.springframework.dao
exception hierarchy.
Uses the same SQLExceptionTranslator
mechanism as org.springframework.jdbc.core.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 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(org.springframework.orm.ibatis.SqlMapClientCallback<T>)
,
setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient)
,
JdbcAccessor.setDataSource(javax.sql.DataSource)
,
JdbcAccessor.setExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
,
SqlMapClientFactoryBean.setDataSource(javax.sql.DataSource)
,
SqlMapTransactionManager.getDataSource()
,
SqlMapExecutor
Constructor and Description |
---|
SqlMapClientTemplate()
Create a new SqlMapClientTemplate.
|
SqlMapClientTemplate(javax.sql.DataSource dataSource,
com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
Create a new SqlMapTemplate.
|
SqlMapClientTemplate(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
Create a new SqlMapTemplate.
|
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
int |
delete(java.lang.String statementName) |
int |
delete(java.lang.String statementName,
java.lang.Object parameterObject) |
void |
delete(java.lang.String statementName,
java.lang.Object parameterObject,
int requiredRowsAffected)
Convenience method provided by Spring: execute a delete operation
with an automatic check that the delete affected the given required
number of rows.
|
<T> T |
execute(SqlMapClientCallback<T> action)
Execute the given data access action on a SqlMapExecutor.
|
java.util.List |
executeWithListResult(SqlMapClientCallback<java.util.List> action)
Deprecated.
as of Spring 3.0 - not really needed anymore with generic
execute(org.springframework.orm.ibatis.SqlMapClientCallback<T>) method |
java.util.Map |
executeWithMapResult(SqlMapClientCallback<java.util.Map> action)
Deprecated.
as of Spring 3.0 - not really needed anymore with generic
execute(org.springframework.orm.ibatis.SqlMapClientCallback<T>) method |
javax.sql.DataSource |
getDataSource()
If no DataSource specified, use SqlMapClient's DataSource.
|
com.ibatis.sqlmap.client.SqlMapClient |
getSqlMapClient()
Return the iBATIS Database Layer SqlMapClient that this template works with.
|
java.lang.Object |
insert(java.lang.String statementName) |
java.lang.Object |
insert(java.lang.String statementName,
java.lang.Object parameterObject) |
java.util.List |
queryForList(java.lang.String statementName) |
java.util.List |
queryForList(java.lang.String statementName,
int skipResults,
int maxResults) |
java.util.List |
queryForList(java.lang.String statementName,
java.lang.Object parameterObject) |
java.util.List |
queryForList(java.lang.String statementName,
java.lang.Object parameterObject,
int skipResults,
int maxResults) |
java.util.Map |
queryForMap(java.lang.String statementName,
java.lang.Object parameterObject,
java.lang.String keyProperty) |
java.util.Map |
queryForMap(java.lang.String statementName,
java.lang.Object parameterObject,
java.lang.String keyProperty,
java.lang.String valueProperty) |
java.lang.Object |
queryForObject(java.lang.String statementName) |
java.lang.Object |
queryForObject(java.lang.String statementName,
java.lang.Object parameterObject) |
java.lang.Object |
queryForObject(java.lang.String statementName,
java.lang.Object parameterObject,
java.lang.Object resultObject) |
void |
queryWithRowHandler(java.lang.String statementName,
java.lang.Object parameterObject,
com.ibatis.sqlmap.client.event.RowHandler rowHandler) |
void |
queryWithRowHandler(java.lang.String statementName,
com.ibatis.sqlmap.client.event.RowHandler rowHandler) |
void |
setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.
|
int |
update(java.lang.String statementName) |
int |
update(java.lang.String statementName,
java.lang.Object parameterObject) |
void |
update(java.lang.String statementName,
java.lang.Object parameterObject,
int requiredRowsAffected)
Convenience method provided by Spring: execute an update operation
with an automatic check that the update affected the given required
number of rows.
|
public SqlMapClientTemplate()
public SqlMapClientTemplate(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
sqlMapClient
- iBATIS SqlMapClient that defines the mapped statementspublic SqlMapClientTemplate(javax.sql.DataSource dataSource, com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
dataSource
- JDBC DataSource to obtain connections fromsqlMapClient
- iBATIS SqlMapClient that defines the mapped statementspublic void setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
public com.ibatis.sqlmap.client.SqlMapClient getSqlMapClient()
public javax.sql.DataSource getDataSource()
getDataSource
in class org.springframework.jdbc.support.JdbcAccessor
SqlMapTransactionManager.getDataSource()
public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
afterPropertiesSet
in class org.springframework.jdbc.support.JdbcAccessor
public <T> T execute(SqlMapClientCallback<T> action) throws org.springframework.dao.DataAccessException
action
- callback object that specifies the data access actionnull
org.springframework.dao.DataAccessException
- in case of SQL Maps errors@Deprecated public java.util.List executeWithListResult(SqlMapClientCallback<java.util.List> action) throws org.springframework.dao.DataAccessException
execute(org.springframework.orm.ibatis.SqlMapClientCallback<T>)
methodaction
- callback object that specifies the data access actionorg.springframework.dao.DataAccessException
- in case of SQL Maps errors@Deprecated public java.util.Map executeWithMapResult(SqlMapClientCallback<java.util.Map> action) throws org.springframework.dao.DataAccessException
execute(org.springframework.orm.ibatis.SqlMapClientCallback<T>)
methodaction
- callback object that specifies the data access actionorg.springframework.dao.DataAccessException
- in case of SQL Maps errorspublic java.lang.Object queryForObject(java.lang.String statementName) throws org.springframework.dao.DataAccessException
queryForObject
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryForObject(String)
public java.lang.Object queryForObject(java.lang.String statementName, java.lang.Object parameterObject) throws org.springframework.dao.DataAccessException
queryForObject
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryForObject(String, Object)
public java.lang.Object queryForObject(java.lang.String statementName, java.lang.Object parameterObject, java.lang.Object resultObject) throws org.springframework.dao.DataAccessException
queryForObject
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryForObject(String, Object, Object)
public java.util.List queryForList(java.lang.String statementName) throws org.springframework.dao.DataAccessException
queryForList
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryForList(String)
public java.util.List queryForList(java.lang.String statementName, java.lang.Object parameterObject) throws org.springframework.dao.DataAccessException
queryForList
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryForList(String, Object)
public java.util.List queryForList(java.lang.String statementName, int skipResults, int maxResults) throws org.springframework.dao.DataAccessException
queryForList
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryForList(String, int, int)
public java.util.List queryForList(java.lang.String statementName, java.lang.Object parameterObject, int skipResults, int maxResults) throws org.springframework.dao.DataAccessException
queryForList
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryForList(String, Object, int, int)
public void queryWithRowHandler(java.lang.String statementName, com.ibatis.sqlmap.client.event.RowHandler rowHandler) throws org.springframework.dao.DataAccessException
queryWithRowHandler
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryWithRowHandler(String, RowHandler)
public void queryWithRowHandler(java.lang.String statementName, java.lang.Object parameterObject, com.ibatis.sqlmap.client.event.RowHandler rowHandler) throws org.springframework.dao.DataAccessException
queryWithRowHandler
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryWithRowHandler(String, Object, RowHandler)
public java.util.Map queryForMap(java.lang.String statementName, java.lang.Object parameterObject, java.lang.String keyProperty) throws org.springframework.dao.DataAccessException
queryForMap
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryForMap(String, Object, String)
public java.util.Map queryForMap(java.lang.String statementName, java.lang.Object parameterObject, java.lang.String keyProperty, java.lang.String valueProperty) throws org.springframework.dao.DataAccessException
queryForMap
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.queryForMap(String, Object, String, String)
public java.lang.Object insert(java.lang.String statementName) throws org.springframework.dao.DataAccessException
insert
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.insert(String)
public java.lang.Object insert(java.lang.String statementName, java.lang.Object parameterObject) throws org.springframework.dao.DataAccessException
insert
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.insert(String, Object)
public int update(java.lang.String statementName) throws org.springframework.dao.DataAccessException
update
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.update(String)
public int update(java.lang.String statementName, java.lang.Object parameterObject) throws org.springframework.dao.DataAccessException
update
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.update(String, Object)
public void update(java.lang.String statementName, java.lang.Object parameterObject, int requiredRowsAffected) throws org.springframework.dao.DataAccessException
SqlMapClientOperations
update
in interface SqlMapClientOperations
statementName
- the name of the mapped statementparameterObject
- the parameter objectrequiredRowsAffected
- the number of rows that the update is
required to affectorg.springframework.dao.DataAccessException
- in case of errorspublic int delete(java.lang.String statementName) throws org.springframework.dao.DataAccessException
delete
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.delete(String)
public int delete(java.lang.String statementName, java.lang.Object parameterObject) throws org.springframework.dao.DataAccessException
delete
in interface SqlMapClientOperations
org.springframework.dao.DataAccessException
- in case of errorsSqlMapExecutor.delete(String, Object)
public void delete(java.lang.String statementName, java.lang.Object parameterObject, int requiredRowsAffected) throws org.springframework.dao.DataAccessException
SqlMapClientOperations
delete
in interface SqlMapClientOperations
statementName
- the name of the mapped statementparameterObject
- the parameter objectrequiredRowsAffected
- the number of rows that the delete is
required to affectorg.springframework.dao.DataAccessException
- in case of errors