toolbox.services.dao
Class DaoService

Package class diagram package DaoService
java.lang.Object
  extended by toolbox.services.BaseService
      extended by toolbox.services.dao.DaoService
All Implemented Interfaces:
Service
Direct Known Subclasses:
AuditServiceDbImpl, LoggingServiceDbImpl, ORMQueryServiceImpl

public class DaoService
extends BaseService

Convenience service implementation that can be used to develop services that require interaction with a RDBMS using the toolbox.dao package.


Constructor Summary
protected DaoService()
          Default constructor.
 
Method Summary
protected  boolean checkConstraint(java.lang.String query, java.lang.Object[] params)
          Convenience method to check a single foreign key constraint.
 void create(java.lang.String name, java.lang.String confHome, ServiceEnvironment env, XMLProperties xmlProps)
          Create the service by obtaining a refrence to the DaoManager in the provided environment.
 void destroy()
          Destroy this service by destroying worker instance.
protected  java.util.List doCustomQuery(Query query)
          Convenience method to execute the given query.
protected  java.util.List doCustomQuery(java.lang.String query)
          Convenience method to execute a query without parameters.
protected  DaoManager getDaoManager()
          Returns the DaoManager for this service.
protected  DaoWorker getDaoWorker()
          Returns the DaoWorker for this service.
protected  java.lang.Integer getNextSequenceValue(java.lang.String seq)
          Return the next value from the named oracle sequence.
protected  int insertDaoBean(java.lang.String table, DaoBean bean)
          Convenience method to insert the properties of the given DaoBean into the named table.
protected  int insertDaoBean(java.lang.String table, DaoBean bean, TransactionContext tc)
          Convenience method to insert the properties of the given DaoBean into the named table within the given transaction context.
protected  int updateDaoBean(java.lang.String table, DaoBean bean)
          Convenience method to update the properties of the given DaoBean in the named table.
protected  int updateDaoBean(java.lang.String table, DaoBean bean, TransactionContext tc)
          Convenience method to update the properties of the given DaoBean in the named table within the given TransactionContext.
 
Methods inherited from class toolbox.services.BaseService
getConfigHome, getName, getProperties, getProperty, getXMLProperties, logConfig, logFine, logFiner, logFinest, logInfo, logSevere, logWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DaoService

protected DaoService()
Default constructor.

Method Detail

create

public void create(java.lang.String name,
                   java.lang.String confHome,
                   ServiceEnvironment env,
                   XMLProperties xmlProps)
            throws ServiceException
Create the service by obtaining a refrence to the DaoManager in the provided environment.

Specified by:
create in interface Service
Overrides:
create in class BaseService
Parameters:
name - The name of this service.
confHome - The path to the configuration home directory.
env - The service environment for this service.
xmlProps - XML configuration properties.
Throws:
ServiceException - if this service cannot be created.

getDaoWorker

protected DaoWorker getDaoWorker()
Returns the DaoWorker for this service.

Returns:
DaoWorker instance.

getDaoManager

protected DaoManager getDaoManager()
Returns the DaoManager for this service.

Returns:
DaoManager instance.

doCustomQuery

protected java.util.List doCustomQuery(java.lang.String query)
                                throws ServiceException
Convenience method to execute a query without parameters.

Parameters:
query - Query to execute.
Returns:
List instance of results.
Throws:
ServiceException

doCustomQuery

protected java.util.List doCustomQuery(Query query)
                                throws ServiceException
Convenience method to execute the given query.

Parameters:
query - Query to execute.
Returns:
List instance of results.
Throws:
ServiceException

insertDaoBean

protected int insertDaoBean(java.lang.String table,
                            DaoBean bean)
                     throws ServiceException
Convenience method to insert the properties of the given DaoBean into the named table.

Parameters:
table - Name of table to insert bean properties.
bean - DaoBean instance.
Returns:
Return the insert count as an int.
Throws:
ServiceException - if the bean properties cannot be inserted.

insertDaoBean

protected int insertDaoBean(java.lang.String table,
                            DaoBean bean,
                            TransactionContext tc)
                     throws ServiceException
Convenience method to insert the properties of the given DaoBean into the named table within the given transaction context.

Parameters:
table - Name of table to insert bean properties.
bean - DaoBean instance.
tc - Current TransactionContext.
Returns:
Return the insert count as an int.
Throws:
ServiceException - if the bean properties cannot be inserted.

updateDaoBean

protected int updateDaoBean(java.lang.String table,
                            DaoBean bean)
                     throws ServiceException
Convenience method to update the properties of the given DaoBean in the named table.

Parameters:
table - Name of table to update.
bean - DaoBean instance.
Returns:
Return the update count as an int.
Throws:
ServiceException - if the bean properties cannot be updated.

updateDaoBean

protected int updateDaoBean(java.lang.String table,
                            DaoBean bean,
                            TransactionContext tc)
                     throws ServiceException
Convenience method to update the properties of the given DaoBean in the named table within the given TransactionContext.

Parameters:
table - Name of table to update.
bean - DaoBean instance.
tc - Current TransactionContext.
Returns:
Return the update count as an int.
Throws:
ServiceException - if the bean properties cannot be updated.

checkConstraint

protected boolean checkConstraint(java.lang.String query,
                                  java.lang.Object[] params)
                           throws ServiceException
Convenience method to check a single foreign key constraint.

The query must return a single column named "count". If the count is greater than 0 the constraint exists.

Parameters:
query - Constraint query string.
params - Constraint parameters
Returns:
boolean Indicating the existance of the constraint.
Throws:
ServiceException - if an exception occurs while checking the constraint.

getNextSequenceValue

protected java.lang.Integer getNextSequenceValue(java.lang.String seq)
                                          throws ServiceException
Return the next value from the named oracle sequence.

Parameters:
seq - String containing the name of the sequence.
Returns:
Integer containing the next value.
Throws:
ServiceException - if the value cannot be returned.

destroy

public void destroy()
Destroy this service by destroying worker instance.

Specified by:
destroy in interface Service
Overrides:
destroy in class BaseService