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 Propertiesprivate Propertiesprivate Propertiesprivate StringThe fully-qualified class name of the database driver used for theDataSource.private StringThe password used for this factory'sDataSourcedatabase connection, if the built-in connection pooling is used.private StringThe type of database this factory connects to.private StringThe URL used for this factory'sDataSourcedatabase connection, if the built-in connection pooling is used.private StringThe user name used for this factory'sDataSourcedatabase connection, if the built-in connection pooling is used.private DataSourceThe application'sDataSourceused for persistent storage.private StringThe JNDI name for the application'sDataSource, if one is set up in the servlet container's configuration.private Propertiesprivate StringThe JNDI context for the application'sDataSource, if one is set up in the servlet container's configuration.(package private) static org.apache.commons.logging.Logprivate StringThe maximum number of active connections for the pool used by this factory'sDataSource, if the built-in connection pooling is used.private StringThe maximum number of idle connections for the pool used by this factory'sDataSource, if the built-in connection pooling is used.private StringThe maximum time to wait for a connection to become available in milliseconds, before an exception is thrown.private StringTokenizerThe list of modules in use by the application inStringTokenizerform.static StringThe list of modules in use by the application inStringform.private StringThe full path to the file on the server where the private key is stored for key pair encryption.private StringThe full path to the file on the server where the public key is stored for key pair (RSA) encryption.private StringIf set to true, abandoned connections will be removed and recycled.private StringThe number of seconds a connection is idle before it is considered abandoned.private org.hibernate.SessionFactoryprivate SettingsUsed to look up the Java class names for the various DAO's this factory creates.private MapAMapof SQL statements used by the application.private StringThe 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 TypeMethodDescriptionvoidvoidvoidCreates 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.voidRetrieves 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 aDataSourceobject in a JNDI context.Creates a connection pool using various properties defined in this factory.getProperties(String databaseType, String module) Loads SQL statements into aPropertiesobject for a given database type.org.hibernate.Sessionorg.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.voidinitialize(String settingsLocation) Initializes thisDAOFactoryusing the settings defined in the file located at the imcomingsettingLocation.voidInitializes this factory'sdataSourceproperty.voidinitializeSettings(String settingsLocation) Loads database settings from a properties file into the properties of thisDAOFactory.voidReads 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 givenPropertiesobject as the default properties.voidvoidvoidsetAppComponents(Properties appComponents) voidsetAppComponentsDefaults(Properties appComponentsDefaults) voidsetAppSettings(Properties appSettings) voidsetDatabaseDriver(String databaseDriver) voidsetDatabasePassword(String databasePassword) voidsetDatabaseType(String databaseType) voidsetDatabaseURL(String databaseURL) voidsetDatabaseUserName(String databaseUserName) voidsetDataSource(DataSource dataSource) voidsetDataSourceName(String dataSourceName) voidsetHibernateSettings(Properties hibernateSettings) voidsetJndiContext(String jndiContext) voidsetMaxActive(String maxActive) voidsetMaxIdle(String maxIdle) voidsetMaxWait(String maxWait) voidsetModuleList(StringTokenizer moduleList) voidsetModuleListString(String moduleList) voidsetPaymentPrivateKeyFile(String paymentPrivateKeyFile) voidsetPaymentPublicKeyFile(String paymentPublicKeyFile) voidsetRemoveAbandoned(String removeAbandoned) voidsetRemoveAbandonedTimeout(String removeAbandonedTimeout) voidsetSessionFactory(org.hibernate.SessionFactory sessionFactory) voidsetSettings(Settings settings) voidvoidsetTwoWayKeyFile(String twoWayKeyFile) org.hibernate.SessionMethods 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
createDAO, getInjector, setInjector
-
Field Details
-
log
static org.apache.commons.logging.Log log -
sqlMap
AMapof SQL statements used by the application. -
moduleList
The list of modules in use by the application inStringTokenizerform. Modules may include core, product, order, and customer. -
moduleListString
The list of modules in use by the application inStringform. Modules may include core, product, order, and customer. -
dataSource
The application'sDataSourceused 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'sDataSourcedatabase connection, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDIdataSourceNameandjndiContextsettings. -
databaseUserName
The user name used for this factory'sDataSourcedatabase connection, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDIdataSourceNameandjndiContextsettings. -
databasePassword
The password used for this factory'sDataSourcedatabase connection, if the built-in connection pooling is used. This factory will use its own connection pooling if it fails to connect using the JNDIdataSourceNameandjndiContextsettings. -
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 JNDIdataSourceNameandjndiContextsettings. -
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 JNDIdataSourceNameandjndiContextsettings. -
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 JNDIdataSourceNameandjndiContextsettings. -
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 JNDIdataSourceNameandjndiContextsettings. -
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 JNDIdataSourceNameandjndiContextsettings. -
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:
getDatabaseTypein interfaceDAOFactory
-
setDatabaseType
- Specified by:
setDatabaseTypein interfaceDAOFactory
-
getMaxIdle
-
setMaxIdle
-
getMaxActive
-
setMaxActive
-
getMaxWait
-
setMaxWait
-
getRemoveAbandoned
-
setRemoveAbandoned
-
getRemoveAbandonedTimeout
-
setRemoveAbandonedTimeout
-
getPaymentPrivateKeyFile
-
setPaymentPrivateKeyFile
-
getPaymentPublicKeyFile
-
setPaymentPublicKeyFile
-
getTwoWayKeyFile
-
setTwoWayKeyFile
-
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
-
setSettings
- Specified by:
setSettingsin interfaceDAOFactory
-
initialize
Initializes thisDAOFactory. Called byBaseRequestProcessor.- Specified by:
initializein interfaceDAOFactory- Throws:
Exception
-
initialize
Initializes thisDAOFactoryusing 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 themoduleListproperty 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 aPropertiesobject 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
Propertiesobject 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
Propertiesobject representing the contents of the file.
-
loadProperties
Load properties from a .properties file represented by the argument, using a givenPropertiesobject as the default properties.- Parameters:
path- The path to the .properties file being loaded.defaultProperties- APropertiesobject representing the default properties to be returned.- Returns:
- A
Propertiesobject representing the contents of the file.
-
initializeDataSource
Initializes this factory'sdataSourceproperty. This method first attempts to establish aDataSourcebased on a JNDI data source name and context defined in the JNDI environment, using thedatasourceNameandjndiContextproperties. If this fails, it will create it's own connection pool using the various other properties defined in this factory, including thedatabaseURL,databaseUserName, anddatabasePasswordproperties.- Throws:
Exception
-
getJndiDataSource
Looks up aDataSourceobject in a JNDI context. Attempts to establish aDataSourcebased on a JNDI data source name and context defined in the JNDI environment, using thedatasourceNameandjndiContextproperties.- Specified by:
getJndiDataSourcein interfaceDAOFactory- Returns:
- A
DataSourceobject for the application. - Throws:
Exception
-
getPooledDataSource
Creates a connection pool using various properties defined in this factory. Returns aDataSourceobject tied to it.- Returns:
- A
DataSourceobject for the application. - Throws:
Exception
-
getTransferMap
Retrieves aMapof properties that will be transfered to each of the data access objects this factory creates.- Returns:
- A
Mapof 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
nullif initialization failed. - Throws:
Exception
-
createDAO
Creates and initializes a data access object for use by the application.- Specified by:
createDAOin interfaceDAOFactory- 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
-
createDAOFromClassName
Creates and initializes a data access object for use by the application. Using the incoming class name, appends the value of thedatabaseTypeproperty 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.CustomerDAOMSSQLcom.softslate.commerce.daos.customer.CustomerDAOBasiccom.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:
createDAOFromClassNamein interfaceDAOFactory- Parameters:
className- AStringrepresenting 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
-
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
-
setAppSettings
- Specified by:
setAppSettingsin interfaceDAOFactory
-
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
-
setAppComponents
- Specified by:
setAppComponentsin interfaceDAOFactory
-
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
-
setAppComponentsDefaults
- Specified by:
setAppComponentsDefaultsin interfaceDAOFactory
-
getHibernateSettings
Description copied from interface:DAOFactoryRetrieves 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:
getHibernateSettingsin interfaceDAOFactory
-
setHibernateSettings
- Specified by:
setHibernateSettingsin interfaceDAOFactory
-
getSessionFactory
public org.hibernate.SessionFactory getSessionFactory()Description copied from interface:DAOFactoryRetrieves this factory's HibernateSessionFactory.- Specified by:
getSessionFactoryin interfaceDAOFactory
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory) - Specified by:
setSessionFactoryin interfaceDAOFactory
-
startSession
public org.hibernate.Session startSession()- Specified by:
startSessionin interfaceDAOFactory
-
getSession
public org.hibernate.Session getSession()- Specified by:
getSessionin interfaceDAOFactory
-
closeSession
public void closeSession()- Specified by:
closeSessionin interfaceDAOFactory
-
beginTransaction
public void beginTransaction()- Specified by:
beginTransactionin interfaceDAOFactory
-
commitTransaction
public void commitTransaction() throws org.hibernate.HibernateException- Specified by:
commitTransactionin interfaceDAOFactory- Throws:
org.hibernate.HibernateException
-
rollbackTransactionKeepingSessionOpen
public void rollbackTransactionKeepingSessionOpen()- Specified by:
rollbackTransactionKeepingSessionOpenin interfaceDAOFactory
-
rollbackTransaction
public void rollbackTransaction()- Specified by:
rollbackTransactionin interfaceDAOFactory
-
evictCache
public void evictCache()- Specified by:
evictCachein interfaceDAOFactory
-