com.softslate.commerce.daos.core
Class HibernateDAOFactory

java.lang.Object
  extended by com.softslate.commerce.daos.core.BaseDAOFactory
      extended by com.softslate.commerce.daos.core.HibernateDAOFactory
All Implemented Interfaces:
DAOFactory

public class HibernateDAOFactory
extends BaseDAOFactory
implements DAOFactory

Factory class used to create and initialize instances of Hibernate data access objects.

An instance of HDAOFactory is created in the Struts layer and placed in the application scope. (See BaseRequestProcessor.)

Immediately after instantiating the requested DAO, this factory passes its own properties to it so that the newly created object can use them to communicate with the rest of the application.

Author:
David Tobey

Field Summary
private  java.util.Properties appComponents
           
private  java.util.Properties appSettings
           
private  java.util.Map importExportSqlMap
           
private  LegacyDAOFactory legacyDAOFactory
           
(package private) static org.apache.commons.logging.Log log
           
private  org.hibernate.SessionFactory sessionFactory
           
private  Settings settings
           
private static java.lang.ThreadLocal threadSession
           
private static java.lang.ThreadLocal threadTransaction
           
 
Fields inherited from class com.softslate.commerce.daos.core.BaseDAOFactory
moduleListString
 
Constructor Summary
HibernateDAOFactory()
           
 
Method Summary
 void beginTransaction()
          Start a new database transaction.
 void closeSession()
          Closes the Session local to the thread.
 void commitTransaction()
          Commit the database transaction.
 java.lang.Object createDAO(java.lang.String type)
          Creates and initializes a data access object for use by the application.
 void evictCache()
          Evicts the Hibernate 2nd level cache, plus any cached queries.
 java.util.Properties getAppComponents()
          Retrieves this factory's component settings.
 java.util.Properties getAppSettings()
          Retrieves this factory's application settings; the current application settings for the system.
 java.lang.String getDatabaseType()
           
 javax.sql.DataSource getDataSource()
          Provided to support legacy calls to the JDBC DataSource of the LegacyDAOFactory.
 java.util.Map getImportExportSqlMap()
           
 LegacyDAOFactory getLegacyDAOFactory()
           
 org.hibernate.Session getSession()
          Retrieves the current Session local to the thread.
 org.hibernate.SessionFactory getSessionFactory()
          Retrieves this factory's Hibernate SessionFactory.
 Settings getSettings()
          Retrieves this factory's Settings instance.
 java.util.Map getSqlMap()
          Provided to support legacy calls to retrieve the SQL map of the LegacyDAOFactory.
 java.util.Map getTransferMap()
          Retrieves a Map of properties that will be transfered to each of the data access objects this factory creates.
 void initialize()
          Initializes this DAOFactory.
 LegacyDAOFactory initializeLegacyDAOFactory()
          Creates a configured instance of LegacyDAOFactory in the application scope.
 org.hibernate.cfg.Configuration initializeSessionFactory()
          Creates a configured instance of Hibernate's SessionFactory in the application scope.
 void rollbackTransaction()
          Rollback the database transaction.
 void setAppComponents(java.util.Properties appComponents)
           
 void setAppSettings(java.util.Properties appSettings)
           
 void setImportExportSqlMap(java.util.Map importExportSqlMap)
           
 void setLegacyDAOFactory(LegacyDAOFactory legacyDAOFactory)
           
 void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
           
 void setSettings(Settings settings)
           
 org.hibernate.Session startSession()
          Starts an interaction with Hibernate.
 
