toolbox.dao
Class AbstractDaoManager

Package class diagram package AbstractDaoManager
java.lang.Object
  extended by toolbox.dao.AbstractDaoManager
All Implemented Interfaces:
DaoManager
Direct Known Subclasses:
GenericDaoManager, MySQLDaoManager, NoDictDaoManager

public abstract class AbstractDaoManager
extends java.lang.Object
implements DaoManager

Abstract DaoManager that provides convenience methods when implementing the DaoManager interface.

The following functionality is provided:

  • A standard way of initialising common SQL statements based on the TableDefinition and FieldDefintion classes provided by this package.
  • Implementations of the getConnection(),releaseConnection(), newDaoWorker(),newTransactionContext(),newListBuilder(),freeResources() and destroy() methods specified by the DaoManager interface.

  • Field Summary
    protected  java.util.Map m_statements
              Hashtable containing table names as keys and arrays of SQL Strings as values.
    protected  java.util.Map m_tableDefs
              Hashtable containing table names as keys and TableDefinition objects as values.
    protected  XMLProperties m_xmlProps
              XML configuration properties
     
    Constructor Summary
    protected AbstractDaoManager()
              Protected constructor to ensure this class cannot be instantiated.
     
    Method Summary
     void destroy()
              Destroy this manager by destroying the member resource pool.
     void freeResources(TransactionContext tc)
              Free the resources held by the given transaction context.
     java.sql.Connection getConnection()
              Returns a reference to a pooled connection.
     DaoWorker getDaoWorker()
              Returns a reference to the DaoWorker instance of the configured worker implementation
     ListBuilder getListBuilder()
              Instantiates and returns an instance of the configured ListBuilder implementation
     java.lang.String getName()
              Return the name of this manager
    protected  void initFinal()
              Method to be called to initialise worker and list builder instances.
    protected  void initSQL()
              Creates SQL strings from the initialised TableDefinitions and stores them in the m_statements Map.
    protected  void initStart(XMLProperties xmlProps)
              Initialises all internal resources for this manager.
     TransactionContext newTransactionContext()
              Instantiates and returns an instance of the configured context implementation
     void releaseConnection(java.sql.Connection connection)
              Release a connection.
     void setName(java.lang.String name)
              Set the name of this manager.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     
    Methods inherited from interface toolbox.dao.DaoManager
    init
     

    Field Detail

    m_tableDefs

    protected java.util.Map m_tableDefs
    Hashtable containing table names as keys and TableDefinition objects as values.


    m_statements

    protected java.util.Map m_statements
    Hashtable containing table names as keys and arrays of SQL Strings as values.


    m_xmlProps

    protected XMLProperties m_xmlProps
    XML configuration properties

    Constructor Detail

    AbstractDaoManager

    protected AbstractDaoManager()
    Protected constructor to ensure this class cannot be instantiated.

    Method Detail

    initStart

    protected void initStart(XMLProperties xmlProps)
                      throws DaoException
    Initialises all internal resources for this manager.

    The following is initialised:

  • The ConnectionManager
  • The class name of the default worker implementation
  • The class name of the default transaction context implementation
  • The class name of the default list builder implementation
  • Throws:
    DaoException - if internal settings cannot be set.

    initSQL

    protected void initSQL()
    Creates SQL strings from the initialised TableDefinitions and stores them in the m_statements Map. This should be the final method call in the init method.

    A String array is created for each initialised TableDefinition. The array contains five SQL strings:

  • 0 - Insert string
  • 1 - Update string
  • 2 - Select all string
  • 3 - Select by primary key string
  • 4 - Delete by primary key string

  • initFinal

    protected void initFinal()
                      throws DaoException
    Method to be called to initialise worker and list builder instances.

    Throws:
    DaoException - if the instances cannot be created.

    setName

    public void setName(java.lang.String name)
    Set the name of this manager.

    Specified by:
    setName in interface DaoManager
    Parameters:
    name - String containing manager name.

    getName

    public java.lang.String getName()
    Return the name of this manager

    Specified by:
    getName in interface DaoManager
    Returns:
    String containing the name of this manager.

    getConnection

    public java.sql.Connection getConnection()
                                      throws DaoException
    Returns a reference to a pooled connection.

    Specified by:
    getConnection in interface DaoManager
    Returns:
    A managed connection.
    Throws:
    DaoException - if a connection cannot be obtained.

    releaseConnection

    public void releaseConnection(java.sql.Connection connection)
    Release a connection.

    Specified by:
    releaseConnection in interface DaoManager
    Parameters:
    connection - Connection to release

    getDaoWorker

    public DaoWorker getDaoWorker()
    Returns a reference to the DaoWorker instance of the configured worker implementation

    Specified by:
    getDaoWorker in interface DaoManager
    Returns:
    DaoWorker instance.

    newTransactionContext

    public TransactionContext newTransactionContext()
                                             throws DaoException
    Instantiates and returns an instance of the configured context implementation

    Specified by:
    newTransactionContext in interface DaoManager
    Returns:
    TransactionContext instance.
    Throws:
    DaoException - if the context cannot be instantiated.

    getListBuilder

    public ListBuilder getListBuilder()
    Instantiates and returns an instance of the configured ListBuilder implementation

    Specified by:
    getListBuilder in interface DaoManager
    Returns:
    ListBuilder instance.

    freeResources

    public void freeResources(TransactionContext tc)
                       throws DaoException
    Free the resources held by the given transaction context.

    Specified by:
    freeResources in interface DaoManager
    Parameters:
    tc - TransactionContext.
    Throws:
    DaoException - if resources cannot be released from the context.

    destroy

    public void destroy()
                 throws DaoException
    Destroy this manager by destroying the member resource pool.

    Specified by:
    destroy in interface DaoManager
    Throws:
    DaoException - if the pool cannot be destroyed.