Package com.softslate.commerce.daos.core
Class HibernateDAOFactory
java.lang.Object
com.softslate.commerce.daos.core.BaseDAOFactory
com.softslate.commerce.daos.core.HibernateDAOFactory
- All Implemented Interfaces:
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
Modifier and TypeFieldDescriptionprivate Properties
private Properties
private Properties
private Map
private com.google.inject.Injector
(package private) static org.apache.commons.logging.Log
protected org.hibernate.SessionFactory
private Settings
private static final ThreadLocal
private static final ThreadLocal
Fields inherited from class com.softslate.commerce.daos.core.BaseDAOFactory
moduleListString
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addComponentMappings
(org.hibernate.cfg.Configuration configuration, Properties components) void
Start a new database transaction.void
Closes the Session local to the thread.void
Commit the database transaction.<T> T
Creates and initializes a data access object for use by the application.void
Evicts the Hibernate 2nd level cache, plus any cached queries.findImplementer
(String type) Retrieves this factory's component settings.Retrieves this factory's default component settings.Retrieves this factory's application settings; the current application settings for the system.com.google.inject.Injector
Retrieves theInjector
previously set for this factory.org.hibernate.Session
Retrieves the current Session local to the thread.org.hibernate.SessionFactory
Retrieves this factory's HibernateSessionFactory
.Retrieves this factory'sSettings
instance.Retrieves aMap
of properties that will be transfered to each of the data access objects this factory creates.void
Initializes thisDAOFactory
.org.hibernate.cfg.Configuration
Creates a configured instance of Hibernate'sSessionFactory
in the application scope.void
Rollback the database transaction.void
Rollback the database transaction.void
setAppComponents
(Properties appComponents) void
setAppComponentsDefaults
(Properties appComponentsDefaults) void
setAppSettings
(Properties appSettings) void
setImportExportSqlMap
(Map importExportSqlMap) void
setInjector
(com.google.inject.Injector injector) Sets this factory'sInjector
.void
setSessionFactory
(org.hibernate.SessionFactory sessionFactory) void
setSettings
(Settings settings) org.hibernate.Session
Starts an interaction with Hibernate.Methods inherited from class com.softslate.commerce.daos.core.BaseDAOFactory
createDAOFromClassName, createSettingsDAO, getDatabaseDriver, getDatabasePassword, getDatabaseURL, getDatabaseUserName, getDataSource, getDataSourceName, getHibernateSettings, getJndiContext, getJndiDataSource, getMaxActive, getMaxIdle, getMaxWait, getModuleList, getModuleListString, getPaymentPrivateKeyFile, getPaymentPublicKeyFile, getPooledDataSource, getProperties, getRemoveAbandoned, getRemoveAbandonedTimeout, getSqlMap, 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, getHibernateSettings, getJndiDataSource, setDatabaseType, setHibernateSettings
-
Field Details
-
log
static org.apache.commons.logging.Log log -
threadSession
-
threadTransaction
-
settings
-
appSettings
-
appComponents
-
appComponentsDefaults
-
injector
private com.google.inject.Injector injector -
sessionFactory
protected org.hibernate.SessionFactory sessionFactory -
importExportSqlMap
-
-
Constructor Details
-
HibernateDAOFactory
public HibernateDAOFactory()
-
-
Method Details
-
getSettings
Description copied from interface:DAOFactory
Retrieves this factory'sSettings
instance. The currentSettings
, containing various settings to be used by DAOs created by this factory. This factory will pass theSettings
to every object it creates.- Specified by:
getSettings
in interfaceDAOFactory
- Overrides:
getSettings
in classBaseDAOFactory
-
setSettings
- Specified by:
setSettings
in interfaceDAOFactory
- Overrides:
setSettings
in classBaseDAOFactory
-
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 theSettings
instance, which stores settings drawn from the database.- Specified by:
getAppSettings
in interfaceDAOFactory
- Overrides:
getAppSettings
in classBaseDAOFactory
-
setAppSettings
- Specified by:
setAppSettings
in interfaceDAOFactory
- Overrides:
setAppSettings
in classBaseDAOFactory
-
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 interfaceDAOFactory
- Overrides:
getAppComponents
in classBaseDAOFactory
-
setAppComponents
- Specified by:
setAppComponents
in interfaceDAOFactory
- Overrides:
setAppComponents
in classBaseDAOFactory
-
getAppComponentsDefaults
Description copied from interface:DAOFactory
Retrieves this factory's default component settings. The component settings identify which Java class implement the various Interfaces used by the system.- Specified by:
getAppComponentsDefaults
in interfaceDAOFactory
- Overrides:
getAppComponentsDefaults
in classBaseDAOFactory
-
setAppComponentsDefaults
- Specified by:
setAppComponentsDefaults
in interfaceDAOFactory
- Overrides:
setAppComponentsDefaults
in classBaseDAOFactory
-
getInjector
public com.google.inject.Injector getInjector()Description copied from interface:DAOFactory
Retrieves theInjector
previously set for this factory.- Specified by:
getInjector
in interfaceDAOFactory
- Returns:
- A
Injector
object that can be used to create other objects and inject them with dependencies.
-
setInjector
public void setInjector(com.google.inject.Injector injector) Description copied from interface:DAOFactory
Sets this factory'sInjector
. This factory will pass theInjector
to every business object it creates.- Specified by:
setInjector
in interfaceDAOFactory
- Parameters:
injector
- The currentInjector
for the system, which can be used to create other objects and inject them with dependencies.
-
getSessionFactory
public org.hibernate.SessionFactory getSessionFactory()Description copied from interface:DAOFactory
Retrieves this factory's HibernateSessionFactory
.- Specified by:
getSessionFactory
in interfaceDAOFactory
- Overrides:
getSessionFactory
in classBaseDAOFactory
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory) - Specified by:
setSessionFactory
in interfaceDAOFactory
- Overrides:
setSessionFactory
in classBaseDAOFactory
-
getImportExportSqlMap
-
setImportExportSqlMap
-
initialize
Description copied from class:BaseDAOFactory
Initializes thisDAOFactory
. Called byBaseRequestProcessor
.- Specified by:
initialize
in interfaceDAOFactory
- Overrides:
initialize
in classBaseDAOFactory
- Throws:
Exception
-
initializeSessionFactory
public org.hibernate.cfg.Configuration initializeSessionFactory()Creates a configured instance of Hibernate'sSessionFactory
in the application scope. -
addComponentMappings
public void addComponentMappings(org.hibernate.cfg.Configuration configuration, Properties components) -
createDAO
Creates and initializes a data access object for use by the application. Looks up the class to be instantiated by using theappComponents
property.- Specified by:
createDAO
in interfaceDAOFactory
- Overrides:
createDAO
in classBaseDAOFactory
- Parameters:
type
- AString
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:
Exception
-
createDAO
- Specified by:
createDAO
in interfaceDAOFactory
-
findImplementer
-
getTransferMap
Retrieves aMap
of properties that will be transfered to each of the data access objects this factory creates.- Overrides:
getTransferMap
in classBaseDAOFactory
- 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 interfaceDAOFactory
- Overrides:
startSession
in classBaseDAOFactory
- Returns:
- Session
-
getSession
public org.hibernate.Session getSession()Retrieves the current Session local to the thread.- Specified by:
getSession
in interfaceDAOFactory
- Overrides:
getSession
in classBaseDAOFactory
- Returns:
- Session
-
closeSession
public void closeSession()Closes the Session local to the thread.- Specified by:
closeSession
in interfaceDAOFactory
- Overrides:
closeSession
in classBaseDAOFactory
-
beginTransaction
public void beginTransaction()Start a new database transaction.- Specified by:
beginTransaction
in interfaceDAOFactory
- Overrides:
beginTransaction
in classBaseDAOFactory
-
commitTransaction
public void commitTransaction() throws org.hibernate.HibernateExceptionCommit the database transaction.- Specified by:
commitTransaction
in interfaceDAOFactory
- Overrides:
commitTransaction
in classBaseDAOFactory
- Throws:
org.hibernate.HibernateException
-
rollbackTransactionKeepingSessionOpen
public void rollbackTransactionKeepingSessionOpen()Rollback the database transaction.- Specified by:
rollbackTransactionKeepingSessionOpen
in interfaceDAOFactory
- Overrides:
rollbackTransactionKeepingSessionOpen
in classBaseDAOFactory
-
rollbackTransaction
public void rollbackTransaction()Rollback the database transaction.- Specified by:
rollbackTransaction
in interfaceDAOFactory
- Overrides:
rollbackTransaction
in classBaseDAOFactory
-
getDatabaseType
- Specified by:
getDatabaseType
in interfaceDAOFactory
- Overrides:
getDatabaseType
in classBaseDAOFactory
-
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, usinggetSessionFactory().evict(String region)
, and then runsgetSessionFactory().evictQueries();
to evicted cached queries.- Specified by:
evictCache
in interfaceDAOFactory
- Overrides:
evictCache
in classBaseDAOFactory
-