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
FieldsModifier and TypeFieldDescriptionprivate Propertiesprivate Propertiesprivate Propertiesprivate Mapprivate com.google.inject.Injector(package private) static org.apache.commons.logging.Logprotected org.hibernate.SessionFactoryprivate Settingsprivate static final ThreadLocalprivate static final ThreadLocalFields inherited from class com.softslate.commerce.daos.core.BaseDAOFactory
moduleListString -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddComponentMappings(org.hibernate.cfg.Configuration configuration, Properties components) voidStart a new database transaction.voidCloses the Session local to the thread.voidCommit the database transaction.<T> TCreates and initializes a data access object for use by the application.voidEvicts 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.InjectorRetrieves theInjectorpreviously set for this factory.org.hibernate.SessionRetrieves the current Session local to the thread.org.hibernate.SessionFactoryRetrieves this factory's HibernateSessionFactory.Retrieves this factory'sSettingsinstance.Retrieves aMapof properties that will be transfered to each of the data access objects this factory creates.voidInitializes thisDAOFactory.org.hibernate.cfg.ConfigurationCreates a configured instance of Hibernate'sSessionFactoryin the application scope.voidRollback the database transaction.voidRollback the database transaction.voidsetAppComponents(Properties appComponents) voidsetAppComponentsDefaults(Properties appComponentsDefaults) voidsetAppSettings(Properties appSettings) voidsetImportExportSqlMap(Map importExportSqlMap) voidsetInjector(com.google.inject.Injector injector) Sets this factory'sInjector.voidsetSessionFactory(org.hibernate.SessionFactory sessionFactory) voidsetSettings(Settings settings) org.hibernate.SessionStarts 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, setTwoWayKeyFileMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:DAOFactoryRetrieves this factory'sSettingsinstance. The currentSettings, containing various settings to be used by DAOs created by this factory. This factory will pass theSettingsto every object it creates.- Specified by:
getSettingsin interfaceDAOFactory- Overrides:
getSettingsin classBaseDAOFactory
-
setSettings
- Specified by:
setSettingsin interfaceDAOFactory- Overrides:
setSettingsin classBaseDAOFactory
-
getAppSettings
Description copied from interface:DAOFactoryRetrieves 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 theSettingsinstance, which stores settings drawn from the database.- Specified by:
getAppSettingsin interfaceDAOFactory- Overrides:
getAppSettingsin classBaseDAOFactory
-
setAppSettings
- Specified by:
setAppSettingsin interfaceDAOFactory- Overrides:
setAppSettingsin classBaseDAOFactory
-
getAppComponents
Description copied from interface:DAOFactoryRetrieves this factory's component settings. The component settings identify which Java class implement the various Interfaces used by the system.- Specified by:
getAppComponentsin interfaceDAOFactory- Overrides:
getAppComponentsin classBaseDAOFactory
-
setAppComponents
- Specified by:
setAppComponentsin interfaceDAOFactory- Overrides:
setAppComponentsin classBaseDAOFactory
-
getAppComponentsDefaults
Description copied from interface:DAOFactoryRetrieves this factory's default component settings. The component settings identify which Java class implement the various Interfaces used by the system.- Specified by:
getAppComponentsDefaultsin interfaceDAOFactory- Overrides:
getAppComponentsDefaultsin classBaseDAOFactory
-
setAppComponentsDefaults
- Specified by:
setAppComponentsDefaultsin interfaceDAOFactory- Overrides:
setAppComponentsDefaultsin classBaseDAOFactory
-
getInjector
public com.google.inject.Injector getInjector()Description copied from interface:DAOFactoryRetrieves theInjectorpreviously set for this factory.- Specified by:
getInjectorin interfaceDAOFactory- Returns:
- A
Injectorobject 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:DAOFactorySets this factory'sInjector. This factory will pass theInjectorto every business object it creates.- Specified by:
setInjectorin interfaceDAOFactory- Parameters:
injector- The currentInjectorfor 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:DAOFactoryRetrieves this factory's HibernateSessionFactory.- Specified by:
getSessionFactoryin interfaceDAOFactory- Overrides:
getSessionFactoryin classBaseDAOFactory
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory) - Specified by:
setSessionFactoryin interfaceDAOFactory- Overrides:
setSessionFactoryin classBaseDAOFactory
-
getImportExportSqlMap
-
setImportExportSqlMap
-
initialize
Description copied from class:BaseDAOFactoryInitializes thisDAOFactory. Called byBaseRequestProcessor.- Specified by:
initializein interfaceDAOFactory- Overrides:
initializein classBaseDAOFactory- Throws:
Exception
-
initializeSessionFactory
public org.hibernate.cfg.Configuration initializeSessionFactory()Creates a configured instance of Hibernate'sSessionFactoryin 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 theappComponentsproperty.- Specified by:
createDAOin interfaceDAOFactory- Overrides:
createDAOin classBaseDAOFactory- Parameters:
type- AStringassociated with the class name of the data access object to be created.- Returns:
- An instantiated and initialized data access object, or
nullif initialization failed. - Throws:
Exception
-
createDAO
- Specified by:
createDAOin interfaceDAOFactory
-
findImplementer
-
getTransferMap
Retrieves aMapof properties that will be transfered to each of the data access objects this factory creates.- Overrides:
getTransferMapin classBaseDAOFactory- Returns:
- A
Mapof 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:
startSessionin interfaceDAOFactory- Overrides:
startSessionin classBaseDAOFactory- Returns:
- Session
-
getSession
public org.hibernate.Session getSession()Retrieves the current Session local to the thread.- Specified by:
getSessionin interfaceDAOFactory- Overrides:
getSessionin classBaseDAOFactory- Returns:
- Session
-
closeSession
public void closeSession()Closes the Session local to the thread.- Specified by:
closeSessionin interfaceDAOFactory- Overrides:
closeSessionin classBaseDAOFactory
-
beginTransaction
public void beginTransaction()Start a new database transaction.- Specified by:
beginTransactionin interfaceDAOFactory- Overrides:
beginTransactionin classBaseDAOFactory
-
commitTransaction
public void commitTransaction() throws org.hibernate.HibernateExceptionCommit the database transaction.- Specified by:
commitTransactionin interfaceDAOFactory- Overrides:
commitTransactionin classBaseDAOFactory- Throws:
org.hibernate.HibernateException
-
rollbackTransactionKeepingSessionOpen
public void rollbackTransactionKeepingSessionOpen()Rollback the database transaction.- Specified by:
rollbackTransactionKeepingSessionOpenin interfaceDAOFactory- Overrides:
rollbackTransactionKeepingSessionOpenin classBaseDAOFactory
-
rollbackTransaction
public void rollbackTransaction()Rollback the database transaction.- Specified by:
rollbackTransactionin interfaceDAOFactory- Overrides:
rollbackTransactionin classBaseDAOFactory
-
getDatabaseType
- Specified by:
getDatabaseTypein interfaceDAOFactory- Overrides:
getDatabaseTypein 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:
evictCachein interfaceDAOFactory- Overrides:
evictCachein classBaseDAOFactory
-