org.springframework.orm.ibatis
Class SqlMapTemplate

java.lang.Object
  extended byorg.springframework.jdbc.support.JdbcAccessor
      extended byorg.springframework.orm.ibatis.SqlMapTemplate
All Implemented Interfaces:
SqlMapOperations

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.

NOTE: The SqlMap/MappedStatement API is the one to use with iBATIS SQL Maps 1.x. The SqlMapClient/SqlMapSession API is only available with SQL Maps 2.

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

Constructor Summary
SqlMapTemplate()
          Create a new SqlMapTemplate.
SqlMapTemplate(javax.sql.DataSource dataSource, com.ibatis.db.sqlmap.SqlMap sqlMap)
          Create a new SqlMapTemplate.
 
Method Summary
 void afterPropertiesSet()
          Eagerly initialize the exception translator, creating a default one for the specified DataSource if none set.
 java.lang.Object execute(java.lang.String statementName, SqlMapCallback action)
          Execute the given data access action on the given iBATIS mapped statement.
 java.util.List executeQueryForList(java.lang.String statementName, java.lang.Object parameterObject)
           
 java.util.List executeQueryForList(java.lang.String statementName, java.lang.Object parameterObject, int skipResults, int maxResults)
           
 java.util.Map executeQueryForMap(java.lang.String statementName, java.lang.Object parameterObject, java.lang.String keyProperty)
           
 java.util.Map executeQueryForMap(java.lang.String statementName, java.lang.Object parameterObject, java.lang.String keyProperty, java.lang.String valueProperty)
           
 java.lang.Object executeQueryForObject(java.lang.String statementName, java.lang.Object parameterObject)
           
 java.lang.Object executeQueryForObject(java.lang.String statementName, java.lang.Object parameterObject, java.lang.Object resultObject)
           
 void executeQueryWithRowHandler(java.lang.String statementName, java.lang.Object parameterObject, com.ibatis.db.sqlmap.RowHandler rowHandler)
           
 int executeUpdate(java.lang.String statementName, java.lang.Object parameterObject)
           
 java.util.List executeWithListResult(java.lang.String statementName, SqlMapCallback action)
          Execute the given data access action on the given mapped statement, expecting a List result.
 java.util.Map executeWithMapResult(java.lang.String statementName, SqlMapCallback action)
          Execute the given data access action on the given mapped statement, expecting a Map result.
 com.ibatis.db.sqlmap.SqlMap getSqlMap()
          Return the iBATIS Database Layer SqlMap that this template works with.
 void setSqlMap(com.ibatis.db.sqlmap.SqlMap sqlMap)
          Set the iBATIS Database Layer SqlMap that defines the mapped statements.
 
Methods inherited from class org.springframework.jdbc.support.JdbcAccessor
getDataSource, getExceptionTranslator, setDataSource, setExceptionTranslator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlMapTemplate

public SqlMapTemplate()
Create a new SqlMapTemplate.


SqlMapTemplate

public SqlMapTemplate(javax.sql.DataSource dataSource,
                      com.ibatis.db.sqlmap.SqlMap sqlMap)
Create a new SqlMapTemplate.

Parameters:
dataSource - JDBC DataSource to obtain connections from
sqlMap - iBATIS SqlMap that defines the mapped statements
Method Detail

setSqlMap

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


getSqlMap

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


afterPropertiesSet

public void afterPropertiesSet()
Description copied from class: JdbcAccessor
Eagerly initialize the exception translator, creating a default one for the specified DataSource if none set.

Overrides:
afterPropertiesSet in class JdbcAccessor

execute

public java.lang.Object execute(java.lang.String statementName,
                                SqlMapCallback action)
                         throws DataAccessException
Execute the given data access action on the given iBATIS mapped statement.

Parameters:
statementName - name of the statement mapped in the iBATIS SqlMap config file
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

executeWithListResult

public java.util.List executeWithListResult(java.lang.String statementName,
                                            SqlMapCallback action)
                                     throws 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
Returns:
a List result
Throws:
DataAccessException - in case of SQL Maps errors

executeWithMapResult

public java.util.Map executeWithMapResult(java.lang.String statementName,
                                          SqlMapCallback action)
                                   throws 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
Returns:
a Map result
Throws:
DataAccessException - in case of SQL Maps errors

executeQueryForObject

public java.lang.Object executeQueryForObject(java.lang.String statementName,
                                              java.lang.Object parameterObject)
                                       throws DataAccessException
Specified by:
executeQueryForObject in interface SqlMapOperations
Throws:
DataAccessException

executeQueryForObject

public java.lang.Object executeQueryForObject(java.lang.String statementName,
                                              java.lang.Object parameterObject,
                                              java.lang.Object resultObject)
                                       throws DataAccessException
Specified by:
executeQueryForObject in interface SqlMapOperations
Throws:
DataAccessException

executeQueryForList

public java.util.List executeQueryForList(java.lang.String statementName,
                                          java.lang.Object parameterObject)
                                   throws DataAccessException
Specified by:
executeQueryForList in interface SqlMapOperations
Throws:
DataAccessException

executeQueryForList

public java.util.List executeQueryForList(java.lang.String statementName,
                                          java.lang.Object parameterObject,
                                          int skipResults,
                                          int maxResults)
                                   throws DataAccessException
Specified by:
executeQueryForList in interface SqlMapOperations
Throws:
DataAccessException

executeQueryForMap

public java.util.Map executeQueryForMap(java.lang.String statementName,
                                        java.lang.Object parameterObject,
                                        java.lang.String keyProperty)
                                 throws DataAccessException
Specified by:
executeQueryForMap in interface SqlMapOperations
Throws:
DataAccessException

executeQueryForMap

public java.util.Map executeQueryForMap(java.lang.String statementName,
                                        java.lang.Object parameterObject,
                                        java.lang.String keyProperty,
                                        java.lang.String valueProperty)
                                 throws DataAccessException
Specified by:
executeQueryForMap in interface SqlMapOperations
Throws:
DataAccessException

executeQueryWithRowHandler

public void executeQueryWithRowHandler(java.lang.String statementName,
                                       java.lang.Object parameterObject,
                                       com.ibatis.db.sqlmap.RowHandler rowHandler)
                                throws DataAccessException
Specified by:
executeQueryWithRowHandler in interface SqlMapOperations
Throws:
DataAccessException

executeUpdate

public int executeUpdate(java.lang.String statementName,
                         java.lang.Object parameterObject)
                  throws DataAccessException
Specified by:
executeUpdate in interface SqlMapOperations
Throws:
DataAccessException


Copyright (C) 2003-2004 The Spring Framework Project.