com.softslate.commerce.daos.core
Class BaseDAOFactory

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

public abstract class BaseDAOFactory
extends java.lang.Object
implements DAOFactory

Author:
David Tobey

Field Summary
private  java.util.Properties appComponents
           
private  java.util.Properties appSettings
           
private  java.lang.String databaseDriver
          The fully-qualified class name of the database driver used for the DataSource.
private  java.lang.String databasePassword
          The password used for this factory's DataSource database connection, if the built-in connection pooling is used.
private  java.lang.String databaseType
          The type of database this factory connects to.
private  java.lang.String databaseURL
          The URL used for this factory's DataSource database connection, if the built-in connection pooling is used.
private  java.lang.String databaseUserName
          The user name used for this factory's DataSource database connection, if the built-in connection pooling is used.
private  javax.sql.DataSource dataSource
          The application's DataSource used for persistent storage.
private  java.lang.String dataSourceName
          The JNDI name for the application's DataSource, if one is set up in the servlet container's configuration.
private  java.util.Properties hibernateSettings
           
private  java.lang.String jndiContext
          The JNDI context for the application's DataSource, if one is set up in the servlet container's configuration.
(package private) static org.apache.commons.logging.Log log
           
private  java.lang.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.
private  java.lang.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.
private  java.lang.String maxWait
          The maximum time to wait for a connection to become available in milliseconds, before an exception is thrown.
private  java.util.StringTokenizer moduleList
          The list of modules in use by the application in StringTokenizer form.
static java.lang.String moduleListString
          The list of modules in use by the application in String form.
private  java.lang.String paymentPrivateKeyFile
          The full path to the file on the server where the private key is stored for key pair encryption.
private  java.lang.String paymentPublicKeyFile
          The full path to the file on the server where the public key is stored for key pair (RSA) encryption.
private  java.lang.String removeAbandoned
          If set to true, abandoned connections will be removed and recycled.
private  java.lang.String removeAbandonedTimeout
          The number of seconds a connection is idle before it is considered abandoned.
private  org.hibernate.SessionFactory sessionFactory
           
private  Settings settings
          Used to look up the Java class names for the various DAO's this factory creates.
private  java.util.Map sqlMap
          A Map of SQL statements used by the application.
private  java.lang.String twoWayKeyFile
          The full path to the file on the server where the key is stored for two way (DES) encryption.
 