Methods inherited from class com.softslate.commerce.daos.core.BaseDAOFactory
createDAOFromClassName, createSettingsDAO, getDatabaseDriver, getDatabasePassword, getDatabaseURL, getDatabaseUserName, getDataSourceName, getHibernateSettings, getJndiContext, getJndiDataSource, getMaxActive, getMaxIdle, getMaxWait, getModuleList, getModuleListString, getPaymentPrivateKeyFile, getPaymentPublicKeyFile, getPooledDataSource, getProperties, getRemoveAbandoned, getRemoveAbandonedTimeout, getTwoWayKeyFile, initialize, initializeDataSource, initializeSettings, initializeSQLProperties, loadProperties, loadProperties, setDatabaseDriver, setDatabasePassword, setDatabaseType, setDatabaseURL, setDatabaseUserName, setDataSource, setDataSourceName, setHibernateSettings, setJndiContext, setMaxActive, setMaxIdle, setMaxWait, setModuleList, setModuleListString, setPaymentPrivateKeyFile, setPaymentPublicKeyFile, setRemoveAbandoned, setRemoveAbandonedTimeout, setSqlMap, setTwoWayKeyFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.softslate.commerce.daos.core.DAOFactory
createDAOFromClassName, createSettingsDAO, getDatabaseDriver, getDatabasePassword, getDatabaseURL, getDatabaseUserName, getDataSourceName, getHibernateSettings, getJndiContext, getJndiDataSource, getMaxActive, getMaxIdle, getMaxWait, getModuleList, getModuleListString, getPaymentPrivateKeyFile, getPaymentPublicKeyFile, getRemoveAbandoned, getRemoveAbandonedTimeout, getTwoWayKeyFile, initialize, initializeDataSource, initializeSQLProperties, setDatabaseDriver, setDatabasePassword, setDatabaseType, setDatabaseURL, setDatabaseUserName, setDataSource, setDataSourceName, setHibernateSettings, setJndiContext, setMaxActive, setMaxIdle, setMaxWait, setModuleList, setModuleListString, setPaymentPrivateKeyFile, setPaymentPublicKeyFile, setRemoveAbandoned, setRemoveAbandonedTimeout, setTwoWayKeyFile
 

Field Detail

log

static org.apache.commons.logging.Log log

threadSession

private static final java.lang.ThreadLocal threadSession

threadTransaction

private static final java.lang.ThreadLocal threadTransaction

settings

private Settings settings

appSettings

private java.util.Properties appSettings

appComponents

private java.util.Properties appComponents

sessionFactory

private org.hibernate.SessionFactory sessionFactory

legacyDAOFactory

private LegacyDAOFactory legacyDAOFactory

importExportSqlMap

private java.util.Map importExportSqlMap
Constructor Detail

HibernateDAOFactory

public HibernateDAOFactory()
Method Detail

getSettings

public Settings getSettings()
Description copied from interface: DAOFactory
Retrieves this factory's Settings instance. The current Settings, containing various settings to be used by DAOs created by this factory. This factory will pass the Settings to every object it creates.

Specified by:
getSettings in interface DAOFactory
Overrides:
getSettings in class BaseDAOFactory

setSettings

public void setSettings(Settings settings)
Specified by:
setSettings in interface DAOFactory
Overrides:
setSettings in class BaseDAOFactory

getAppSettings

public java.util.Properties getAppSettings()
Description copied from interface: DAOFactory
Retrieves this factory's application settings; the current application settings for the system. This factory will pass the application settings to every DAO it creates. The application settings are settings for information unique to a given installation, such as the location of files on the server, as opposed to the Settings instance, which stores settings drawn from the database.

Specified by:
getAppSettings in interface DAOFactory
Overrides:
getAppSettings in class BaseDAOFactory

setAppSettings

public void setAppSettings(java.util.Properties appSettings)
Specified by:
setAppSettings in interface DAOFactory
Overrides:
setAppSettings in class BaseDAOFactory

getAppComponents

public java.util.Properties getAppComponents()
Description copied from interface: DAOFactory
Retrieves this factory's component settings. The component settings identify which Java class implement the various Interfaces used by the system.

Specified by:
getAppComponents in interface DAOFactory
Overrides:
getAppComponents in class BaseDAOFactory

setAppComponents

public void setAppComponents(java.util.Properties appComponents)
Specified by:
setAppComponents in interface DAOFactory
Overrides:
setAppComponents in class BaseDAOFactory

getSessionFactory

public org.hibernate.SessionFactory getSessionFactory()
Description copied from interface: DAOFactory
Retrieves this factory's Hibernate SessionFactory.

Specified by:
getSessionFactory in interface DAOFactory
Overrides:
getSessionFactory in class BaseDAOFactory

setSessionFactory

public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Specified by:
setSessionFactory in interface DAOFactory
Overrides:
setSessionFactory in class BaseDAOFactory

getLegacyDAOFactory

