Save This Page
Home » spring-framework-2.5.6-with-dependencies » org.springframework » orm » ibatis » [javadoc | source]
org.springframework.orm.ibatis
public class: SqlMapClientTemplate [javadoc | source]
java.lang.Object
   org.springframework.jdbc.support.JdbcAccessor
      org.springframework.orm.ibatis.SqlMapClientTemplate

All Implemented Interfaces:
    SqlMapClientOperations, InitializingBean

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 org.springframework.jdbc.support.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 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).
Fields inherited from org.springframework.jdbc.support.JdbcAccessor:
logger
Constructor:
 public 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
Method from org.springframework.orm.ibatis.SqlMapClientTemplate Summary:
afterPropertiesSet,   delete,   delete,   delete,   execute,   executeWithListResult,   executeWithMapResult,   getDataSource,   getSqlMapClient,   insert,   insert,   queryForList,   queryForList,   queryForList,   queryForList,   queryForMap,   queryForMap,   queryForObject,   queryForObject,   queryForObject,   queryForPaginatedList,   queryForPaginatedList,   queryWithRowHandler,   queryWithRowHandler,   setSqlMapClient,   update,   update,   update
Methods from org.springframework.jdbc.support.JdbcAccessor:
afterPropertiesSet,   getDataSource,   getExceptionTranslator,   isLazyInit,   setDataSource,   setDatabaseProductName,   setExceptionTranslator,   setLazyInit
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.orm.ibatis.SqlMapClientTemplate Detail:
 public  void afterPropertiesSet() 
 public int delete(String statementName) throws DataAccessException 
 public int delete(String statementName,
    Object parameterObject) throws DataAccessException 
 public  void delete(String statementName,
    Object parameterObject,
    int requiredRowsAffected) throws DataAccessException 
 public Object execute(SqlMapClientCallback action) throws DataAccessException 
    Execute the given data access action on a SqlMapExecutor.
 public List executeWithListResult(SqlMapClientCallback action) throws DataAccessException 
    Execute the given data access action on a SqlMapExecutor, expecting a List result.
 public Map executeWithMapResult(SqlMapClientCallback action) throws DataAccessException 
    Execute the given data access action on a SqlMapExecutor, expecting a Map result.
 public DataSource getDataSource() 
    If no DataSource specified, use SqlMapClient's DataSource.
 public SqlMapClient getSqlMapClient() 
    Return the iBATIS Database Layer SqlMapClient that this template works with.
 public Object insert(String statementName) throws DataAccessException 
 public Object insert(String statementName,
    Object parameterObject) throws DataAccessException 
 public List queryForList(String statementName) throws DataAccessException 
 public List queryForList(String statementName,
    Object parameterObject) throws DataAccessException 
 public List queryForList(String statementName,
    int skipResults,
    int maxResults) throws DataAccessException 
 public List queryForList(String statementName,
    Object parameterObject,
    int skipResults,
    int maxResults) throws DataAccessException 
 public Map queryForMap(String statementName,
    Object parameterObject,
    String keyProperty) throws DataAccessException 
 public Map queryForMap(String statementName,
    Object parameterObject,
    String keyProperty,
    String valueProperty) throws DataAccessException 
 public Object queryForObject(String statementName) throws DataAccessException 
 public Object queryForObject(String statementName,
    Object parameterObject) throws DataAccessException 
 public Object queryForObject(String statementName,
    Object parameterObject,
    Object resultObject) throws DataAccessException 
 public PaginatedList queryForPaginatedList(String statementName,
    int pageSize) throws DataAccessException 
Deprecated! as - of iBATIS 2.3.0

 public PaginatedList queryForPaginatedList(String statementName,
    Object parameterObject,
    int pageSize) throws DataAccessException 
Deprecated! as - of iBATIS 2.3.0

 public  void queryWithRowHandler(String statementName,
    RowHandler rowHandler) throws DataAccessException 
 public  void queryWithRowHandler(String statementName,
    Object parameterObject,
    RowHandler rowHandler) throws DataAccessException 
 public  void setSqlMapClient(SqlMapClient sqlMapClient) 
    Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.
 public int update(String statementName) throws DataAccessException 
 public int update(String statementName,
    Object parameterObject) throws DataAccessException 
 public  void update(String statementName,
    Object parameterObject,
    int requiredRowsAffected) throws DataAccessException