Constructor Summary
BaseDAOFactory()
           
 
Method Summary
 void beginTransaction()
           
 void closeSession()
           
 void commitTransaction()
           
 java.lang.Object createDAO(java.lang.String type)
          Creates and initializes a data access object for use by the application.
 java.lang.Object createDAOFromClassName(java.lang.String className)
          Creates and initializes a data access object for use by the application.
 java.lang.Object createSettingsDAO()
          Creates and initializes a settings bean data access object for use by the application.
 void evictCache()
           
 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 getDatabaseDriver()
           
 java.lang.String getDatabasePassword()
           
 java.lang.String getDatabaseType()
           
 java.lang.String getDatabaseURL()
           
 java.lang.String getDatabaseUserName()
           
 javax.sql.DataSource getDataSource()
           
 java.lang.String getDataSourceName()
           
 java.util.Properties getHibernateSettings()
          Retrieves this factory's Hibernate settings.
 java.lang.String getJndiContext()
           
 javax.sql.DataSource getJndiDataSource()
          Looks up a DataSource object in a JNDI context.
 java.lang.String getMaxActive()
           
 java.lang.String getMaxIdle()
           
 java.lang.String getMaxWait()
           
 java.util.StringTokenizer getModuleList()
           
 java.lang.String getModuleListString()
           
 java.lang.String getPaymentPrivateKeyFile()
           
 java.lang.String getPaymentPublicKeyFile()
           
 javax.sql.DataSource getPooledDataSource()
          Creates a connection pool using various properties defined in this factory.
 java.util.Properties getProperties(java.lang.String databaseType, java.lang.String module)
          Loads SQL statements into a Properties object for a given database type.
 java.lang.String getRemoveAbandoned()
           
 java.lang.String getRemoveAbandonedTimeout()
           
 org.hibernate.Session getSession()
           
 org.hibernate.SessionFactory getSessionFactory()
          Retrieves this factory's Hibernate SessionFactory.
 Settings getSettings()
          Retrieves this factory's Settings instance.
 java.util.Map getSqlMap()
           
 java.util.Map getTransferMap()
          Retrieves a Map of properties that will be transfered to each of the data access objects this factory creates.
 java.lang.String getTwoWayKeyFile()
           
 void initialize()
          Initializes this DAOFactory.
 void initialize(java.lang.String settingsLocation)
          Initializes this DAOFactory using the settings defined in the file located at the imcoming settingLocation.
 void initializeDataSource()
          Initializes this factory's dataSource property.
 void initializeSettings(java.lang.String settingsLocation)
          Loads database settings from a properties file into the properties of this DAOFactory.
 void initializeSQLProperties()
          Reads in the application's SQL statements into this factory's sqlMap.
 java.util.Properties loadProperties(java.lang.String path)
          Load properties from a .properties file represented by the argument.
 java.util.Properties loadProperties(java.lang.String path, java.util.Properties defaultProperties)
          Load properties from a .properties file represented by the argument, using a given Properties object as the default properties.
 void rollbackTransaction()
           
 void setAppComponents(java.util.Properties appComponents)
           
 void setAppSettings(java.util.Properties appSettings)
           
 void setDatabaseDriver(java.lang.String databaseDriver)
           
 void setDatabasePassword(java.lang.String databasePassword)
           
 void setDatabaseType(java.lang.String databaseType)
           
 void setDatabaseURL(java.lang.String databaseURL)
           
 void setDatabaseUserName(java.lang.String databaseUserName)
           
 void setDataSource(javax.sql.DataSource dataSource)
           
 void setDataSourceName(java.lang.String dataSourceName)
           
 void setHibernateSettings(java.util.Properties hibernateSettings)
           
 void setJndiContext(java.lang.String jndiContext)
           
 void setMaxActive(java.lang.String maxActive)
           
 void setMaxIdle(java.lang.String maxIdle)
           
 void setMaxWait(java.lang.String maxWait)
           
 void setModuleList(java.util.StringTokenizer moduleList)
           
 void setModuleListString(java.lang.String moduleList)
           
 void setPaymentPrivateKeyFile(java.lang.String paymentPrivateKeyFile)
           
 void setPaymentPublicKeyFile(java.lang.String paymentPublicKeyFile)
           
 void setRemoveAbandoned(java.lang.String removeAbandoned)
           
 void setRemoveAbandonedTimeout(java.lang.String removeAbandonedTimeout)
           
 void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
           
 void setSettings(Settings settings)
           
 void setSqlMap(java.util.Map sqlMap)
           
 void setTwoWayKeyFile(java.lang.String twoWayKeyFile)
           
 org.hibernate.Session startSession()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

static org.apache.commons.logging.Log log

sqlMap

private java.util.Map sqlMap
A Map of SQL statements used by the application.


moduleList

private java.util.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 java.lang.String moduleListString
The list of modules in use by the application in String form. Modules may include core, product, order, and customer.


dataSource

private javax.sql.DataSource dataSource
The application's DataSource used for persistent storage.


dataSourceName

private java.lang.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 java.lang.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 java.lang.String databaseDriver
The fully-qualified class name of the database driver used for the DataSource.


databaseURL

private java.lang.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 java.lang.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 java.lang.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 java.lang.String databaseType
The type of database this factory connects to. For example, "MSSQL" or "MySQL".


maxIdle

private java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.String paymentPrivateKeyFile
The full path to the file on the server where the private key is stored for key pair encryption.


