toolbox.dao
Class DaoWorkerImpl

Package class diagram package DaoWorkerImpl
java.lang.Object
  extended by toolbox.dao.DaoWorkerImpl
All Implemented Interfaces:
DaoWorker

public class DaoWorkerImpl
extends java.lang.Object
implements DaoWorker

Default implementation of the DaoWorker interface. Provides implementation for all methods of the interface.


Constructor Summary
DaoWorkerImpl()
          Default constructor
 
Method Summary
 void destroy()
          Destroy this worker
 java.util.List executeCallForList(java.lang.String call, java.lang.Object[] params)
          Execute a stored procedure that will return a List of results
 java.lang.Object[] executeCallForOutput(java.lang.String call, java.lang.Object[] params, java.lang.Object[] outParams, int paramOffSet)
          Execute a stored procedure that will return an array of registered output parameters.
 java.lang.Object executeCallForStatus(java.lang.String call, java.lang.Object[] params)
          Execute a stored procedure that will return exit status of the procedure.
 java.util.List getAllEntries(java.lang.String tableName)
          Return all entries from the named table.
 java.util.List getAllEntries(java.lang.String tableName, java.lang.Class returnType)
          Return all entries from the named table.
 java.util.List getCustomEntries(java.lang.String query, java.lang.Object[] params)
          Executes a custom select statement.
 java.util.List getCustomEntries(java.lang.String query, java.lang.Object[] params, java.lang.Class returnType)
          Executes a custom select statement.
 java.util.List getCustomEntries(java.lang.String query, java.lang.Object[] params, java.lang.Class returnType, int max)
          Executes a custom select statement.
 java.util.List getCustomEntries(java.lang.String query, java.lang.Object[] params, int max)
          Executes a custom select statement.
 java.util.Map getEntryByPrimaryKey(java.lang.String tableName, java.util.Map pkValue)
          Returns an entry from the named table by its primary key.
 java.lang.Object getEntryByPrimaryKey(java.lang.String tableName, java.util.Map pkValue, java.lang.Class returnType)
          Returns an entry from the named table by its primary key.
 java.util.Map getEntryByPrimaryKey(java.lang.String tableName, java.lang.Object pkValue)
          Returns an entry from the named table by its primary key.
 java.lang.Object getEntryByPrimaryKey(java.lang.String tableName, java.lang.Object pkValue, java.lang.Class returnType)
          Returns an entry from the named table by its primary key.
 void init(java.util.Map stmnts, java.util.Map tableDefs, DaoManager manager)
          Initialise the worker with required data dictionary information.
 int insert(java.lang.String tableName, java.util.Map values)
          Inserts the given map of values into the named table.
 int insert(java.lang.String tableName, java.util.Map values, TransactionContext tc)
          Inserts the given map of values into the named table within the given transaction context.
 java.lang.Object insertAndReturnKey(java.lang.String tableName, java.util.Map values)
          Inserts the given Object map of values into the named table and returns an auto-generated key.
 java.lang.Object insertAndReturnKey(java.lang.String tableName, java.util.Map values, TransactionContext tc)
          Inserts the given Object map of values into the named table and returns an auto-generated key within the given transaction context.
 int removeCustomEntries(java.lang.String delete, java.lang.Object[] params)
          Executes a custom delete statement.
 int removeCustomEntries(java.lang.String delete, java.lang.Object[] params, TransactionContext tc)
          Executes a custom delete statement within the given transaction context.
 int removeEntryByPrimaryKey(java.lang.String tableName, java.util.Map pkValue)
          Removes an entry from the named table using the given primary key value.
 int removeEntryByPrimaryKey(java.lang.String tableName, java.util.Map pkValue, TransactionContext tc)
          Removes an entry from the named table using the given primary key value within the given transaction context.
 int removeEntryByPrimaryKey(java.lang.String tableName, java.lang.Object pkValue)
          Removes an entry from the named table using the given primary key value.
 int removeEntryByPrimaryKey(java.lang.String tableName, java.lang.Object pkValue, TransactionContext tc)
          Removes an entry from the named table using the given primary key value within the given transaction context.
 int update(java.lang.String tableName, java.util.Map values)
          Update the named table with the given map of values.
 int update(java.lang.String tableName, java.util.Map values, TransactionContext tc)
          Update the named table with the given map of values within the given transaction context.
 int updateCustomEntries(java.lang.String update, java.lang.Object[] params)
          Executes a custom update statement.
 int updateCustomEntries(java.lang.String update, java.lang.Object[] params, TransactionContext tc)
          Executes a custom update statement within the given transaction context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DaoWorkerImpl

public DaoWorkerImpl()
Default constructor

Method Detail

init

public void init(java.util.Map stmnts,
                 java.util.Map tableDefs,
                 DaoManager manager)
Initialise the worker with required data dictionary information.

Specified by:
init in interface DaoWorker
Parameters:
stmnts - Map containing generated statements.
tableDefs - Map containing TableDefinitions.
manager - DaoManager that created this worker.

insert

public int insert(java.lang.String tableName,
                  java.util.Map values)
           throws DaoException
Inserts the given map of values into the named table.

Specified by:
insert in interface DaoWorker
Parameters:
tableName - Name of table to insert values into. Must be defined in the XML configuration.
values - Map containig values to insert into the named table.
Returns:
Return insert count as an int.
Throws:
DaoException - if a database access exception occurs.

insert

public int insert(java.lang.String tableName,
                  java.util.Map values,
                  TransactionContext tc)
           throws DaoException
Inserts the given map of values into the named table within the given transaction context.

Specified by:
insert in interface DaoWorker
Parameters:
tableName - Name of table to insert values into. Must be defined in the XML configuration.
values - Map containig values to insert into the named table.
tc - Current transaction context.
Returns:
Return insert count as an int.
Throws:
DaoException - if a database access exception occurs.

insertAndReturnKey

public java.lang.Object insertAndReturnKey(java.lang.String tableName,
                                           java.util.Map values)
                                    throws DaoException
Inserts the given Object map of values into the named table and returns an auto-generated key.

Specified by:
insertAndReturnKey in interface DaoWorker
Parameters:
tableName - Name of table to insert values into. Must be defined in the XML configuration.
values - Map containig values to insert into the named table.
Returns:
Object containing an auto-generated key.
Throws:
DaoException - if a database access exception occurs.

insertAndReturnKey

public java.lang.Object insertAndReturnKey(java.lang.String tableName,
                                           java.util.Map values,
                                           TransactionContext tc)
                                    throws DaoException
Inserts the given Object map of values into the named table and returns an auto-generated key within the given transaction context.

Specified by:
insertAndReturnKey in interface DaoWorker
Parameters:
tableName - Name of table to insert values into. Must be defined in the XML configuration.
values - Map containig values to insert into the named table.
tc - Current transaction context.
Returns:
Object containing an auto-generated key.
Throws:
DaoException - if a database access exception occurs.

update

public int update(java.lang.String tableName,
                  java.util.Map values)
           throws DaoException
Update the named table with the given map of values.

Specified by:
update in interface DaoWorker
Parameters:
tableName - Name of table to insert values into. Must be defined in the XML configuration.
values - Map containing update values.
Returns:
Return the update count as an int.
Throws:
DaoException - if a database access exception occurs.

update

public int update(java.lang.String tableName,
                  java.util.Map values,
                  TransactionContext tc)
           throws DaoException
Update the named table with the given map of values within the given transaction context.

Specified by:
update in interface DaoWorker
Parameters:
tableName - Name of table to insert values into. Must be defined in the XML configuration.
values - Map containing update values.
tc - Current transaction context.
Returns:
Return the update count as an int.
Throws:
DaoException - if a database access exception occurs.

getEntryByPrimaryKey

public java.util.Map getEntryByPrimaryKey(java.lang.String tableName,
                                          java.util.Map pkValue)
                                   throws DaoException
Returns an entry from the named table by its primary key.

Specified by:
getEntryByPrimaryKey in interface DaoWorker
Parameters:
tableName - Name of table that contains target entry
pkValue - Map containing primary key value.
Returns:
Map containing target entry or null if the entry does not exist.
Throws:
DaoException - if an exception occurs while accessing the database

getEntryByPrimaryKey

public java.lang.Object getEntryByPrimaryKey(java.lang.String tableName,
                                             java.util.Map pkValue,
                                             java.lang.Class returnType)
                                      throws DaoException
Returns an entry from the named table by its primary key.

The returned entry will be wrapped in the specified return type.

Specified by:
getEntryByPrimaryKey in interface DaoWorker
Parameters:
tableName - Name of table that contains target entry
pkValue - Map containing primary key value.
returnType - Class denoting the return type.
Returns:
Object containing target entry or null if the entry does not exist.
Throws:
DaoException - if an exception occurs while accessing the database

getEntryByPrimaryKey

public java.util.Map getEntryByPrimaryKey(java.lang.String tableName,
                                          java.lang.Object pkValue)
                                   throws DaoException
Returns an entry from the named table by its primary key.

Specified by:
getEntryByPrimaryKey in interface DaoWorker
Parameters:
tableName - Name of table that contains target entry
pkValue - Object containing primary key value.
Returns:
Map containing target entry or null if the entry does not exist.
Throws:
DaoException - if an exception occurs while accessing the database

getEntryByPrimaryKey

public java.lang.Object getEntryByPrimaryKey(java.lang.String tableName,
                                             java.lang.Object pkValue,
                                             java.lang.Class returnType)
                                      throws DaoException
Returns an entry from the named table by its primary key.

The returned entry will be wrapped in the specified return type.

Specified by:
getEntryByPrimaryKey in interface DaoWorker
Parameters:
tableName - Name of table that contains target entry
pkValue - Object containing primary key value.
returnType - Class denoting the return type.
Returns:
Object containing target entry or null if the entry does not exist.
Throws:
DaoException - if an exception occurs while accessing the database

removeEntryByPrimaryKey

public int removeEntryByPrimaryKey(java.lang.String tableName,
                                   java.lang.Object pkValue)
                            throws DaoException
Removes an entry from the named table using the given primary key value.

Specified by:
removeEntryByPrimaryKey in interface DaoWorker
Parameters:
tableName - Name of table that contains target entry.
pkValue - Object containing primary key value.
Returns:
Return delete count as an int.
Throws:
DaoException - if an exception occurs while accessing the database

removeEntryByPrimaryKey

public int removeEntryByPrimaryKey(java.lang.String tableName,
                                   java.lang.Object pkValue,
                                   TransactionContext tc)
                            throws DaoException
Removes an entry from the named table using the given primary key value within the given transaction context.

Specified by:
removeEntryByPrimaryKey in interface DaoWorker
Parameters:
tableName - Name of table that contains target entry.
pkValue - Object containing primary key value.
tc - Current transaction context.
Returns:
Return the delete count as an int.
Throws:
DaoException - if an exception occurs while accessing the database

removeEntryByPrimaryKey

public int removeEntryByPrimaryKey(java.lang.String tableName,
                                   java.util.Map pkValue)
                            throws DaoException
Removes an entry from the named table using the given primary key value.

Specified by:
removeEntryByPrimaryKey in interface DaoWorker
Parameters:
tableName - Name of table that contains target entry.
pkValue - Map containing primary key value.
Returns:
Return the delete count as an int.
Throws:
DaoException - if an exception occurs while accessing the database

removeEntryByPrimaryKey

public int removeEntryByPrimaryKey(java.lang.String tableName,
                                   java.util.Map pkValue,
                                   TransactionContext tc)
                            throws DaoException
Removes an entry from the named table using the given primary key value within the given transaction context.

Specified by:
removeEntryByPrimaryKey in interface DaoWorker
Parameters:
tableName - Name of table that contains target entry.
pkValue - Map containing primary key value.
tc - Current transaction context.
Returns:
Return the delete count as an int.
Throws:
DaoException - if an exception occurs while accessing the database

getAllEntries

public java.util.List getAllEntries(java.lang.String tableName)
                             throws DaoException
Return all entries from the named table.

Specified by:
getAllEntries in interface DaoWorker
Parameters:
tableName - Name of table.
Returns:
List containing all entries.
Throws:
DaoException - if an exception occurs while accessing the database

getAllEntries

public java.util.List getAllEntries(java.lang.String tableName,
                                    java.lang.Class returnType)
                             throws DaoException
Return all entries from the named table.

The returned entry will be wrapped in the specified return type.

Specified by:
getAllEntries in interface DaoWorker
Parameters:
tableName - Name of table.
returnType - Class denoting the return type.
Returns:
List containing all entries.
Throws:
DaoException - if an exception occurs while accessing the database

executeCallForStatus

public java.lang.Object executeCallForStatus(java.lang.String call,
                                             java.lang.Object[] params)
                                      throws DaoException
Execute a stored procedure that will return exit status of the procedure.

Specified by:
executeCallForStatus in interface DaoWorker
Parameters:
call - String containing procedure call.
params - Object array containing procedure parameters
Returns:
Object containing the output value.
Throws:
DaoException - if an exception occurs while executing the procedure.

executeCallForOutput

public java.lang.Object[] executeCallForOutput(java.lang.String call,
                                               java.lang.Object[] params,
                                               java.lang.Object[] outParams,
                                               int paramOffSet)
                                        throws DaoException
