|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.support.JdbcAccessor org.springframework.orm.ibatis.SqlMapClientTemplate
public class SqlMapClientTemplate
Helper class that simplifies data access via the SqlMapClient API of iBATIS
SQL Maps, and converts 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 SqlMapExecutor's execution methods. See the SqlMapExecutor javadocs for details on those 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. Can additionally be configured with a DataSource for fetching Connections, although this is not necessary if a DataSource is specified for the SqlMapClient itself.
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.
execute(org.springframework.orm.ibatis.SqlMapClientCallback)
,
setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient)
,
JdbcAccessor.setDataSource(javax.sql.DataSource)
,
JdbcAccessor.setExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
,
SqlMapClientFactoryBean.setDataSource(javax.sql.DataSource)
,
SqlMapTransactionManager.getDataSource()
,
SqlMapSession
,
SqlMapExecutor
Field Summary |
---|
Fields inherited from class org.springframework.jdbc.support.JdbcAccessor |
---|
logger |
Constructor Summary | |
---|---|
SqlMapClientTemplate()
Create a new SqlMapClientTemplate. |
|
SqlMapClientTemplate(DataSource dataSource,
com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
Create a new SqlMapTemplate. |
|
SqlMapClientTemplate(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(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. |
Object |
execute(SqlMapClientCallback action)
Execute the given data access action on a SqlMapSession. |
List |
executeWithListResult(SqlMapClientCallback action)
Execute the given data access action on a SqlMapSession, expecting a List result. |
Map |
executeWithMapResult(SqlMapClientCallback action)
Execute the given data access action on a SqlMapSession, expecting a Map result. |
DataSource |
getDataSource()
If no DataSource specified, use SqlMapClient's DataSource. |
com.ibatis.sqlmap.client.SqlMapClient |
getSqlMapClient()
Return the iBATIS Database Layer SqlMapClient that this template works with. |
Object |
insert(String statementName,
Object parameterObject)
|
List |
queryForList(String statementName,
Object parameterObject)
|
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)
|
com.ibatis.common.util.PaginatedList |
queryForPaginatedList(String statementName,
Object parameterObject,
int pageSize)
|
void |
queryWithRowHandler(String statementName,
Object parameterObject,
com.ibatis.sqlmap.client.event.RowHandler rowHandler)
|
void |
setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
Set the iBATIS Database Layer SqlMapClient that defines the mapped statements. |
int |
update(String statementName,
Object parameterObject)
|
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. |
Methods inherited from class org.springframework.jdbc.support.JdbcAccessor |
---|
getExceptionTranslator, isLazyInit, setDatabaseProductName, setDataSource, setExceptionTranslator, setLazyInit |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SqlMapClientTemplate()
public SqlMapClientTemplate(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
sqlMapClient
- iBATIS SqlMapClient that defines the mapped statementspublic SqlMapClientTemplate(DataSource dataSource, com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
dataSource
- JDBC DataSource to obtain connections fromsqlMapClient
- iBATIS SqlMapClient that defines the mapped statementsMethod Detail |
---|
public void setSqlMapClient(com.ibatis.sqlmap.client.SqlMapClient sqlMapClient)
public com.ibatis.sqlmap.client.SqlMapClient getSqlMapClient()
public DataSource getDataSource()
getDataSource
in class JdbcAccessor
SqlMapTransactionManager.getDataSource()
public void afterPropertiesSet()
JdbcAccessor
afterPropertiesSet
in interface InitializingBean
afterPropertiesSet
in class JdbcAccessor
public Object execute(SqlMapClientCallback action) throws DataAccessException
action
- callback object that specifies the data access action
null
DataAccessException
- in case of SQL Maps errorspublic List executeWithListResult(SqlMapClientCallback action) throws DataAccessException
action
- callback object that specifies the data access action
DataAccessException
- in case of SQL Maps errorspublic Map executeWithMapResult(SqlMapClientCallback action) throws DataAccessException
action
- callback object that specifies the data access action
DataAccessException
- in case of SQL Maps errorspublic Object queryForObject(String statementName, Object parameterObject) throws DataAccessException
queryForObject
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.queryForObject(String, Object)
public Object queryForObject(String statementName, Object parameterObject, Object resultObject) throws DataAccessException
queryForObject
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.queryForObject(String, Object, Object)
public List queryForList(String statementName, Object parameterObject) throws DataAccessException
queryForList
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.queryForList(String, Object)
public List queryForList(String statementName, Object parameterObject, int skipResults, int maxResults) throws DataAccessException
queryForList
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.queryForList(String, Object, int, int)
public void queryWithRowHandler(String statementName, Object parameterObject, com.ibatis.sqlmap.client.event.RowHandler rowHandler) throws DataAccessException
queryWithRowHandler
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.queryWithRowHandler(String, Object, RowHandler)
public com.ibatis.common.util.PaginatedList queryForPaginatedList(String statementName, Object parameterObject, int pageSize) throws DataAccessException
queryForPaginatedList
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.queryForPaginatedList(String, Object, int)
public Map queryForMap(String statementName, Object parameterObject, String keyProperty) throws DataAccessException
queryForMap
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.queryForMap(String, Object, String)
public Map queryForMap(String statementName, Object parameterObject, String keyProperty, String valueProperty) throws DataAccessException
queryForMap
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.queryForMap(String, Object, String, String)
public Object insert(String statementName, Object parameterObject) throws DataAccessException
insert
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.insert(String, Object)
public int update(String statementName, Object parameterObject) throws DataAccessException
update
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.update(String, Object)
public int delete(String statementName, Object parameterObject) throws DataAccessException
delete
in interface SqlMapClientOperations
DataAccessException
- in case of errorsSqlMapExecutor.delete(String, Object)
public void update(String statementName, Object parameterObject, int requiredRowsAffected) throws DataAccessException
SqlMapClientOperations
update
in interface SqlMapClientOperations
statementName
- the name of the mapped statementparameterObject
- the parameter objectrequiredRowsAffected
- the number of rows that the update is
required to affect
DataAccessException
- in case of errorspublic void delete(String statementName, Object parameterObject, int requiredRowsAffected) throws DataAccessException
SqlMapClientOperations
delete
in interface SqlMapClientOperations
statementName
- the name of the mapped statementparameterObject
- the parameter objectrequiredRowsAffected
- the number of rows that the delete is
required to affect
DataAccessException
- in case of errors
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |