Class BaseDAOFactory

java.lang.Object
com.softslate.commerce.daos.core.BaseDAOFactory
All Implemented Interfaces:
DAOFactory
Direct Known Subclasses:
HibernateDAOFactory

public abstract class BaseDAOFactory extends Object implements DAOFactory
Author:
David Tobey
  • Field Details

    • log

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

      private Map sqlMap
      A Map of SQL statements used by the application.
    • moduleList

      private StringTokenizer moduleList
      The list of modules in use by the application in StringTokenizer form. Modules may include core, product, order, and customer.
    • moduleListString

      public static String moduleListString
      The list of modules in use by the application in String form. Modules may include core, product, order, and customer.
    • dataSource

      private DataSource dataSource
      The application's DataSource used for persistent storage.
    • dataSourceName

      private String dataSourceName
      The JNDI name for the application's DataSource, if one is set up in the servlet container's configuration. (For example, in server.xml for Tomcat.)
    • jndiContext

      private String jndiContext
      The JNDI context for the application's DataSource, if one is set up in the servlet container's configuration. (For example, in server.xml for Tomcat.)
    • databaseDriver

      private String databaseDriver
      The fully-qualified class name of the database driver used for the DataSource.
    • databaseURL

      private String databaseURL
      The URL used for this factory's DataSource database connection, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDI dataSourceName and jndiContext settings.
    • databaseUserName

      private String databaseUserName
      The user name used for this factory's DataSource database connection, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDI dataSourceName and jndiContext settings.
    • databasePassword

      private String databasePassword
      The password used for this factory's DataSource database connection, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDI dataSourceName and jndiContext settings.
    • databaseType

      private String databaseType
      The type of database this factory connects to. For example, "MSSQL" or "MySQL".
    • maxIdle

      private String maxIdle
      The maximum number of idle connections for the pool used by this factory's DataSource, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDI dataSourceName and jndiContext settings.
    • maxActive

      private String maxActive
      The maximum number of active connections for the pool used by this factory's DataSource, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDI dataSourceName and jndiContext settings.
    • maxWait

      private String maxWait
      The maximum time to wait for a connection to become available in milliseconds, before an exception is thrown. Used by this factory's DataSource, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDI dataSourceName and jndiContext settings.
    • removeAbandoned

      private String removeAbandoned
      If set to true, abandoned connections will be removed and recycled. Used by this factory's DataSource, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDI dataSourceName and jndiContext settings.
    • removeAbandonedTimeout

      private String removeAbandonedTimeout
      The number of seconds a connection is idle before it is considered abandoned. Used by this factory's DataSource, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDI dataSourceName and jndiContext settings.
    • paymentPrivateKeyFile

      private String paymentPrivateKeyFile
      The full path to the file on the server where the private key is stored for key pair encryption.
    • paymentPublicKeyFile

      private String paymentPublicKeyFile
      The full path to the file on the server where the public key is stored for key pair (RSA) encryption.
    • twoWayKeyFile

      private String twoWayKeyFile
      The full path to the file on the server where the key is stored for two way (DES) encryption.
    • settings

      private Settings settings
      Used to look up the Java class names for the various DAO's this factory creates.
    • appSettings

      private Properties appSettings
    • appComponents

      private Properties appComponents
    • appComponentsDefaults

      private Properties appComponentsDefaults
    • hibernateSettings

      private Properties hibernateSettings
    • sessionFactory

      private org.hibernate.SessionFactory sessionFactory
  • Constructor Details

    • BaseDAOFactory

      public BaseDAOFactory()
  • Method Details

    • getSqlMap

      public Map getSqlMap()
    • setSqlMap

      public void setSqlMap(Map sqlMap)
    • getModuleList

      public StringTokenizer getModuleList()
    • setModuleList

      public void setModuleList(StringTokenizer moduleList)
    • getModuleListString

      public String getModuleListString()
    • setModuleListString

      public void setModuleListString(String moduleList)
    • getDataSource

      public DataSource getDataSource()
    • setDataSource

      public void setDataSource(DataSource dataSource)
    • getDataSourceName

      public String getDataSourceName()
    • setDataSourceName

      public void setDataSourceName(String dataSourceName)
    • getJndiContext

      public String getJndiContext()
    • setJndiContext

      public void setJndiContext(String jndiContext)
    • getDatabaseDriver

      public String getDatabaseDriver()
    • setDatabaseDriver

      public void setDatabaseDriver(String databaseDriver)
    • getDatabaseURL

      public String getDatabaseURL()
    • setDatabaseURL

      public void setDatabaseURL(String databaseURL)
    • getDatabaseUserName

      public String getDatabaseUserName()
    • setDatabaseUserName

      public void setDatabaseUserName(String databaseUserName)
    • getDatabasePassword

      public String getDatabasePassword()
    • setDatabasePassword

      public void setDatabasePassword(String databasePassword)
    • getDatabaseType

      public String getDatabaseType()
      Specified by:
      getDatabaseType in interface DAOFactory
    • setDatabaseType

      public void setDatabaseType(String databaseType)
      Specified by:
      setDatabaseType in interface DAOFactory
    • getMaxIdle

      public String getMaxIdle()
    • setMaxIdle

      public void setMaxIdle(String maxIdle)
    • getMaxActive

      public String getMaxActive()
    • setMaxActive

      public void setMaxActive(String maxActive)
    • getMaxWait

      public String getMaxWait()
    • setMaxWait

      public void setMaxWait(String maxWait)
    • getRemoveAbandoned

      public String getRemoveAbandoned()
    • setRemoveAbandoned

      public void setRemoveAbandoned(String removeAbandoned)
    • getRemoveAbandonedTimeout

      public String getRemoveAbandonedTimeout()
    • setRemoveAbandonedTimeout

      public void setRemoveAbandonedTimeout(String removeAbandonedTimeout)
    • getPaymentPrivateKeyFile

      public String getPaymentPrivateKeyFile()
    • setPaymentPrivateKeyFile

      public void setPaymentPrivateKeyFile(String paymentPrivateKeyFile)
    • getPaymentPublicKeyFile

      public String getPaymentPublicKeyFile()
    • setPaymentPublicKeyFile

      public void setPaymentPublicKeyFile(String paymentPublicKeyFile)
    • getTwoWayKeyFile

      public String getTwoWayKeyFile()
    • setTwoWayKeyFile

      public void setTwoWayKeyFile(String twoWayKeyFile)
    • 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
    • setSettings

      public void setSettings(Settings settings)
      Specified by:
      setSettings in interface DAOFactory
    • initialize

      public void initialize() throws Exception
      Initializes this DAOFactory. Called by BaseRequestProcessor.
      Specified by:
      initialize in interface DAOFactory
      Throws:
      Exception
    • initialize

      public void initialize(String settingsLocation) throws Exception
      Initializes this DAOFactory using the settings defined in the file located at the imcoming settingLocation.
      Parameters:
      settingsLocation - The location of a file containing database settings.
      Throws:
      Exception
    • initializeSQLProperties

      public void initializeSQLProperties() throws Exception
      Reads in the application's SQL statements into this factory's sqlMap. Loops through each of the active modules defined in the moduleList property and reads in the SQL properities from the files in "/WEB-INF/classes/resources.
      Throws:
      Exception
    • initializeSettings

      public void initializeSettings(String settingsLocation)
      Loads database settings from a properties file into the properties of this DAOFactory.
      Parameters:
      settingsLocation - The location of a file containing database settings.
    • getProperties

      public Properties getProperties(String databaseType, String module) throws Exception
      Loads SQL statements into a Properties object for a given database type. Reads a default sql.properties file for a given module under "WEB-INF/classes/resources" and then another file with SQL statements that override the defaults with SQL specific to the given database type. Finally, loads the sql-custom.properties file in each module to provide a way to override any of the statements deployed with the application.
      Parameters:
      databaseType - The type of database the SQL statements apply to.
      module - The module the SQL statements correspond to. For example, core, product, order, or customer.
      Returns:
      A Properties object representing the SQL statements.
      Throws:
      Exception
    • loadProperties

      public Properties loadProperties(String path)
      Load properties from a .properties file represented by the argument.
      Parameters:
      path - The path to the .properties file being loaded.
      Returns:
      A Properties object representing the contents of the file.
    • loadProperties

      public Properties loadProperties(String path, Properties defaultProperties)
      Load properties from a .properties file represented by the argument, using a given Properties object as the default properties.
      Parameters:
      path - The path to the .properties file being loaded.
      defaultProperties - A Properties object representing the default properties to be returned.
      Returns:
      A Properties object representing the contents of the file.
    • initializeDataSource

      public void initializeDataSource() throws Exception
      Initializes this factory's dataSource property. This method first attempts to establish a DataSource based on a JNDI data source name and context defined in the JNDI environment, using the datasourceName and jndiContext properties. If this fails, it will create it's own connection pool using the various other properties defined in this factory, including the databaseURL,databaseUserName, and databasePassword properties.
      Throws:
      Exception
    • getJndiDataSource

      public DataSource getJndiDataSource() throws Exception
      Looks up a DataSource object in a JNDI context. Attempts to establish a DataSource based on a JNDI data source name and context defined in the JNDI environment, using the datasourceName and jndiContext properties.
      Specified by:
      getJndiDataSource in interface DAOFactory
      Returns:
      A DataSource object for the application.
      Throws:
      Exception
    • getPooledDataSource

      public DataSource getPooledDataSource() throws Exception
      Creates a connection pool using various properties defined in this factory. Returns a DataSource object tied to it.
      Returns:
      A DataSource object for the application.
      Throws:
      Exception
    • getTransferMap

      public Map getTransferMap()
      Retrieves a Map of properties that will be transfered to each of the data access objects this factory creates.
      Returns:
      A Map of properties that will be transfered to each of the data access objects this factory creates
    • createSettingsDAO

      public Object createSettingsDAO() throws Exception
      Creates and initializes a settings bean data access object for use by the application.
      Returns:
      An instantiated and initialized settings bean data access object, or null if initialization failed.
      Throws:
      Exception
    • createDAO

      public Object createDAO(String type) throws Exception
      Creates and initializes a data access object for use by the application.
      Specified by:
      createDAO in interface DAOFactory
      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
    • createDAOFromClassName

      public Object createDAOFromClassName(String className) throws Exception
      Creates and initializes a data access object for use by the application. Using the incoming class name, appends the value of the databaseType property to the class name and attempts to instantiate that object. If that fails, it next appends "Basic" to the end of the class name. If a class still cannot be found, the class name from the class name itself is used.

      For example, if this factory receives a request to create an instance of CustomerDAO, this factory will try to instantiate the following objects in this order:

      1. com.softslate.commerce.daos.customer.CustomerDAOMSSQL
      2. com.softslate.commerce.daos.customer.CustomerDAOBasic
      3. com.softslate.commerce.daos.customer.CustomerDAO

      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.

      Specified by:
      createDAOFromClassName in interface DAOFactory
      Parameters:
      className - A String representing 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
    • 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
    • setAppSettings

      public void setAppSettings(Properties appSettings)
      Specified by:
      setAppSettings in interface DAOFactory
    • 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
    • setAppComponents

      public void setAppComponents(Properties appComponents)
      Specified by:
      setAppComponents in interface DAOFactory
    • 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
    • setAppComponentsDefaults

      public void setAppComponentsDefaults(Properties appComponentsDefaults)
      Specified by:
      setAppComponentsDefaults in interface DAOFactory
    • getHibernateSettings

      public Properties getHibernateSettings()
      Description copied from interface: DAOFactory
      Retrieves this factory's Hibernate settings. The Hibernate settings are explicitly set for the HibernateDAOFactory before it is initialized, so that they can be changed after the installer tool is run.
      Specified by:
      getHibernateSettings in interface DAOFactory
    • setHibernateSettings

      public void setHibernateSettings(Properties hibernateSettings)
      Specified by:
      setHibernateSettings in interface DAOFactory
    • getSessionFactory

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

      public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
      Specified by:
      setSessionFactory in interface DAOFactory
    • startSession

      public org.hibernate.Session startSession()
      Specified by:
      startSession in interface DAOFactory
    • getSession

      public org.hibernate.Session getSession()
      Specified by:
      getSession in interface DAOFactory
    • closeSession

      public void closeSession()
      Specified by:
      closeSession in interface DAOFactory
    • beginTransaction

      public void beginTransaction()
      Specified by:
      beginTransaction in interface DAOFactory
    • commitTransaction

      public void commitTransaction() throws org.hibernate.HibernateException
      Specified by:
      commitTransaction in interface DAOFactory
      Throws:
      org.hibernate.HibernateException
    • rollbackTransactionKeepingSessionOpen

      public void rollbackTransactionKeepingSessionOpen()
      Specified by:
      rollbackTransactionKeepingSessionOpen in interface DAOFactory
    • rollbackTransaction

      public void rollbackTransaction()
      Specified by:
      rollbackTransaction in interface DAOFactory
    • evictCache

      public void evictCache()
      Specified by:
      evictCache in interface DAOFactory