com.ibatis.dao.client.template
Class SqlMapDaoTemplate

java.lang.Object
  extended bycom.ibatis.dao.client.template.DaoTemplate
      extended bycom.ibatis.dao.client.template.SqlMapDaoTemplate
All Implemented Interfaces:
Dao, SqlMapExecutor

public abstract class SqlMapDaoTemplate
extends DaoTemplate
implements SqlMapExecutor

A DaoTemplate for SQL Map implementations that provides a convenient method to access the SqlMapExecutor. This class also provides SqlMapExecutor method wrappers that conveniently wrap SQLExceptions with DAO Exceptions.

Author:
Zach Scott

Field Summary
 
Fields inherited from class com.ibatis.dao.client.template.DaoTemplate
daoManager
 
Constructor Summary
SqlMapDaoTemplate(DaoManager daoManager)
          The DaoManager that manages this Dao instance will be passed in as the parameter to this constructor automatically upon instantiation.
 
Method Summary
 int delete(java.lang.String id)
          Executes a mapped SQL DELETE statement.
 int delete(java.lang.String id, java.lang.Object parameterObject)
          Executes a mapped SQL DELETE statement.
 int executeBatch()
          Executes (flushes) all statements currently batched.
 java.util.List executeBatchDetailed()
          Executes (flushes) all statements currently batched.
protected  SqlMapExecutor getSqlMapExecutor()
          Gets the SQL Map Executor associated with the current DaoTransaction that this Dao is working under.
