public class SqlMapClientTemplate extends org.springframework.jdbc.support.JdbcAccessor implements SqlMapClientOperations
SqlMapClient API, converting
checked SQLExceptions into unchecked DataAccessExceptions, following the org.springframework.dao
exception hierarchy. Uses the same 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 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).| Constructor and Description |
|---|
SqlMapClientTemplate()
Create a new SqlMapClientTemplate.
|
SqlMapClientTemplate(DataSource dataSource,
SqlMapClient sqlMapClient)
Create a new SqlMapTemplate.
|
SqlMapClientTemplate(SqlMapClient sqlMapClient)
Create a new SqlMapTemplate.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
int |
delete(String id) |
int |
delete(String id,
Object parameterObject) |
void |
delete(String id,
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.
|
int |
deleteArgs(String id,
Object... args)
Do delete operation by var-args paramenters as #1# to #n#
|
<E,K> int |
deleteEntity(Class<E> cls,
K key)
Update an entity object by its key.
|
<T> T |
execute(SqlMapClientCallback<T> action)
Execute the given data access action on a SqlMapExecutor.
|
<T> int |
executeDelete(CriteriaDelete<T> deleteQuery)
Delete entities by the CriteriaUpdate object.
|
<T> List<T> |
executeQuery(CriteriaQuery<T> criteriaQuery)
Query the object list by the CriteriaQuery object.
|
<T> List<T> |
executeQuery(CriteriaQuery<T> criteriaQuery,
int startPosition,
int maxResult)
Query the object list by the CriteriaQuery object.
|
<T> T |
executeQueryObject(CriteriaQuery<T> criteriaQuery)
Query the first object by the CriteriaQuery object.
|
<T> int |
executeQueryPage(CriteriaQuery<T> criteriaQuery,
List<T> page,
int startPosition,
int maxResult)
Query the object list by the CriteriaQuery object and fill into page
|
<T> int |
executeUpdate(CriteriaUpdate<T> updateQuery)
Update entities by the CriteriaUpdate object.
|
<E,K> E |
findEntity(Class<E> cls,
K key)
Find an entity object by its key.
|
CriteriaBuilder |
getCriteriaBuilder()
Return an instance of
CriteriaBuilder for the creation of CriteriaQuery,
CriteriaUpdateor CriteriaDelete objects. |
DataSource |
getDataSource()
If no DataSource specified, use SqlMapClient's DataSource.
|
Dialect |
getDialect()
Get the dialect of the iBatis instance.
|
String |
getGlobalProperty(String name)
Get the property from iBatis.
|
SqlMapClient |
getSqlMapClient()
Return the iBATIS Database Layer SqlMapClient that this template works with.
|
<T> T |
insert(String id) |
<T> T |
insert(String id,
Object parameterObject) |
<T> T |
insertArgs(String id,
Object... args)
Do insert operation by var-args paramenters as #1# to #n#
|
<E> E |
insertEntity(Class<E> cls,
E entity)
Insert an entity object.
|
<T> T |
queryForFirst(String id)
Do query and return first row as result object.
|
<T> T |
queryForFirst(String id,
Object parameterObject)
Do query and return first row as result object.
|
<T> T |
queryForFirstArgs(String id,
Object... args)
Do queryForFirst operation by var-args paramenters as #1# to #n#
|
<T> List<T> |
queryForList(String id) |
<T> List<T> |
queryForList(String id,
int skipResults,
int maxResults) |
<T> List<T> |
queryForList(String id,
Object parameterObject) |
<T> List<T> |
queryForList(String id,
Object parameterObject,
int skipResults,
int maxResults) |
<T> List<T> |
queryForListArgs(int skip,
int max,
String id,
Object... args)
Do queryForList operation by var-args paramenters as #1# to #n#
|
<T> List<T> |
queryForListArgs(String id,
Object... args)
Do queryForList operation by var-args paramenters as #1# to #n#
|
<K,V> Map<K,V> |
queryForMap(String id,
Object parameterObject,
String keyProperty) |
<K,V> Map<K,V> |
queryForMap(String id,
Object parameterObject,
String keyProperty,
Class<K> keyType,
String valueProperty,
Class<V> valueType) |
<K,V> Map<K,V> |
queryForMap(String id,
Object parameterObject,
String keyProperty,
String valueProperty) |
<K,V> Map<K,V> |
queryForMapArgs(String id,
String keyProp,
Class<K> keyType,
String valueProp,
Class<V> valueType,
Object... args)
Do queryForMap operation by var-args paramenters as #1# to #n#
|
<K,V> Map<K,V> |
queryForMapArgs(String id,
String keyProp,
Object... args)
Do queryForMap operation by var-args paramenters as #1# to #n#
|
<K,V> Map<K,V> |
queryForMapArgs(String id,
String keyProp,
String valueProp,
Object... args)
Do queryForMap operation by var-args paramenters as #1# to #n#
|
<T> T |
queryForObject(String id) |
<T> T |
queryForObject(String id,
Object parameterObject) |
<T> T |
queryForObject(String id,
Object parameterObject,
Object resultObject) |
<T> T |
queryForObjectArgs(String id,
Object... args)
Do queryForObject operation by var-args paramenters as #1# to #n#
|
<T> int |
queryForPage(List<T> page,
String id,
int skip,
int max)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects within a certain
range into the page argument and return the total number.
|
<T> int |
queryForPage(List<T> page,
String id,
Object paramObject,
int skip,
int max)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects within a certain
range into the page argument and return the total number.
|
<T> int |
queryForPageArgs(List<T> page,
String id,
int skip,
int max,
Object... args)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects within a certain
range into the page argument and return the total number.
|
ResultSet |
queryForResultSet(String id)
Do query and return a cached result set.
|
ResultSet |
queryForResultSet(String id,
Object parameterObject)
Do query and return a cached result set.
|
ResultSet |
queryForResultSetArgs(String id,
Object... args)
Do queryForResultSet operation by var-args paramenters as #1# to #n#
|
void |
queryWithRowHandler(String id,
Object parameterObject,
RowHandler rowHandler) |
void |
queryWithRowHandler(String id,
RowHandler rowHandler) |
void |
queryWithRowHandler(String id,
RowHandler rowHandler,
Object... args)
Do queryWithRowHandler operation by var-args paramenters as #1# to #n#
|
void |
setSqlMapClient(SqlMapClient sqlMapClient)
Set the iBATIS Database Layer SqlMapClient that defines the mapped statements.
|
int |
update(String id) |
int |
update(String id,
Object parameterObject) |
void |
update(String id,
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.
|
int |
updateArgs(String id,
Object... args)
Do update operation by var-args paramenters as #1# to #n#
|
<E,K> int |
updateEntity(Class<E> cls,
E entity)
Update an entity object.
|
public SqlMapClientTemplate()
public SqlMapClientTemplate(SqlMapClient sqlMapClient)
sqlMapClient - iBATIS SqlMapClient that defines the mapped statementspublic SqlMapClientTemplate(DataSource dataSource, SqlMapClient sqlMapClient)
dataSource - JDBC DataSource to obtain connections fromsqlMapClient - iBATIS SqlMapClient that defines the mapped statementspublic void setSqlMapClient(SqlMapClient sqlMapClient)
public SqlMapClient getSqlMapClient()
public DataSource getDataSource()
getDataSource in class org.springframework.jdbc.support.JdbcAccessorSqlMapTransactionManager.getDataSource()public void afterPropertiesSet()
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanafterPropertiesSet in class org.springframework.jdbc.support.JdbcAccessorpublic <T> T execute(SqlMapClientCallback<T> action) throws org.springframework.dao.DataAccessException
action - callback object that specifies the data access actionnullorg.springframework.dao.DataAccessException - in case of SQL Maps errorspublic <T> T queryForObject(String id) throws org.springframework.dao.DataAccessException
queryForObject in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForObject(String)public <T> T queryForObject(String id, Object parameterObject) throws org.springframework.dao.DataAccessException
queryForObject in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForObject(String, Object)public <T> T queryForObject(String id, Object parameterObject, Object resultObject) throws org.springframework.dao.DataAccessException
queryForObject in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForObject(String, Object, Object)public <T> List<T> queryForList(String id) throws org.springframework.dao.DataAccessException
queryForList in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForList(String)public <T> List<T> queryForList(String id, Object parameterObject) throws org.springframework.dao.DataAccessException
queryForList in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForList(String, Object)public <T> List<T> queryForList(String id, int skipResults, int maxResults) throws org.springframework.dao.DataAccessException
queryForList in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForList(String, int, int)public <T> List<T> queryForList(String id, Object parameterObject, int skipResults, int maxResults) throws org.springframework.dao.DataAccessException
queryForList in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForList(String, Object, int, int)public void queryWithRowHandler(String id, RowHandler rowHandler) throws org.springframework.dao.DataAccessException
queryWithRowHandler in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryWithRowHandler(String, RowHandler)public void queryWithRowHandler(String id, Object parameterObject, RowHandler rowHandler) throws org.springframework.dao.DataAccessException
queryWithRowHandler in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryWithRowHandler(String, Object, RowHandler)public void queryWithRowHandler(String id, RowHandler rowHandler, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryWithRowHandler in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.queryWithRowHandler(String, Object, RowHandler)public <K,V> Map<K,V> queryForMap(String id, Object parameterObject, String keyProperty) throws org.springframework.dao.DataAccessException
queryForMap in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForMap(String, Object, String)public <K,V> Map<K,V> queryForMap(String id, Object parameterObject, String keyProperty, String valueProperty) throws org.springframework.dao.DataAccessException
queryForMap in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForMap(String, Object, String, String)public <K,V> Map<K,V> queryForMap(String id, Object parameterObject, String keyProperty, Class<K> keyType, String valueProperty, Class<V> valueType) throws org.springframework.dao.DataAccessException
queryForMap in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.queryForMap(String, Object, String, Class, String, Class)public <T> T insert(String id) throws org.springframework.dao.DataAccessException
insert in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.insert(String)public <T> T insert(String id, Object parameterObject) throws org.springframework.dao.DataAccessException
insert in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.insert(String, Object)public int update(String id) throws org.springframework.dao.DataAccessException
update in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.update(String)public int update(String id, Object parameterObject) throws org.springframework.dao.DataAccessException
update in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.update(String, Object)public void update(String id, Object parameterObject, int requiredRowsAffected) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsupdate in interface SqlMapClientOperationsid - the name of the mapped statementparameterObject - the parameter objectrequiredRowsAffected - the number of rows that the update is required to affectorg.springframework.dao.DataAccessException - in case of errorspublic int delete(String id) throws org.springframework.dao.DataAccessException
delete in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.delete(String)public int delete(String id, Object parameterObject) throws org.springframework.dao.DataAccessException
delete in interface SqlMapClientOperationsorg.springframework.dao.DataAccessException - in case of errorsSqlMapExecutor.delete(String, Object)public void delete(String id, Object parameterObject, int requiredRowsAffected) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsdelete in interface SqlMapClientOperationsid - the name of the mapped statementparameterObject - the parameter objectrequiredRowsAffected - the number of rows that the delete is required to affectorg.springframework.dao.DataAccessException - in case of errorspublic <T> T insertArgs(String id, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsinsertArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.insert(String, Object)public int updateArgs(String id, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsupdateArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.update(String, Object)public int deleteArgs(String id, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsdeleteArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.delete(String, Object)public <T> List<T> queryForListArgs(String id, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForListArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.queryForList(String, Object)public <T> List<T> queryForListArgs(int skip, int max, String id, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForListArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.queryForList(String, Object, int, int)public <T> int queryForPage(List<T> page, String id, int skip, int max) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForPage in interface SqlMapClientOperationspage - page container, input/output parameterid - The name of the statement to execute.skip - The number of results to ignore.max - The maximum number of results to return.org.springframework.dao.DataAccessExceptionpublic <T> int queryForPage(List<T> page, String id, Object paramObject, int skip, int max) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForPage in interface SqlMapClientOperationspage - page container, input/output parameterid - The name of the statement to execute.skip - The number of results to ignore.max - The maximum number of results to return.org.springframework.dao.DataAccessExceptionpublic <T> int queryForPageArgs(List<T> page, String id, int skip, int max, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForPageArgs in interface SqlMapClientOperationspage - page container, input/output parameterid - The name of the statement to execute.skip - The number of results to ignore.max - The maximum number of results to return.args - The parameter objects #1# to #n#org.springframework.dao.DataAccessExceptionpublic <K,V> Map<K,V> queryForMapArgs(String id, String keyProp, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForMapArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.queryForMap(String, Object, String)public <K,V> Map<K,V> queryForMapArgs(String id, String keyProp, String valueProp, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForMapArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.queryForMap(String, Object, String, String)public <K,V> Map<K,V> queryForMapArgs(String id, String keyProp, Class<K> keyType, String valueProp, Class<V> valueType, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForMapArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.queryForMap(String, Object, String, Class, String, Class)public <T> T queryForObjectArgs(String id, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForObjectArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.queryForObject(String, Object)public <T> T queryForFirstArgs(String id, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForFirstArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.queryForFirst(String, Object)public <T> T queryForFirst(String id) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForFirst in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapExecutor.queryForList(String)public <T> T queryForFirst(String id, Object parameterObject) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForFirst in interface SqlMapClientOperationsparameterObject - the parameter for queryorg.springframework.dao.DataAccessExceptionSqlMapExecutor.queryForList(String, Object)public Dialect getDialect()
public <E> E insertEntity(Class<E> cls, E entity) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsinsertEntity in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionEntityManager.insertEntity(Class, Object)public <E,K> int updateEntity(Class<E> cls, E entity) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsupdateEntity in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionEntityManager.updateEntity(Class, Object)public <E,K> int deleteEntity(Class<E> cls, K key) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsdeleteEntity in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionEntityManager.deleteEntity(Class, Object)public <E,K> E findEntity(Class<E> cls, K key) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsfindEntity in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionEntityManager.findEntity(Class, Object)public <T> T executeQueryObject(CriteriaQuery<T> criteriaQuery) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsexecuteQueryObject in interface SqlMapClientOperationscriteriaQuery - the CriteriaQuery object.org.springframework.dao.DataAccessExceptionpublic <T> List<T> executeQuery(CriteriaQuery<T> criteriaQuery) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsexecuteQuery in interface SqlMapClientOperationscriteriaQuery - the CriteriaQuery object.org.springframework.dao.DataAccessExceptionpublic <T> List<T> executeQuery(CriteriaQuery<T> criteriaQuery, int startPosition, int maxResult) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsexecuteQuery in interface SqlMapClientOperationscriteriaQuery - the CriteriaQuery object.startPosition - position of the first result, numbered from 0maxResult - maximum number of results to retrieveorg.springframework.dao.DataAccessExceptionpublic <T> int executeQueryPage(CriteriaQuery<T> criteriaQuery, List<T> page, int startPosition, int maxResult) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsexecuteQueryPage in interface SqlMapClientOperationscriteriaQuery - the CriteriaQuery object.page - the page containerstartPosition - position of the first result, numbered from 0maxResult - maximum number of results to retrieveorg.springframework.dao.DataAccessExceptionpublic <T> int executeUpdate(CriteriaUpdate<T> updateQuery) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsexecuteUpdate in interface SqlMapClientOperationsupdateQuery - the CriteriaUpdate object.org.springframework.dao.DataAccessExceptionpublic <T> int executeDelete(CriteriaDelete<T> deleteQuery) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsexecuteDelete in interface SqlMapClientOperationsdeleteQuery - the CriteriaDelete object.org.springframework.dao.DataAccessExceptionpublic CriteriaBuilder getCriteriaBuilder() throws org.springframework.dao.DataAccessException
SqlMapClientOperationsCriteriaBuilder for the creation of CriteriaQuery,
CriteriaUpdateor CriteriaDelete objects.getCriteriaBuilder in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionpublic ResultSet queryForResultSetArgs(String id, Object... args) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForResultSetArgs in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionSqlMapClientOperations.queryForResultSet(String, Object)public ResultSet queryForResultSet(String id) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForResultSet in interface SqlMapClientOperationsorg.springframework.dao.DataAccessExceptionRowSetpublic ResultSet queryForResultSet(String id, Object parameterObject) throws org.springframework.dao.DataAccessException
SqlMapClientOperationsqueryForResultSet in interface SqlMapClientOperationsparameterObject - the parameter for queryorg.springframework.dao.DataAccessExceptionRowSetpublic String getGlobalProperty(String name)
PropertyProvidergetGlobalProperty in interface PropertyProviderCopyright © 2084–2018 dukeware.com. All rights reserved.