paymentPublicKeyFile

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


twoWayKeyFile

private java.lang.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 java.util.Properties appSettings

appComponents

private java.util.Properties appComponents

hibernateSettings

private java.util.Properties hibernateSettings

sessionFactory

private org.hibernate.SessionFactory sessionFactory
Constructor Detail

BaseDAOFactory

public BaseDAOFactory()
Method Detail

getSqlMap

public java.util.Map getSqlMap()
Specified by:
getSqlMap in interface DAOFactory

setSqlMap

public void setSqlMap(java.util.Map sqlMap)

getModuleList

public java.util.StringTokenizer getModuleList()
Specified by:
getModuleList in interface DAOFactory

setModuleList

public void setModuleList(java.util.StringTokenizer moduleList)
Specified by:
setModuleList in interface DAOFactory

getModuleListString

public java.lang.String getModuleListString()
Specified by:
getModuleListString in interface DAOFactory

setModuleListString

public void setModuleListString(java.lang.String moduleList)
Specified by:
setModuleListString in interface DAOFactory

getDataSource

public javax.sql.DataSource getDataSource()
Specified by:
getDataSource in interface DAOFactory

setDataSource

public void setDataSource(javax.sql.DataSource dataSource)
Specified by:
setDataSource in interface DAOFactory

getDataSourceName

public java.lang.String getDataSourceName()
Specified by:
getDataSourceName in interface DAOFactory

setDataSourceName

public void setDataSourceName(java.lang.String dataSourceName)
Specified by:
setDataSourceName in interface DAOFactory

getJndiContext

public java.lang.String getJndiContext()
Specified by:
getJndiContext in interface DAOFactory

setJndiContext

public void setJndiContext(java.lang.String jndiContext)
Specified by:
setJndiContext in interface DAOFactory

getDatabaseDriver

public java.lang.String getDatabaseDriver()
Specified by:
getDatabaseDriver in interface DAOFactory

setDatabaseDriver

public void setDatabaseDriver(java.lang.String databaseDriver)
Specified by:
setDatabaseDriver in interface DAOFactory

getDatabaseURL

public java.lang.String getDatabaseURL()
Specified by:
getDatabaseURL in interface DAOFactory

setDatabaseURL

public void setDatabaseURL(java.lang.String databaseURL)
Specified by:
setDatabaseURL in interface DAOFactory

getDatabaseUserName

public java.lang.String getDatabaseUserName()
Specified by:
getDatabaseUserName in interface DAOFactory

setDatabaseUserName

public void setDatabaseUserName(java.lang.String databaseUserName)
Specified by:
setDatabaseUserName in interface DAOFactory

getDatabasePassword

public java.lang.String getDatabasePassword()
Specified by:
getDatabasePassword in interface DAOFactory

setDatabasePassword

public void setDatabasePassword(java.lang.String databasePassword)
Specified by:
setDatabasePassword in interface DAOFactory

getDatabaseType

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

setDatabaseType

public void setDatabaseType(java.lang.String databaseType)
Specified by:
setDatabaseType in interface DAOFactory

getMaxIdle

public java.lang.String getMaxIdle()
Specified by:
getMaxIdle in interface DAOFactory

setMaxIdle

public void setMaxIdle(java.lang.String maxIdle)
Specified by:
setMaxIdle in interface DAOFactory

getMaxActive

public java.lang.String getMaxActive()
Specified by:
getMaxActive in interface DAOFactory

setMaxActive

public void setMaxActive(java.lang.String maxActive)
Specified by:
setMaxActive in interface DAOFactory

getMaxWait

public java.lang.String getMaxWait()
Specified by:
getMaxWait in interface DAOFactory

setMaxWait

public void setMaxWait(java.lang.String maxWait)
Specified by:
setMaxWait in interface DAOFactory

getRemoveAbandoned