public LegacyDAOFactory getLegacyDAOFactory()

setLegacyDAOFactory

public void setLegacyDAOFactory(LegacyDAOFactory legacyDAOFactory)

getImportExportSqlMap

public java.util.Map getImportExportSqlMap()

setImportExportSqlMap

public void setImportExportSqlMap(java.util.Map importExportSqlMap)

initialize

public void initialize()
                throws java.lang.Exception
Description copied from class: BaseDAOFactory
Initializes this DAOFactory. Called by BaseRequestProcessor.

Specified by:
initialize in interface DAOFactory
Overrides:
initialize in class BaseDAOFactory
Throws:
java.lang.Exception

initializeSessionFactory

public org.hibernate.cfg.Configuration initializeSessionFactory()
Creates a configured instance of Hibernate's SessionFactory in the application scope.


createDAO

public java.lang.Object createDAO(java.lang.String type)
                           throws java.lang.Exception
Creates and initializes a data access object for use by the application. Looks up the class to be instantiated by using the appComponents property.

Specified by:
createDAO in interface DAOFactory
Overrides:
createDAO in class BaseDAOFactory
Parameters:
type - A String associated with the class name of the data access object to be created.
Returns:
An instantiated and initialized data access object, or null if initialization failed.
Throws:
java.lang.Exception

getTransferMap

public java.util.Map getTransferMap()
Retrieves a Map of properties that will be transfered to each of the data access objects this factory creates.

Overrides:
getTransferMap in class BaseDAOFactory
Returns:
A Map of properties that will be transfered to each of the data access objects this factory creates

startSession

public org.hibernate.Session startSession()
Starts an interaction with Hibernate.

Specified by:
startSession in interface DAOFactory
Overrides:
startSession in class BaseDAOFactory
Returns:
Session

getSession

public org.hibernate.Session getSession()
Retrieves the current Session local to the thread.

Specified by:
getSession in interface DAOFactory
Overrides:
getSession in class BaseDAOFactory
Returns:
Session

closeSession

public void closeSession()
Closes the Session local to the thread.

Specified by:
closeSession in interface DAOFactory
Overrides:
closeSession in class BaseDAOFactory

beginTransaction

public void beginTransaction()
Start a new database transaction.

Specified by:
beginTransaction in interface DAOFactory
Overrides:
beginTransaction in class BaseDAOFactory

commitTransaction

public void commitTransaction()
Commit the database transaction.

Specified by:
commitTransaction in interface DAOFactory
Overrides:
commitTransaction in class BaseDAOFactory

rollbackTransaction

public void rollbackTransaction()
Rollback the database transaction.

Specified by:
rollbackTransaction in interface DAOFactory
Overrides:
rollbackTransaction in class BaseDAOFactory

initializeLegacyDAOFactory

public LegacyDAOFactory initializeLegacyDAOFactory()
Creates a configured instance of LegacyDAOFactory in the application scope.

If successful, an instance of LegacyDAOFactory will be returned that allows the DAOs it creates to implement connection pooling, and that has loaded all of the application's SQL statements into memory.


getDataSource

public javax.sql.DataSource getDataSource()
Provided to support legacy calls to the JDBC DataSource of the LegacyDAOFactory.

Specified by:
getDataSource in interface DAOFactory
Overrides:
getDataSource in class BaseDAOFactory

getSqlMap

public java.util.Map getSqlMap()
Provided to support legacy calls to retrieve the SQL map of the LegacyDAOFactory.

Specified by:
getSqlMap in interface DAOFactory
Overrides:
getSqlMap in class BaseDAOFactory

getDatabaseType

public java.lang.String getDatabaseType()
Specified by:
getDatabaseType in interface DAOFactory
Overrides:
getDatabaseType in class BaseDAOFactory

evictCache

public void evictCache()
Evicts the Hibernate 2nd level cache, plus any cached queries. Evicts each of the cached regions defined in the default version of ehcache.xml, using getSessionFactory().evict(String region), and then runs getSessionFactory().evictQueries(); to evicted cached queries.

Specified by:
evictCache in interface DAOFactory
Overrides:
evictCache in class BaseDAOFactory


Copyright ? SoftSlate, LLC 2003?2005