Class HibernateDAOFactory

java.lang.Object
com.softslate.commerce.daos.core.BaseDAOFactory
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 Details

    • log

      static org.apache.commons.logging.Log log
    • threadSession

      private static final ThreadLocal threadSession
    • threadTransaction

      private static final ThreadLocal threadTransaction
    • settings

      private Settings settings
    • appSettings

      private Properties appSettings
    • appComponents

      private Properties appComponents
    • appComponentsDefaults

      private Properties appComponentsDefaults
    • injector

      private com.google.inject.Injector injector
    • sessionFactory

      protected org.hibernate.SessionFactory sessionFactory
    • importExportSqlMap

      private Map importExportSqlMap
  • Constructor Details

    • HibernateDAOFactory

      public HibernateDAOFactory()
  • Method Details

    • 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 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(Properties appSettings)
      Specified by:
      setAppSettings in interface DAOFactory
      Overrides:
      setAppSettings in class BaseDAOFactory
    • getAppComponents

      public 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(Properties appComponents)
      Specified by:
      setAppComponents in interface DAOFactory
      Overrides:
      setAppComponents in class BaseDAOFactory
    • getAppComponentsDefaults

      public Properties 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 interface DAOFactory
      Overrides:
      getAppComponentsDefaults in class BaseDAOFactory
    • setAppComponentsDefaults

      public void setAppComponentsDefaults(Properties appComponentsDefaults)
      Specified by:
      setAppComponentsDefaults in interface DAOFactory
      Overrides:
      setAppComponentsDefaults in class BaseDAOFactory
    • getInjector

      public com.google.inject.Injector getInjector()
      Description copied from interface: DAOFactory
      Retrieves the Injector previously set for this factory.
      Specified by:
      getInjector in interface DAOFactory
      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's Injector. This factory will pass the Injector to every business object it creates.
      Specified by:
      setInjector in interface DAOFactory
      Parameters:
      injector - The current Injector 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 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
    • getImportExportSqlMap

      public Map getImportExportSqlMap()
    • setImportExportSqlMap

      public void setImportExportSqlMap(Map importExportSqlMap)
    • initialize

      public void initialize() throws Exception
      Description copied from class: BaseDAOFactory
      Initializes this DAOFactory. Called by BaseRequestProcessor.
      Specified by:
      initialize in interface DAOFactory
      Overrides:
      initialize in class BaseDAOFactory
      Throws:
      Exception
    • initializeSessionFactory

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

      public void addComponentMappings(org.hibernate.cfg.Configuration configuration, Properties components)
    • createDAO

      public Object createDAO(String type) throws 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:
      Exception
    • createDAO

      public <T> T createDAO(Class<T> type)
      Specified by:
      createDAO in interface DAOFactory
    • findImplementer

      public String findImplementer(String type)
    • getTransferMap

      public 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() throws org.hibernate.HibernateException
      Commit the database transaction.
      Specified by:
      commitTransaction in interface DAOFactory
      Overrides:
      commitTransaction in class BaseDAOFactory
      Throws:
      org.hibernate.HibernateException
    • rollbackTransactionKeepingSessionOpen

      public void rollbackTransactionKeepingSessionOpen()
      Rollback the database transaction.
      Specified by:
      rollbackTransactionKeepingSessionOpen in interface DAOFactory
      Overrides:
      rollbackTransactionKeepingSessionOpen in class BaseDAOFactory
    • rollbackTransaction

      public void rollbackTransaction()
      Rollback the database transaction.
      Specified by:
      rollbackTransaction in interface DAOFactory
      Overrides:
      rollbackTransaction in class BaseDAOFactory
    • getDatabaseType

      public 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