public class

SqlMapClientTemplate

extends JdbcAccessor
implements SqlMapClientOperations
java.lang.Object
   ↳ org.springframework.jdbc.support.JdbcAccessor
     ↳ org.springframework.orm.ibatis.SqlMapClientTemplate

Class Overview

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).

Summary

[Expand]
Inherited Fields
From class org.springframework.jdbc.support.JdbcAccessor
Public Constructors
SqlMapClientTemplate()
Create a new SqlMapClientTemplate.
SqlMapClientTemplate(SqlMapClient sqlMapClient)
Create a new SqlMapTemplate.
SqlMapClientTemplate(DataSource dataSource, SqlMapClient sqlMapClient)
Create a new SqlMapTemplate.
Public Methods
void afterPropertiesSet()
Eagerly initialize the exception translator, if demanded, creating a default one for the specified DataSource if none set.
int delete(String statementName, Object parameterObject)
void delete(String statementName, 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.
int delete(String statementName)
<T> T execute(SqlMapClientCallback<T> action)
Execute the given data access action on a SqlMapExecutor.
List executeWithListResult(SqlMapClientCallback<List> action)
This method is deprecated. as of Spring 3.0 - not really needed anymore with generic execute(SqlMapClientCallback) method
Map executeWithMapResult(SqlMapClientCallback<Map> action)
This method is deprecated. as of Spring 3.0 - not really needed anymore with generic execute(SqlMapClientCallback) method
DataSource getDataSource()
If no DataSource specified, use SqlMapClient's DataSource.
SqlMapClient getSqlMapClient()
Return the iBATIS Database Layer SqlMapClient that this template works with.
Object insert(String statementName)
Object insert(String statementName, Object parameterObject)
List queryForList(String statementName, Object parameterObject)
List queryForList(String statementName)
List queryForList(String statementName, int skipResults, int maxResults)
List queryForList(String statementName, Object parameterObject, int skipResults, int maxResults)
Map queryForMap(String statementName, Object parameterObject, String keyProperty)
Map queryForMap(String statementName, Object parameterObject, String keyProperty, String valueProperty)
Object queryForObject(String statementName, Object parameterObject)
Object queryForObject(String statementName, Object parameterObject, Object resultObject)
Object queryForObject(String statementName)
void queryWithRowHandler(String statementName, RowHandler rowHandler)
void queryWithRowHandler(String statementName, Object parameterObject, RowHandler rowHandler)
void setSqlMapClient(SqlMapClient sqlMapClient)
Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.
int update(String statementName, Object parameterObject)
int update(String statementName)
void update(String statementName, 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.
[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

Public Constructors

public SqlMapClientTemplate ()

Create a new SqlMapClientTemplate.

public SqlMapClientTemplate (SqlMapClient sqlMapClient)

Create a new SqlMapTemplate.

Parameters
sqlMapClient iBATIS SqlMapClient that defines the mapped statements

public SqlMapClientTemplate (DataSource dataSource, SqlMapClient sqlMapClient)

Create a new SqlMapTemplate.

Parameters
dataSource JDBC DataSource to obtain connections from
sqlMapClient iBATIS SqlMapClient that defines the mapped statements

Public Methods

public void afterPropertiesSet ()

Eagerly initialize the exception translator, if demanded, creating a default one for the specified DataSource if none set.

public int delete (String statementName, Object parameterObject)

public void delete (String statementName, 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.

Parameters
statementName the name of the mapped statement
parameterObject the parameter object
requiredRowsAffected the number of rows that the delete is required to affect

public int delete (String statementName)

public T execute (SqlMapClientCallback<T> action)

Execute the given data access action on a SqlMapExecutor.

Parameters
action callback object that specifies the data access action
Returns
  • a result object returned by the action, or null
Throws
DataAccessException in case of SQL Maps errors

public List executeWithListResult (SqlMapClientCallback<List> action)

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.

Parameters
action callback object that specifies the data access action
Returns
  • the List result
Throws
DataAccessException in case of SQL Maps errors

public Map executeWithMapResult (SqlMapClientCallback<Map> action)

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.

Parameters
action callback object that specifies the data access action
Returns
  • the Map result
Throws
DataAccessException in case of SQL Maps errors

public DataSource getDataSource ()

If no DataSource specified, use SqlMapClient's DataSource.

See Also
  • com.ibatis.sqlmap.client.SqlMapClient#getDataSource()

public SqlMapClient getSqlMapClient ()

Return the iBATIS Database Layer SqlMapClient that this template works with.

public Object insert (String statementName)

public Object insert (String statementName, Object parameterObject)

public List queryForList (String statementName, Object parameterObject)

public List queryForList (String statementName)

public List queryForList (String statementName, int skipResults, int maxResults)

public List queryForList (String statementName, Object parameterObject, int skipResults, int maxResults)

public Map queryForMap (String statementName, Object parameterObject, String keyProperty)

public Map queryForMap (String statementName, Object parameterObject, String keyProperty, String valueProperty)

public Object queryForObject (String statementName, Object parameterObject)

public Object queryForObject (String statementName, Object parameterObject, Object resultObject)

public Object queryForObject (String statementName)

public void queryWithRowHandler (String statementName, RowHandler rowHandler)

public void queryWithRowHandler (String statementName, Object parameterObject, RowHandler rowHandler)

public void setSqlMapClient (SqlMapClient sqlMapClient)

Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.

public int update (String statementName, Object parameterObject)

public int update (String statementName)

public void update (String statementName, 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.

Parameters
statementName the name of the mapped statement
parameterObject the parameter object
requiredRowsAffected the number of rows that the update is required to affect