Package com.softslate.commerce.daos.core
Class BaseDAOFactory
java.lang.Object
com.softslate.commerce.daos.core.BaseDAOFactory
- All Implemented Interfaces:
DAOFactory
- Direct Known Subclasses:
HibernateDAOFactory
- Author:
- David Tobey
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Properties
private Properties
private Properties
private String
The fully-qualified class name of the database driver used for theDataSource
.private String
The password used for this factory'sDataSource
database connection, if the built-in connection pooling is used.private String
The type of database this factory connects to.private String
The URL used for this factory'sDataSource
database connection, if the built-in connection pooling is used.private String
The user name used for this factory'sDataSource
database connection, if the built-in connection pooling is used.private DataSource
The application'sDataSource
used for persistent storage.private String
The JNDI name for the application'sDataSource
, if one is set up in the servlet container's configuration.private Properties
private String
The JNDI context for the application'sDataSource
, if one is set up in the servlet container's configuration.(package private) static org.apache.commons.logging.Log
private String
The maximum number of active connections for the pool used by this factory'sDataSource
, if the built-in connection pooling is used.private String
The maximum number of idle connections for the pool used by this factory'sDataSource
, if the built-in connection pooling is used.private String
The maximum time to wait for a connection to become available in milliseconds, before an exception is thrown.private StringTokenizer
The list of modules in use by the application inStringTokenizer
form.static String
The list of modules in use by the application inString
form.private String
The full path to the file on the server where the private key is stored for key pair encryption.private String
The full path to the file on the server where the public key is stored for key pair (RSA) encryption.private String
If set to true, abandoned connections will be removed and recycled.private String
The number of seconds a connection is idle before it is considered abandoned.private org.hibernate.SessionFactory
private Settings
Used to look up the Java class names for the various DAO's this factory creates.private Map
AMap
of SQL statements used by the application.private String
The full path to the file on the server where the key is stored for two way (DES) encryption. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
Creates and initializes a data access object for use by the application.createDAOFromClassName
(String className) Creates and initializes a data access object for use by the application.Creates and initializes a settings bean data access object for use by the application.void
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.Retrieves this factory's Hibernate settings.Looks up aDataSource
object in a JNDI context.Creates a connection pool using various properties defined in this factory.getProperties
(String databaseType, String module) Loads SQL statements into aProperties
object for a given database type.org.hibernate.Session
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
.void
initialize
(String settingsLocation) Initializes thisDAOFactory
using the settings defined in the file located at the imcomingsettingLocation
.void
Initializes this factory'sdataSource
property.void
initializeSettings
(String settingsLocation) Loads database settings from a properties file into the properties of thisDAOFactory
.void
Reads in the application's SQL statements into this factory'ssqlMap
.loadProperties
(String path) Load properties from a .properties file represented by the argument.loadProperties
(String path, Properties defaultProperties) Load properties from a .properties file represented by the argument, using a givenProperties
object as the default properties.void
void
void
setAppComponents
(Properties appComponents) void
setAppComponentsDefaults
(Properties appComponentsDefaults) void
setAppSettings
(Properties appSettings) void
setDatabaseDriver
(String databaseDriver) void
setDatabasePassword
(String databasePassword) void
setDatabaseType
(String databaseType) void
setDatabaseURL
(String databaseURL) void
setDatabaseUserName
(String databaseUserName) void
setDataSource
(DataSource dataSource) void
setDataSourceName
(String dataSourceName) void
setHibernateSettings
(Properties hibernateSettings) void
setJndiContext
(String jndiContext) void
setMaxActive
(String maxActive) void
setMaxIdle
(String maxIdle) void
setMaxWait
(String maxWait) void
setModuleList
(StringTokenizer moduleList) void
setModuleListString
(String moduleList) void
setPaymentPrivateKeyFile
(String paymentPrivateKeyFile) void
setPaymentPublicKeyFile
(String paymentPublicKeyFile) void
setRemoveAbandoned
(String removeAbandoned) void
setRemoveAbandonedTimeout
(String removeAbandonedTimeout) void
setSessionFactory
(org.hibernate.SessionFactory sessionFactory) void
setSettings
(Settings settings) void
void
setTwoWayKeyFile
(String twoWayKeyFile) org.hibernate.Session
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
createDAO, getInjector, setInjector
-
Field Details
-
log
static org.apache.commons.logging.Log log -
sqlMap
AMap
of SQL statements used by the application. -
moduleList
The list of modules in use by the application inStringTokenizer
form. Modules may include core, product, order, and customer. -
moduleListString
The list of modules in use by the application inString
form. Modules may include core, product, order, and customer. -
dataSource
The application'sDataSource
used for persistent storage. -
dataSourceName
The JNDI name for the application'sDataSource
, if one is set up in the servlet container's configuration. (For example, in server.xml for Tomcat.) -
jndiContext
The JNDI context for the application'sDataSource
, if one is set up in the servlet container's configuration. (For example, in server.xml for Tomcat.) -
databaseDriver
The fully-qualified class name of the database driver used for theDataSource
. -
databaseURL
The URL used for this factory'sDataSource
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 JNDIdataSourceName
andjndiContext
settings. -
databaseUserName
The user name used for this factory'sDataSource
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 JNDIdataSourceName
andjndiContext
settings. -
databasePassword
The password used for this factory'sDataSource
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 JNDIdataSourceName
andjndiContext
settings. -
databaseType
The type of database this factory connects to. For example, "MSSQL" or "MySQL". -
maxIdle
The maximum number of idle connections for the pool used by this factory'sDataSource
, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDIdataSourceName
andjndiContext
settings. -
maxActive
The maximum number of active connections for the pool used by this factory'sDataSource
, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDIdataSourceName
andjndiContext
settings. -
maxWait
The maximum time to wait for a connection to become available in milliseconds, before an exception is thrown. Used by this factory'sDataSource
, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDIdataSourceName
andjndiContext
settings. -
removeAbandoned
If set to true, abandoned connections will be removed and recycled. Used by this factory'sDataSource
, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDIdataSourceName
andjndiContext
settings. -
removeAbandonedTimeout
The number of seconds a connection is idle before it is considered abandoned. Used by this factory'sDataSource
, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDIdataSourceName
andjndiContext
settings. -
paymentPrivateKeyFile
The full path to the file on the server where the private key is stored for key pair encryption. -
paymentPublicKeyFile
The full path to the file on the server where the public key is stored for key pair (RSA) encryption. -
twoWayKeyFile
The full path to the file on the server where the key is stored for two way (DES) encryption. -
settings
Used to look up the Java class names for the various DAO's this factory creates. -
appSettings
-
appComponents
-
appComponentsDefaults
-
hibernateSettings
-
sessionFactory
private org.hibernate.SessionFactory sessionFactory
-
-
Constructor Details
-
BaseDAOFactory
public BaseDAOFactory()
-
-
Method Details
-
getSqlMap
-
setSqlMap
-
getModuleList
-
setModuleList
-
getModuleListString
-
setModuleListString
-
getDataSource
-
setDataSource
-
getDataSourceName
-
setDataSourceName
-
getJndiContext
-
setJndiContext
-
getDatabaseDriver
-
setDatabaseDriver
-
getDatabaseURL
-
setDatabaseURL
-
getDatabaseUserName
-
setDatabaseUserName
-
getDatabasePassword
-
setDatabasePassword
-
getDatabaseType
- Specified by:
getDatabaseType
in interfaceDAOFactory
-
setDatabaseType
- Specified by:
setDatabaseType
in interfaceDAOFactory
-
getMaxIdle
-
setMaxIdle
-
getMaxActive
-
setMaxActive
-
getMaxWait
-
setMaxWait
-
getRemoveAbandoned
-
setRemoveAbandoned
-
getRemoveAbandonedTimeout
-
setRemoveAbandonedTimeout
-
getPaymentPrivateKeyFile
-
setPaymentPrivateKeyFile
-
getPaymentPublicKeyFile
-
setPaymentPublicKeyFile
-
getTwoWayKeyFile
-
setTwoWayKeyFile
-
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
-
setSettings
- Specified by:
setSettings
in interfaceDAOFactory
-
initialize
Initializes thisDAOFactory
. Called byBaseRequestProcessor
.- Specified by:
initialize
in interfaceDAOFactory
- Throws:
Exception
-
initialize
Initializes thisDAOFactory
using the settings defined in the file located at the imcomingsettingLocation
.- Parameters:
settingsLocation
- The location of a file containing database settings.- Throws:
Exception
-
initializeSQLProperties
Reads in the application's SQL statements into this factory'ssqlMap
. Loops through each of the active modules defined in themoduleList
property and reads in the SQL properities from the files in "/WEB-INF/classes/resources.- Throws:
Exception
-
initializeSettings
Loads database settings from a properties file into the properties of thisDAOFactory
.- Parameters:
settingsLocation
- The location of a file containing database settings.
-
getProperties
Loads SQL statements into aProperties
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
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
Load properties from a .properties file represented by the argument, using a givenProperties
object as the default properties.- Parameters:
path
- The path to the .properties file being loaded.defaultProperties
- AProperties
object representing the default properties to be returned.- Returns:
- A
Properties
object representing the contents of the file.
-
initializeDataSource
Initializes this factory'sdataSource
property. This method first attempts to establish aDataSource
based on a JNDI data source name and context defined in the JNDI environment, using thedatasourceName
andjndiContext
properties. If this fails, it will create it's own connection pool using the various other properties defined in this factory, including thedatabaseURL
,databaseUserName
, anddatabasePassword
properties.- Throws:
Exception
-
getJndiDataSource
Looks up aDataSource
object in a JNDI context. Attempts to establish aDataSource
based on a JNDI data source name and context defined in the JNDI environment, using thedatasourceName
andjndiContext
properties.- Specified by:
getJndiDataSource
in interfaceDAOFactory
- Returns:
- A
DataSource
object for the application. - Throws:
Exception
-
getPooledDataSource
Creates a connection pool using various properties defined in this factory. Returns aDataSource
object tied to it.- Returns:
- A
DataSource
object for the application. - Throws:
Exception
-
getTransferMap
Retrieves aMap
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
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
Creates and initializes a data access object for use by the application.- Specified by:
createDAO
in interfaceDAOFactory
- 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
-
createDAOFromClassName
Creates and initializes a data access object for use by the application. Using the incoming class name, appends the value of thedatabaseType
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:com.softslate.commerce.daos.customer.CustomerDAOMSSQL
com.softslate.commerce.daos.customer.CustomerDAOBasic
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 interfaceDAOFactory
- Parameters:
className
- AString
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
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
-
setAppSettings
- Specified by:
setAppSettings
in interfaceDAOFactory
-
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
-
setAppComponents
- Specified by:
setAppComponents
in interfaceDAOFactory
-
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
-
setAppComponentsDefaults
- Specified by:
setAppComponentsDefaults
in interfaceDAOFactory
-
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 interfaceDAOFactory
-
setHibernateSettings
- Specified by:
setHibernateSettings
in interfaceDAOFactory
-
getSessionFactory
public org.hibernate.SessionFactory getSessionFactory()Description copied from interface:DAOFactory
Retrieves this factory's HibernateSessionFactory
.- Specified by:
getSessionFactory
in interfaceDAOFactory
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory) - Specified by:
setSessionFactory
in interfaceDAOFactory
-
startSession
public org.hibernate.Session startSession()- Specified by:
startSession
in interfaceDAOFactory
-
getSession
public org.hibernate.Session getSession()- Specified by:
getSession
in interfaceDAOFactory
-
closeSession
public void closeSession()- Specified by:
closeSession
in interfaceDAOFactory
-
beginTransaction
public void beginTransaction()- Specified by:
beginTransaction
in interfaceDAOFactory
-
commitTransaction
public void commitTransaction() throws org.hibernate.HibernateException- Specified by:
commitTransaction
in interfaceDAOFactory
- Throws:
org.hibernate.HibernateException
-
rollbackTransactionKeepingSessionOpen
public void rollbackTransactionKeepingSessionOpen()- Specified by:
rollbackTransactionKeepingSessionOpen
in interfaceDAOFactory
-
rollbackTransaction
public void rollbackTransaction()- Specified by:
rollbackTransaction
in interfaceDAOFactory
-
evictCache
public void evictCache()- Specified by:
evictCache
in interfaceDAOFactory
-