public java.lang.String getRemoveAbandoned()
Specified by:
getRemoveAbandoned in interface DAOFactory

setRemoveAbandoned

public void setRemoveAbandoned(java.lang.String removeAbandoned)
Specified by:
setRemoveAbandoned in interface DAOFactory

getRemoveAbandonedTimeout

public java.lang.String getRemoveAbandonedTimeout()
Specified by:
getRemoveAbandonedTimeout in interface DAOFactory

setRemoveAbandonedTimeout

public void setRemoveAbandonedTimeout(java.lang.String removeAbandonedTimeout)
Specified by:
setRemoveAbandonedTimeout in interface DAOFactory

getPaymentPrivateKeyFile

public java.lang.String getPaymentPrivateKeyFile()
Specified by:
getPaymentPrivateKeyFile in interface DAOFactory

setPaymentPrivateKeyFile

public void setPaymentPrivateKeyFile(java.lang.String paymentPrivateKeyFile)
Specified by:
setPaymentPrivateKeyFile in interface DAOFactory

getPaymentPublicKeyFile

public java.lang.String getPaymentPublicKeyFile()
Specified by:
getPaymentPublicKeyFile in interface DAOFactory

setPaymentPublicKeyFile

public void setPaymentPublicKeyFile(java.lang.String paymentPublicKeyFile)
Specified by:
setPaymentPublicKeyFile in interface DAOFactory

getTwoWayKeyFile

public java.lang.String getTwoWayKeyFile()
Specified by:
getTwoWayKeyFile in interface DAOFactory

setTwoWayKeyFile

public void setTwoWayKeyFile(java.lang.String twoWayKeyFile)
Specified by:
setTwoWayKeyFile in interface DAOFactory

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 java.lang.Exception
Initializes this DAOFactory. Called by BaseRequestProcessor.

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

initialize

public void initialize(java.lang.String settingsLocation)
                throws java.lang.Exception
Initializes this DAOFactory using the settings defined in the file located at the imcoming settingLocation.

Specified by:
initialize in interface DAOFactory
Parameters:
settingsLocation - The location of a file containing database settings.
Throws:
java.lang.Exception

initializeSQLProperties

public void initializeSQLProperties()
                             throws java.lang.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.

Specified by:
initializeSQLProperties in interface DAOFactory
Throws:
java.lang.Exception

initializeSettings

public void initializeSettings(java.lang.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 java.util.Properties getProperties(java.lang.String databaseType,
                                          java.lang.String module)
                                   throws java.lang.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:
java.lang.Exception

loadProperties

public java.util.Properties loadProperties(java.lang.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 java.util.Properties loadProperties(java.lang.String path,
                                           java.util.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 java.lang.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.

Specified by:
initializeDataSource in interface DAOFactory
Throws:
java.lang.Exception

getJndiDataSource

public javax.sql.DataSource getJndiDataSource()
                                       throws java.lang.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:
java.lang.Exception

getPooledDataSource

public javax.sql.DataSource getPooledDataSource()
                                         throws java.lang.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:
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.

Returns:
A Map of properties that will be transfered to each of the data access objects this factory creates

createSettingsDAO

public java.lang.Object createSettingsDAO()
                                   throws java.lang.Exception
Creates and initializes a settings bean data access object for use by the application.

Specified by:
createSettingsDAO in interface DAOFactory
Returns:
An instantiated and initialized settings bean data access object, or null if initialization failed.
Throws:
java.lang.Exception

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.

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:
java.lang.Exception

createDAOFromClassName

public java.lang.Object createDAOFromClassName(java.lang.String className)
                                        throws java.lang.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:
java.lang.Exception

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

setAppSettings

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

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

setAppComponents

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

getHibernateSettings

public java.util.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(java.util.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()
Specified by:
commitTransaction in interface DAOFactory

rollbackTransaction

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

evictCache

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


Copyright ? SoftSlate, LLC 2003?2005