org.springframework.orm.ibatis
Class SqlMapTemplate

org.springframework.jdbc.support.JdbcAccessor
  |
  +--org.springframework.orm.ibatis.SqlMapTemplate

public class SqlMapTemplate
extends JdbcAccessor
implements SqlMapOperations

Helper class that simplifies data access via the MappedStatement API of the iBATIS Database Layer, and converts checked SQLExceptions into unchecked DataAccessExceptions, compatible to the org.springframework.dao exception hierarchy. Uses the same SQLExceptionTranslator mechanism as JdbcTemplate.

The main method is execute, taking the name of a mapped statement defined in the iBATIS SqlMap config file and a callback that implements a data access action on the specified statement.

This class provides numerous convenience methods that mirror MappedStatement's executeXXX methods. See the MappedStatement javadocs for details on those methods.

Author:
Juergen Hoeller
Since: 28.11.2003
See Also: execute(java.lang.String,org.springframework.orm.ibatis.SqlMapCallback), setSqlMap(SqlMap), org.springframework.jdbc.support.JdbcAccessor.setDataSource(javax.sql.DataSource), org.springframework.jdbc.support.JdbcAccessor.setExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator), com.ibatis.db.sqlmap.MappedStatement

Constructor Summary
SqlMapTemplate()
          Create a new SqlMapTemplate.
SqlMapTemplate(DataSource dataSource, SqlMap sqlMap)
          Create a new SqlMapTemplate.

Method Summary
 Objectexecute(String statementName, SqlMapCallback action)
          Execute the given data access action on the given mapped statement.
 ListexecuteQueryForList(String statementName, Object parameterObject)
           
 ListexecuteQueryForList(String statementName, Object parameterObject, int skipResults, int maxResults)
           
 MapexecuteQueryForMap(String statementName, Object parameterObject, String keyProperty)
           
 MapexecuteQueryForMap(String statementName, Object parameterObject, String keyProperty, String valueProperty)
           
 ObjectexecuteQueryForObject(String statementName, Object parameterObject)
           
 ObjectexecuteQueryForObject(String statementName, Object parameterObject, Object resultObject)
           
 voidexecuteQueryWithRowHandler(String statementName, Object parameterObject, RowHandler rowHandler)
           
 intexecuteUpdate(String statementName, Object parameterObject)
           
 ListexecuteWithListResult(String statementName, SqlMapCallback action)
          Execute the given data access action on the given mapped statement, expecting a List result.
 MapexecuteWithMapResult(String statementName, SqlMapCallback action)
          Execute the given data access action on the given mapped statement, expecting a Map result.
 SqlMapgetSqlMap()
          Return the iBATIS Database Layer SqlMap that this template works with.
 voidsetSqlMap(SqlMap sqlMap)
          Set the iBATIS Database Layer SqlMap that defines the mapped statements.

Methods inherited from class org.springframework.jdbc.support.JdbcAccessor
afterPropertiesSet, getDataSource, getExceptionTranslator, setDataSource, setExceptionTranslator

Constructor Detail

SqlMapTemplate

public SqlMapTemplate()
Create a new SqlMapTemplate.

SqlMapTemplate

public SqlMapTemplate(DataSource dataSource, SqlMap sqlMap)
Create a new SqlMapTemplate.
Parameters:
dataSource - JDBC DataSource to obtain connections from
sqlMap - iBATIS SqlMap that defines the mapped statements
Method Detail

execute

public Object execute(String statementName, SqlMapCallback action)
throws org.springframework.dao.DataAccessException
Execute the given data access action on the given mapped statement.
Parameters:
statementName - name of the statement mapped in the iBATIS SqlMap config file
action - callback object that specifies the data access action
Throws:
DataAccessException - in case of Hibernate errors

executeQueryForList

public List executeQueryForList(String statementName, Object parameterObject)
throws org.springframework.dao.DataAccessException

executeQueryForList

public List executeQueryForList(String statementName, Object parameterObject, int skipResults, int maxResults)
throws org.springframework.dao.DataAccessException

executeQueryForMap

public Map executeQueryForMap(String statementName, Object parameterObject, String keyProperty)
throws org.springframework.dao.DataAccessException

executeQueryForMap

public Map executeQueryForMap(String statementName, Object parameterObject, String keyProperty, String valueProperty)
throws org.springframework.dao.DataAccessException

executeQueryForObject

public Object executeQueryForObject(String statementName, Object parameterObject)
throws org.springframework.dao.DataAccessException

executeQueryForObject

public Object executeQueryForObject(String statementName, Object parameterObject, Object resultObject)
throws org.springframework.dao.DataAccessException

executeQueryWithRowHandler

public void executeQueryWithRowHandler(String statementName, Object parameterObject, RowHandler rowHandler)
throws org.springframework.dao.DataAccessException

executeUpdate

public int executeUpdate(String statementName, Object parameterObject)
throws org.springframework.dao.DataAccessException

executeWithListResult

public List executeWithListResult(String statementName, SqlMapCallback action)
throws org.springframework.dao.DataAccessException
Execute the given data access action on the given mapped statement, expecting a List result.
Parameters:
statementName - name of the statement mapped in the iBATIS SqlMap config file
action - callback object that specifies the data access action
Throws:
DataAccessException - in case of Hibernate errors

executeWithMapResult

public Map executeWithMapResult(String statementName, SqlMapCallback action)
throws org.springframework.dao.DataAccessException
Execute the given data access action on the given mapped statement, expecting a Map result.
Parameters:
statementName - name of the statement mapped in the iBATIS SqlMap config file
action - callback object that specifies the data access action
Throws:
DataAccessException - in case of Hibernate errors

getSqlMap

public SqlMap getSqlMap()
Return the iBATIS Database Layer SqlMap that this template works with.

setSqlMap

public void setSqlMap(SqlMap sqlMap)
Set the iBATIS Database Layer SqlMap that defines the mapped statements.