Class SqlMapClientTemplate
java.lang.Object
org.springframework.jdbc.support.JdbcAccessor
org.springframework.orm.ibatis.SqlMapClientTemplate
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, SqlMapClientOperations
@Deprecated
public class SqlMapClientTemplate
extends org.springframework.jdbc.support.JdbcAccessor
implements SqlMapClientOperations
Deprecated.
as of Spring 3.2, in favor of the native Spring support in the Mybatis follow-up project
(https://mybatis.org/)
Helper class that simplifies data access via the iBATIS
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 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 can 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).- Since:
- 24.02.2004
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from class org.springframework.jdbc.support.JdbcAccessor
logger -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Create a new SqlMapClientTemplate.SqlMapClientTemplate(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient) Deprecated.Create a new SqlMapTemplate.SqlMapClientTemplate(DataSource dataSource, com.ibatis.sqlmap.client.SqlMapClient sqlMapClient) Deprecated.Create a new SqlMapTemplate. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.intDeprecated.intDeprecated.voidDeprecated.Convenience method provided by Spring: execute a delete operation with an automatic check that the delete affected the given required number of rows.<T> Texecute(SqlMapClientCallback<T> action) Deprecated.Execute the given data access action on a SqlMapExecutor.Deprecated.as of Spring 3.0 - not really needed anymore with genericexecute(SqlMapClientCallback)methodexecuteWithMapResult(SqlMapClientCallback<Map> action) Deprecated.as of Spring 3.0 - not really needed anymore with genericexecute(SqlMapClientCallback)methodDeprecated.If no DataSource specified, use SqlMapClient's DataSource.com.ibatis.sqlmap.client.SqlMapClientDeprecated.Return the iBATIS Database Layer SqlMapClient that this template works with.Deprecated.Deprecated.queryForList(String statementName) Deprecated.queryForList(String statementName, int skipResults, int maxResults) Deprecated.queryForList(String statementName, Object parameterObject) Deprecated.queryForList(String statementName, Object parameterObject, int skipResults, int maxResults) Deprecated.queryForMap(String statementName, Object parameterObject, String keyProperty) Deprecated.queryForMap(String statementName, Object parameterObject, String keyProperty, String valueProperty) Deprecated.queryForObject(String statementName) Deprecated.queryForObject(String statementName, Object parameterObject) Deprecated.queryForObject(String statementName, Object parameterObject, Object resultObject) Deprecated.voidqueryWithRowHandler(String statementName, com.ibatis.sqlmap.client.event.RowHandler rowHandler) Deprecated.voidqueryWithRowHandler(String statementName, Object parameterObject, com.ibatis.sqlmap.client.event.RowHandler rowHandler) Deprecated.voidsetSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient) Deprecated.Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.intDeprecated.intDeprecated.voidDeprecated.Convenience method provided by Spring: execute an update operation with an automatic check that the update affected the given required number of rows.Methods inherited from class org.springframework.jdbc.support.JdbcAccessor
getExceptionTranslator, isLazyInit, obtainDataSource, setDatabaseProductName, setDataSource, setExceptionTranslator, setLazyInit
-
Constructor Details
-
SqlMapClientTemplate
public SqlMapClientTemplate()Deprecated.Create a new SqlMapClientTemplate. -
SqlMapClientTemplate
public SqlMapClientTemplate(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient) Deprecated.Create a new SqlMapTemplate.- Parameters:
sqlMapClient- iBATIS SqlMapClient that defines the mapped statements
-
SqlMapClientTemplate
public SqlMapClientTemplate(DataSource dataSource, com.ibatis.sqlmap.client.SqlMapClient sqlMapClient) Deprecated.Create a new SqlMapTemplate.- Parameters:
dataSource- JDBC DataSource to obtain connections fromsqlMapClient- iBATIS SqlMapClient that defines the mapped statements
-
-
Method Details
-
setSqlMapClient
public void setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient) Deprecated.Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.- Parameters:
sqlMapClient- the SqlMapClient to use
-
getSqlMapClient
public com.ibatis.sqlmap.client.SqlMapClient getSqlMapClient()Deprecated.Return the iBATIS Database Layer SqlMapClient that this template works with.- Returns:
- the SqlMapClient
-
getDataSource
Deprecated.If no DataSource specified, use SqlMapClient's DataSource.- Overrides:
getDataSourcein classorg.springframework.jdbc.support.JdbcAccessor- See Also:
-
afterPropertiesSet
public void afterPropertiesSet()Deprecated.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classorg.springframework.jdbc.support.JdbcAccessor
-
execute
public <T> T execute(SqlMapClientCallback<T> action) throws org.springframework.dao.DataAccessException Deprecated.Execute the given data access action on a SqlMapExecutor.- Type Parameters:
T- the result type- Parameters:
action- callback object that specifies the data access action- Returns:
- a result object returned by the action, or
null - Throws:
org.springframework.dao.DataAccessException- in case of SQL Maps errors
-
executeWithListResult
@Deprecated public List executeWithListResult(SqlMapClientCallback<List> action) throws org.springframework.dao.DataAccessException Deprecated.as of Spring 3.0 - not really needed anymore with genericexecute(SqlMapClientCallback)methodExecute the given data access action on a SqlMapExecutor, expecting a List result.- Parameters:
action- callback object that specifies the data access action- Returns:
- the List result
- Throws:
org.springframework.dao.DataAccessException- in case of SQL Maps errors
-
executeWithMapResult
@Deprecated public Map executeWithMapResult(SqlMapClientCallback<Map> action) throws org.springframework.dao.DataAccessException Deprecated.as of Spring 3.0 - not really needed anymore with genericexecute(SqlMapClientCallback)methodExecute the given data access action on a SqlMapExecutor, expecting a Map result.- Parameters:
action- callback object that specifies the data access action- Returns:
- the Map result
- Throws:
org.springframework.dao.DataAccessException- in case of SQL Maps errors
-
queryForObject
public Object queryForObject(String statementName) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryForObjectin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryForObject
public Object queryForObject(String statementName, Object parameterObject) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryForObjectin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryForObject
public Object queryForObject(String statementName, Object parameterObject, Object resultObject) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryForObjectin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryForList
Deprecated.- Specified by:
queryForListin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryForList
public List queryForList(String statementName, Object parameterObject) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryForListin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryForList
public List queryForList(String statementName, int skipResults, int maxResults) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryForListin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryForList
public List queryForList(String statementName, Object parameterObject, int skipResults, int maxResults) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryForListin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryWithRowHandler
public void queryWithRowHandler(String statementName, com.ibatis.sqlmap.client.event.RowHandler rowHandler) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryWithRowHandlerin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryWithRowHandler
public void queryWithRowHandler(String statementName, Object parameterObject, com.ibatis.sqlmap.client.event.RowHandler rowHandler) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryWithRowHandlerin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryForMap
public Map queryForMap(String statementName, Object parameterObject, String keyProperty) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryForMapin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
queryForMap
public Map queryForMap(String statementName, Object parameterObject, String keyProperty, String valueProperty) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
queryForMapin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
insert
Deprecated.- Specified by:
insertin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
insert
public Object insert(String statementName, Object parameterObject) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
insertin interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
update
Deprecated.- Specified by:
updatein interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
update
public int update(String statementName, Object parameterObject) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
updatein interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
update
public void update(String statementName, Object parameterObject, int requiredRowsAffected) throws org.springframework.dao.DataAccessException Deprecated.Description copied from interface:SqlMapClientOperationsConvenience method provided by Spring: execute an update operation with an automatic check that the update affected the given required number of rows.- Specified by:
updatein interfaceSqlMapClientOperations- Parameters:
statementName- the name of the mapped statementparameterObject- the parameter objectrequiredRowsAffected- the number of rows that the update is required to affect- Throws:
org.springframework.dao.DataAccessException- in case of errors
-
delete
Deprecated.- Specified by:
deletein interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
delete
public int delete(String statementName, Object parameterObject) throws org.springframework.dao.DataAccessException Deprecated.- Specified by:
deletein interfaceSqlMapClientOperations- Throws:
org.springframework.dao.DataAccessException- in case of errors- See Also:
-
delete
public void delete(String statementName, Object parameterObject, int requiredRowsAffected) throws org.springframework.dao.DataAccessException Deprecated.Description copied from interface:SqlMapClientOperationsConvenience method provided by Spring: execute a delete operation with an automatic check that the delete affected the given required number of rows.- Specified by:
deletein interfaceSqlMapClientOperations- Parameters:
statementName- the name of the mapped statementparameterObject- the parameter objectrequiredRowsAffected- the number of rows that the delete is required to affect- Throws:
org.springframework.dao.DataAccessException- in case of errors
-