protected  SqlMapTransactionManager getSqlMapTransactionManager()
          Gets the SQL Map Transaction Manager associated with the current DaoTransaction that this Dao is working under.
 java.lang.Object insert(java.lang.String id)
          Executes a mapped SQL INSERT statement.
 java.lang.Object insert(java.lang.String id, java.lang.Object parameterObject)
          Executes a mapped SQL INSERT statement.
 java.util.List queryForList(java.lang.String id)
          Executes a mapped SQL SELECT statement that returns data to populate a number of result objects.
 java.util.List queryForList(java.lang.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.
 java.util.List queryForList(java.lang.String id, java.lang.Object parameterObject)
          Executes a mapped SQL SELECT statement that returns data to populate a number of result objects.
 java.util.List queryForList(java.lang.String id, java.lang.Object parameterObject, int skip, int max)
          Executes a mapped SQL SELECT statement that returns data to populate a number of result objects within a certain range.
 java.util.Map queryForMap(java.lang.String id, java.lang.Object parameterObject, java.lang.String keyProp)
          Executes a mapped SQL SELECT statement that returns data to populate a number of result objects that will be keyed into a Map.
 java.util.Map queryForMap(java.lang.String id, java.lang.Object parameterObject, java.lang.String keyProp, java.lang.String valueProp)
          Executes a mapped SQL SELECT statement that returns data to populate a number of result objects from which one property will be keyed into a Map.
 java.lang.Object queryForObject(java.lang.String id)
          Executes a mapped SQL SELECT statement that returns data to populate a single object instance.
 java.lang.Object queryForObject(java.lang.String id, java.lang.Object parameterObject)
          Executes a mapped SQL SELECT statement that returns data to populate a single object instance.
 java.lang.Object queryForObject(java.lang.String id, java.lang.Object parameterObject, java.lang.Object resultObject)
          Executes a mapped SQL SELECT statement that returns data to populate the supplied result object.
 PaginatedList queryForPaginatedList(java.lang.String id, int pageSize)
          Executes a mapped SQL SELECT statement that returns data to populate a number of result objects a page at a time.
 PaginatedList queryForPaginatedList(java.lang.String id, java.lang.Object parameterObject, int pageSize)
          Executes a mapped SQL SELECT statement that returns data to populate a number of result objects a page at a time.
 void queryWithRowHandler(java.lang.String id, java.lang.Object parameterObject, RowHandler rowHandler)
          Executes a mapped SQL SELECT statement that returns data to populate a number of result objects that will be handled one at a time by a RowHandler.
 void queryWithRowHandler(java.lang.String id, RowHandler rowHandler)
          Executes a mapped SQL SELECT statement that returns data to populate a number of result objects that will be handled one at a time by a RowHandler.
 void startBatch()
          Starts a batch in which update statements will be cached before being sent to the database all at once.
 int update(java.lang.String id)
          Executes a mapped SQL UPDATE statement.
 int update(java.lang.String id, java.lang.Object parameterObject)
          Executes a mapped SQL UPDATE statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlMapDaoTemplate

public SqlMapDaoTemplate(DaoManager daoManager)
The DaoManager that manages this Dao instance will be passed in as the parameter to this constructor automatically upon instantiation.

Parameters:
daoManager -
Method Detail

getSqlMapExecutor

protected SqlMapExecutor getSqlMapExecutor()
Gets the SQL Map Executor associated with the current DaoTransaction that this Dao is working under. The SqlMapExecutor interface declares a number of methods for executing statements via an SqlMapClient instance.

Returns:
A SqlMapExecutor instance.

getSqlMapTransactionManager

protected SqlMapTransactionManager getSqlMapTransactionManager()
Gets the SQL Map Transaction Manager associated with the current DaoTransaction that this Dao is working under. The SqlMapExecutor interface declares a number of methods for executing statements via an SqlMapClient instance.

NOTE: It is rare to require this in a DAO. Only very special cases of DAO implementations will require access to the SqlMapTransactionManager. Messing with transactions at this level might be dangerous to your data integrity (e.g. committing too early).

Returns:
A SqlMapTransactionManager instance.

insert

public java.lang.Object insert(java.lang.String id,
                               java.lang.Object parameterObject)
Executes a mapped SQL INSERT statement. Insert is a bit different from other update methods, as it provides facilities for returning the primary key of the newly inserted row (rather than the effected rows). This functionality is of course optional.

The parameter object is generally used to supply the input data for the INSERT values.

Specified by:
insert in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
Returns:
The primary key of the newly inserted row. This might be automatically generated by the RDBMS, or selected from a sequence table or other source.

insert

public java.lang.Object insert(java.lang.String id)
Executes a mapped SQL INSERT statement. Insert is a bit different from other update methods, as it provides facilities for returning the primary key of the newly inserted row (rather than the effected rows). This functionality is of course optional.

This overload assumes no parameter is needed.

Specified by:
insert in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
Returns:
The primary key of the newly inserted row. This might be automatically generated by the RDBMS, or selected from a sequence table or other source.

update

public int update(java.lang.String id,
                  java.lang.Object parameterObject)
Executes a mapped SQL UPDATE statement. Update can also be used for any other update statement type, such as inserts and deletes. Update returns the number of rows effected.

The parameter object is generally used to supply the input data for the UPDATE values as well as the WHERE clause parameter(s).

Specified by:
update in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
Returns:
The number of rows effected.

update

public int update(java.lang.String id)
Executes a mapped SQL UPDATE statement. Update can also be used for any other update statement type, such as inserts and deletes. Update returns the number of rows effected.

This overload assumes no parameter is needed.

Specified by:
update in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
Returns:
The number of rows effected.

delete

public int delete(java.lang.String id,
                  java.lang.Object parameterObject)
Executes a mapped SQL DELETE statement. Delete returns the number of rows effected.

The parameter object is generally used to supply the input data for the WHERE clause parameter(s) of the DELETE statement.

Specified by:
delete in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
Returns:
The number of rows effected.

delete

public int delete(java.lang.String id)
Executes a mapped SQL DELETE statement. Delete returns the number of rows effected.

This overload assumes no parameter is needed.

Specified by:
delete in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
Returns:
The number of rows effected.

queryForObject

public java.lang.Object queryForObject(java.lang.String id,
                                       java.lang.Object parameterObject)
Executes a mapped SQL SELECT statement that returns data to populate a single object instance.

The parameter object is generally used to supply the input data for the WHERE clause parameter(s) of the SELECT statement.

Specified by:
queryForObject in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
Returns:
The single result object populated with the result set data.

queryForObject

public java.lang.Object queryForObject(java.lang.String id)
Executes a mapped SQL SELECT statement that returns data to populate a single object instance.

This overload assumes no parameter is needed.

Specified by:
queryForObject in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
Returns:
The single result object populated with the result set data.

queryForObject

public java.lang.Object queryForObject(java.lang.String id,
                                       java.lang.Object parameterObject,
                                       java.lang.Object resultObject)
Executes a mapped SQL SELECT statement that returns data to populate the supplied result object.

The parameter object is generally used to supply the input data for the WHERE clause parameter(s) of the SELECT statement.

Specified by:
queryForObject in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
resultObject - The result object instance that should be populated with result data.
Returns:
The single result object as supplied by the resultObject parameter, populated with the result set data.

queryForList

public java.util.List queryForList(java.lang.String id,
                                   java.lang.Object parameterObject)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects.

The parameter object is generally used to supply the input data for the WHERE clause parameter(s) of the SELECT statement.

Specified by:
queryForList in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
Returns:
A List of result objects.

queryForList

public java.util.List queryForList(java.lang.String id)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects.

This overload assumes no parameter is needed.

Specified by:
queryForList in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
Returns:
A List of result objects.

queryForList

public java.util.List queryForList(java.lang.String id,
                                   java.lang.Object parameterObject,
                                   int skip,
                                   int max)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects within a certain range.

The parameter object is generally used to supply the input data for the WHERE clause parameter(s) of the SELECT statement.

Specified by:
queryForList in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
skip - The number of results to ignore.
max - The maximum number of results to return.
Returns:
A List of result objects.

queryForList

public java.util.List queryForList(java.lang.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.

This overload assumes no parameter is needed.

Specified by:
queryForList in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
skip - The number of results to ignore.
max - The maximum number of results to return.
Returns:
A List of result objects.

queryWithRowHandler

public void queryWithRowHandler(java.lang.String id,
                                java.lang.Object parameterObject,
                                RowHandler rowHandler)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects that will be handled one at a time by a RowHandler.

This is generally a good approach to take when dealing with large sets of records (i.e. hundreds, thousands...) that need to be processed without eating up all of the system resources.

The parameter object is generally used to supply the input data for the WHERE clause parameter(s) of the SELECT statement.

Specified by:
queryWithRowHandler in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
rowHandler - A RowHandler instance

queryWithRowHandler

public void queryWithRowHandler(java.lang.String id,
                                RowHandler rowHandler)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects that will be handled one at a time by a RowHandler.

This is generally a good approach to take when dealing with large sets of records (i.e. hundreds, thousands...) that need to be processed without eating up all of the system resources.

This overload assumes no parameter is needed.

Specified by:
queryWithRowHandler in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
rowHandler - A RowHandler instance

queryForPaginatedList

public PaginatedList queryForPaginatedList(java.lang.String id,
                                           java.lang.Object parameterObject,
                                           int pageSize)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects a page at a time.

The parameter object is generally used to supply the input data for the WHERE clause parameter(s) of the SELECT statement.

Specified by:
queryForPaginatedList in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
pageSize - The maximum number of result objects each page can hold.
Returns:
A PaginatedList of result objects.

queryForPaginatedList

public PaginatedList queryForPaginatedList(java.lang.String id,
                                           int pageSize)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects a page at a time.

This overload assumes no parameter is needed.

Specified by:
queryForPaginatedList in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
pageSize - The maximum number of result objects each page can hold.
Returns:
A PaginatedList of result objects.

queryForMap

public java.util.Map queryForMap(java.lang.String id,
                                 java.lang.Object parameterObject,
                                 java.lang.String keyProp)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects that will be keyed into a Map.

The parameter object is generally used to supply the input data for the WHERE clause parameter(s) of the SELECT statement.

Specified by:
queryForMap in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
keyProp - The property to be used as the key in the Map.
Returns:
A Map keyed by keyProp with values being the result object instance.

queryForMap

public java.util.Map queryForMap(java.lang.String id,
                                 java.lang.Object parameterObject,
                                 java.lang.String keyProp,
                                 java.lang.String valueProp)
Executes a mapped SQL SELECT statement that returns data to populate a number of result objects from which one property will be keyed into a Map.

The parameter object is generally used to supply the input data for the WHERE clause parameter(s) of the SELECT statement.

Specified by:
queryForMap in interface SqlMapExecutor
Parameters:
id - The name of the statement to execute.
parameterObject - The parameter object (e.g. JavaBean, Map, XML etc.).
keyProp - The property to be used as the key in the Map.
valueProp - The property to be used as the value in the Map.
Returns:
A Map keyed by keyProp with values of valueProp.

startBatch

public void startBatch()
Starts a batch in which update statements will be cached before being sent to the database all at once. This can improve overall performance of updates update when dealing with numerous updates (e.g. inserting 1:M related data).

Specified by:
startBatch in interface SqlMapExecutor

executeBatch

public int executeBatch()
Executes (flushes) all statements currently batched.

Specified by:
executeBatch in interface SqlMapExecutor
Returns:
the number of rows updated in the batch

executeBatchDetailed

public java.util.List executeBatchDetailed()
Executes (flushes) all statements currently batched.

Specified by:
executeBatchDetailed in interface SqlMapExecutor
Returns:
a List of BatchResult objects. There will be one element in the list for each sub-batch executed. A sub-batch is created by adding a statement to the batch that does not equal the prior statement.
See Also:
BatchException