| java.lang.Object org.springframework.jdbc.support.JdbcAccessor org.springframework.orm.ibatis.SqlMapClientTemplate
SqlMapClientTemplate | public class SqlMapClientTemplate extends JdbcAccessor implements SqlMapClientOperations(Code) | | 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).
author: Juergen Hoeller since: 24.02.2004 See Also: SqlMapClientTemplate.execute See Also: SqlMapClientTemplate.setSqlMapClient See Also: SqlMapClientTemplate.setDataSource See Also: SqlMapClientTemplate.setExceptionTranslator See Also: SqlMapClientFactoryBean.setDataSource See Also: com.ibatis.sqlmap.client.SqlMapClient.getDataSource See Also: com.ibatis.sqlmap.client.SqlMapExecutor |
Method Summary | |
public void | afterPropertiesSet() | public int | delete(String statementName) | public int | delete(String statementName, Object parameterObject) | public void | delete(String statementName, Object parameterObject, int requiredRowsAffected) | public Object | execute(SqlMapClientCallback action) Execute the given data access action on a SqlMapExecutor. | public List | executeWithListResult(SqlMapClientCallback action) Execute the given data access action on a SqlMapExecutor,
expecting a List result. | public Map | executeWithMapResult(SqlMapClientCallback action) 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) | public Object | insert(String statementName, Object parameterObject) | public List | queryForList(String statementName) | public List | queryForList(String statementName, Object parameterObject) | public List | queryForList(String statementName, int skipResults, int maxResults) | public List | queryForList(String statementName, Object parameterObject, int skipResults, int maxResults) | public Map | queryForMap(String statementName, Object parameterObject, String keyProperty) | public Map | queryForMap(String statementName, Object parameterObject, String keyProperty, String valueProperty) | public Object | queryForObject(String statementName) | public Object | queryForObject(String statementName, Object parameterObject) | public Object | queryForObject(String statementName, Object parameterObject, Object resultObject) | public PaginatedList | queryForPaginatedList(String statementName, int pageSize) | public PaginatedList | queryForPaginatedList(String statementName, Object parameterObject, int pageSize) | public void | queryWithRowHandler(String statementName, RowHandler rowHandler) | public void | queryWithRowHandler(String statementName, Object parameterObject, RowHandler rowHandler) | public void | setSqlMapClient(SqlMapClient sqlMapClient) Set the iBATIS Database Layer SqlMapClient that defines the mapped statements. | public int | update(String statementName) | public int | update(String statementName, Object parameterObject) | public void | update(String statementName, Object parameterObject, int requiredRowsAffected) |
SqlMapClientTemplate | public SqlMapClientTemplate()(Code) | | Create a new SqlMapClientTemplate.
|
SqlMapClientTemplate | public SqlMapClientTemplate(SqlMapClient sqlMapClient)(Code) | | Create a new SqlMapTemplate.
Parameters: sqlMapClient - iBATIS SqlMapClient that defines the mapped statements |
SqlMapClientTemplate | public SqlMapClientTemplate(DataSource dataSource, SqlMapClient sqlMapClient)(Code) | | Create a new SqlMapTemplate.
Parameters: dataSource - JDBC DataSource to obtain connections from Parameters: sqlMapClient - iBATIS SqlMapClient that defines the mapped statements |
afterPropertiesSet | public void afterPropertiesSet()(Code) | | |
executeWithListResult | public List executeWithListResult(SqlMapClientCallback action) throws DataAccessException(Code) | | Execute the given data access action on a SqlMapExecutor,
expecting a List result.
Parameters: action - callback object that specifies the data access action the List result throws: DataAccessException - in case of SQL Maps errors |
executeWithMapResult | public Map executeWithMapResult(SqlMapClientCallback action) throws DataAccessException(Code) | | Execute the given data access action on a SqlMapExecutor,
expecting a Map result.
Parameters: action - callback object that specifies the data access action the Map result throws: DataAccessException - in case of SQL Maps errors |
getDataSource | public DataSource getDataSource()(Code) | | If no DataSource specified, use SqlMapClient's DataSource.
See Also: com.ibatis.sqlmap.client.SqlMapClient.getDataSource |
getSqlMapClient | public SqlMapClient getSqlMapClient()(Code) | | Return the iBATIS Database Layer SqlMapClient that this template works with.
|
setSqlMapClient | public void setSqlMapClient(SqlMapClient sqlMapClient)(Code) | | Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.
|
Fields inherited from org.springframework.jdbc.support.JdbcAccessor | final protected Log logger(Code)(Java Doc)
|
|
|