Execute a stored procedure that will return an array of registered output parameters.

Specified by:
executeCallForOutput in interface DaoWorker
Parameters:
call - String containing procedure call.
params - Object array containing procedure parameters.
outParams - Object array containing output parameters.
paramOffSet - The offset where the output parameters start.
Returns:
Object arrat containing the output parameter values.
Throws:
DaoException - if an exception occurs while executing the procedure.

executeCallForList

public java.util.List executeCallForList(java.lang.String call,
                                         java.lang.Object[] params)
                                  throws DaoException
Execute a stored procedure that will return a List of results

Specified by:
executeCallForList in interface DaoWorker
Parameters:
call - String containing procedure call.
params - Object array containing procedure parameters
Returns:
List containing results
Throws:
DaoException - if an exception occurs while executing the procedure.

getCustomEntries

public java.util.List getCustomEntries(java.lang.String query,
                                       java.lang.Object[] params,
                                       int max)
                                throws DaoException
Executes a custom select statement.

Specified by:
getCustomEntries in interface DaoWorker
Parameters:
query - Custom query to execute.
params - Parameters for query.
max - Maximum number of entries that may be returned. The value 0 indicates no limit.
Returns:
List containing query results.
Throws:
DaoException - if the custom query cannot be executed.

getCustomEntries

public java.util.List getCustomEntries(java.lang.String query,
                                       java.lang.Object[] params,
                                       java.lang.Class returnType,
                                       int max)
                                throws DaoException
Executes a custom select statement.

The returned entries will be wrapped in the specified return type.

Specified by:
getCustomEntries in interface DaoWorker
Parameters:
query - Custom query to execute.
params - Parameters for query.
returnType - Class denoting the return type.
max - Maximum number of entries that may be returned. The value 0 indicates no limit.
Returns:
List containing query results.
Throws:
DaoException - if the custom query cannot be executed.

getCustomEntries

public java.util.List getCustomEntries(java.lang.String query,
                                       java.lang.Object[] params)
                                throws DaoException
Executes a custom select statement.

Specified by:
getCustomEntries in interface DaoWorker
Parameters:
query - Custom query to execute.
params - Parameters for query.
Returns:
List containing query results.
Throws:
DaoException - if the custom query cannot be executed.

getCustomEntries

public java.util.List getCustomEntries(java.lang.String query,
                                       java.lang.Object[] params,
                                       java.lang.Class returnType)
                                throws DaoException
Executes a custom select statement.

The returned entries will be wrapped in the specified return type.

Specified by:
getCustomEntries in interface DaoWorker
Parameters:
query - Custom query to execute.
params - Parameters for query.
returnType - Class denoting the return type.
Returns:
List containing query results.
Throws:
DaoException - if the custom query cannot be executed.

updateCustomEntries

public int updateCustomEntries(java.lang.String update,
                               java.lang.Object[] params)
                        throws DaoException
Executes a custom update statement.

Specified by:
updateCustomEntries in interface DaoWorker
Parameters:
update - Custom update statement.
params - Parameters for update.
Returns:
Return the update count as an int.
Throws:
DaoException - if update cannot be executed.

updateCustomEntries

public int updateCustomEntries(java.lang.String update,
                               java.lang.Object[] params,
                               TransactionContext tc)
                        throws DaoException
Executes a custom update statement within the given transaction context.

Specified by:
updateCustomEntries in interface DaoWorker
Parameters:
update - Custom update statement.
params - Parameters for update.
tc - Current transaction context.
Returns:
Return the update count as an int.
Throws:
DaoException - if update cannot be executed.

removeCustomEntries

public int removeCustomEntries(java.lang.String delete,
                               java.lang.Object[] params)
                        throws DaoException
Executes a custom delete statement.

Specified by:
removeCustomEntries in interface DaoWorker
Parameters:
delete - Custom delete statement.
params - Parameters for delete statement.
Returns:
Return the delete count as an int.
Throws:
DaoException - if delete cannot be executed.

removeCustomEntries

public int removeCustomEntries(java.lang.String delete,
                               java.lang.Object[] params,
                               TransactionContext tc)
                        throws DaoException
Executes a custom delete statement within the given transaction context.

Specified by:
removeCustomEntries in interface DaoWorker
Parameters:
delete - Custom delete statement.
params - Parameters for delete statement.
tc - Current transaction context.
Returns:
Return the delete count as an int.
Throws:
DaoException - if delete cannot be executed.

destroy

public void destroy()
Destroy this worker

Specified by:
destroy in interface DaoWorker