org.springframework.orm.ibatis
Class SqlMapClientTemplate

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

public class SqlMapClientTemplate
extends JdbcAccessor
implements SqlMapClientOperations

Helper class that simplifies data access via the SqlMapClient 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, a callback that implements a data access action. This class provides numerous convenience methods that mirror SqlMapSession's execution methods. See the SqlMapClient javadocs for details on those methods.

NOTE: The SqlMapClient/SqlMapSession API is the API of iBATIS SQL Maps 2. With SQL Maps 1.x, the SqlMap/MappedStatement API has to be used.

Since:
24.02.2004
Author:
Juergen Hoeller
See Also:
execute(org.springframework.orm.ibatis.SqlMapClientCallback), setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient), JdbcAccessor.setDataSource(javax.sql.DataSource), JdbcAccessor.setExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator), SqlMapSession

Constructor Summary
SqlMapClientTemplate()
          Create a new SqlMapClientTemplate.
SqlMapClientTemplate(javax.sql.DataSource dataSource, com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
          Create a new SqlMapTemplate.
 
Method Summary
 void afterPropertiesSet()
          Eagerly initialize the exception translator, creating a default one for the specified DataSource if none set.
 int delete(java.lang.String statementName, java.lang.Object parameterObject)
           
 java.lang.Object execute(SqlMapClientCallback action)
          Execute the given data access action on an SqlMapSession.
 java.util.List executeWithListResult(SqlMapClientCallback action)
          Execute the given data access action on an SqlMapSession, expecting a List result.
 java.util.Map executeWithMapResult(SqlMapClientCallback action)
          Execute the given data access action on an SqlMapSession, expecting a Map result.
 com.ibatis.sqlmap.client.SqlMapClient getSqlMapClient()
          Return the iBATIS Database Layer SqlMapClient that this template works with.
 java.lang.Object insert(java.lang.String statementName, java.lang.Object parameterObject)
           
 java.util.List queryForList(java.lang.String statementName, java.lang.Object parameterObject)
           
 java.util.List queryForList(java.lang.String statementName, java.lang.Object parameterObject, int skipResults, int maxResults)
           
 java.util.List queryForList(java.lang.String statementName, java.lang.Object parameterObject, com.ibatis.sqlmap.client.event.RowHandler rowHandler)
           
 java.util.Map queryForMap(java.lang.String statementName, java.lang.Object parameterObject, java.lang.String keyProperty)
           
 java.util.Map queryForMap(java.lang.String statementName, java.lang.Object parameterObject, java.lang.String keyProperty, java.lang.String valueProperty)
           
 java.lang.Object queryForObject(java.lang.String statementName, java.lang.Object parameterObject)
           
 java.lang.Object queryForObject(java.lang.String statementName, java.lang.Object parameterObject, java.lang.Object resultObject)
           
 void setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
          Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.
 int update(java.lang.String statementName, java.lang.Object parameterObject)
           
 
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

SqlMapClientTemplate

public SqlMapClientTemplate()
Create a new SqlMapClientTemplate.


SqlMapClientTemplate

public SqlMapClientTemplate(javax.sql.DataSource dataSource,
                            com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
Create a new SqlMapTemplate.

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

setSqlMapClient

public void setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.


getSqlMapClient

public com.ibatis.sqlmap.client.SqlMapClient getSqlMapClient()
Return the iBATIS Database Layer SqlMapClient 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(SqlMapClientCallback action)
                         throws DataAccessException
Execute the given data access action on an SqlMapSession.

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

executeWithListResult

public java.util.List executeWithListResult(SqlMapClientCallback action)
                                     throws DataAccessException
Execute the given data access action on an SqlMapSession, 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

executeWithMapResult

public java.util.Map executeWithMapResult(SqlMapClientCallback action)
                                   throws DataAccessException
Execute the given data access action on an SqlMapSession, 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

queryForObject

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

queryForObject

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

queryForList

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

queryForList

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

queryForList

public java.util.List queryForList(java.lang.String statementName,
                                   java.lang.Object parameterObject,
                                   com.ibatis.sqlmap.client.event.RowHandler rowHandler)
                            throws DataAccessException
Specified by:
queryForList in interface SqlMapClientOperations
Throws:
DataAccessException

queryForMap

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

queryForMap

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

insert

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

update

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

delete

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


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