com.softslate.commerce.daos.core
Class BaseDAO

java.lang.Object
  extended by com.softslate.commerce.daos.core.BaseDAO
All Implemented Interfaces:
DAOInterface
Direct Known Subclasses:
AdministratorDAOHibernate, AttributeDAOHibernate, BaseAdminGatewayDAOHibernate, BasicTaxRateDAOHibernate, CategoryDAOHibernate, CategorySettingDAOHibernate, CountryDAOHibernate, CustomerAddressDAOHibernate, CustomerDAOHibernate, DiscountDAOHibernate, DiscountRangeDAOHibernate, InstallerDAOBasic, ManufacturerDAOHibernate, OptionDAOHibernate, OrderDAOHibernate, OrderDeliveryDAOHibernate, OrderDiscountDAOHibernate, OrderItemAttributeDAOHibernate, OrderItemDAOHibernate, OrderShippingRuleDAOHibernate, PaymentDAOHibernate, ProductDAOHibernate, ProductSettingDAOHibernate, RoleDAOHibernate, SettingsDAOHibernate, ShippingMethodDAOHibernate, ShippingRateDAOHibernate, ShippingRuleDAOHibernate, ShippingRuleRangeDAOHibernate, SKUDAOHibernate, StateDAOHibernate, UpgradesDAOBasic

public abstract class BaseDAO
extends java.lang.Object
implements DAOInterface

Abstract superclass for all objects in the data access layer.

The methods provided allow implementations to communicate with other elements of the application. In particular, retrieve settings (using getSettings()), retrieve database connections (using getConnection()), retrieve SQL statements (using getSqlMap() and getSQL(java.lang.String, java.lang.String)), and create other data access objects (using getDaoFactory()).

Author:
David Tobey

Field Summary
private  java.util.Properties appComponents
           
private  java.util.Properties appSettings
           
private  java.sql.Connection connection
           
private  DAOFactory daoFactory
           
private  DAOUtils daoUtils
           
private  javax.sql.DataSource dataSource
           
private  java.util.Map importExportSqlMap
           
(package private) static org.apache.commons.logging.Log log
           
private  Settings settings
           
private  java.util.Map sqlMap
           
 
Constructor Summary
BaseDAO()
           
 
Method Summary
 boolean deleteObject(java.lang.Object object, boolean commit)
           
 void evictCache()
           
 java.lang.String formatDateTime(java.util.Date dateTime)
          Formats a Date object into a string suitable for storage in the database.
 java.util.Properties getAppComponents()
          Retrieves this factory's component settings.
 java.util.Properties getAppSettings()
          Retrieves this factory's application settings.
 java.sql.Connection getConnection()
          Retrieves a Connection to the application's DataSource.
 DAOFactory getDaoFactory()
          Retrieves the application's DAOFactory.
 DAOUtils getDAOUtils()
          Retrieves a utility object that provides useful methods for daos.
 javax.sql.DataSource getDataSource()
          Retrieves the application's DataSource.
 java.lang.String getImportExportSQL(java.lang.String module, java.lang.String key)
          Returns an SQL statement configured in the .properties files under "/WEB-INF/classes/resources/importexport".
 java.util.Map getImportExportSqlMap()
           
 org.hibernate.Query getNamedQuery(org.hibernate.Session session, java.lang.String queryName)
          Returns a custom named query with the "-custom" suffix if one exists, otherwise returns the normally named query.
 Settings getSettings()
          Retrieves the Settings previously set for this data access object.
 java.lang.String getSQL(java.lang.String module, java.lang.String key)
          Legacy method that returns an SQL statement configured in the .properties files under "/WEB-INF/classes/resources".
 java.util.Map getSqlMap()
          Retrieves a Map of the SQL statements used by the application.
 void initialize(java.util.Map transferMap)
          Initializes this data access object by copying incoming parameters into its properties.
 java.lang.Object insertObject(java.lang.Object object, boolean commit)
           
 java.util.Collection loadAll()
           
 java.util.Collection loadAll(org.hibernate.Filter filter)
           
 java.lang.Object loadObject(java.lang.Object object)
           
 java.util.Date parseDateTime(java.lang.String dateTime)
          Formats a Date object into a string suitable for storage in the database.
 void setAppComponents(java.util.Properties appComponents)
           
 void setAppSettings(java.util.Properties appSettings)
           
 void setConnection(java.sql.Connection connection)
           
 void setDaoFactory(DAOFactory daoFactory)
           
 void setDAOUtils(DAOUtils daoUtils)
           
 void setDataSource(javax.sql.DataSource dataSource)
           
 void setImportExportSqlMap(java.util.Map importExportSqlMap)
           
 void setSettings(Settings settings)
           
 void setSqlMap(java.util.Map sqlMap)
           
 java.lang.Object updateObject(java.lang.Object object, boolean commit)
           
 
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

settings

private Settings settings

appSettings

private java.util.Properties appSettings

appComponents

private java.util.Properties appComponents

dataSource

private javax.sql.DataSource dataSource

connection

private java.sql.Connection connection

sqlMap

private java.util.Map sqlMap

importExportSqlMap

private java.util.Map importExportSqlMap

daoFactory

private DAOFactory daoFactory

daoUtils

private DAOUtils daoUtils
Constructor Detail

BaseDAO

public BaseDAO()
Method Detail

getSettings

public Settings getSettings()
Description copied from interface: DAOInterface
Retrieves the Settings previously set for this data access object.

Specified by:
getSettings in interface DAOInterface
Returns:
A Settings object that represents various settings for the system.

setSettings

public void setSettings(Settings settings)
Specified by:
setSettings in interface DAOInterface

getAppSettings

public java.util.Properties getAppSettings()
Description copied from interface: DAOInterface
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 SettingsBean, which stores settings drawn from the database.

Specified by:
getAppSettings in interface DAOInterface

setAppSettings

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

getAppComponents

public java.util.Properties getAppComponents()
Description copied from interface: DAOInterface
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 DAOInterface

setAppComponents

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

getDataSource

public javax.sql.DataSource getDataSource()
Description copied from interface: DAOInterface
Retrieves the application's DataSource.

Specified by:
getDataSource in interface DAOInterface
Returns:
The application's DataSource.

setDataSource

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

getConnection

public java.sql.Connection getConnection()
Description copied from interface: DAOInterface
Retrieves a Connection to the application's DataSource.

Specified by:
getConnection in interface DAOInterface
Returns:
A Connection to the application's DataSource.

setConnection

public void setConnection(java.sql.Connection connection)
Specified by:
setConnection in interface DAOInterface

getSqlMap

public java.util.Map getSqlMap()
Description copied from interface: DAOInterface
Retrieves a Map of the SQL statements used by the application.

Specified by:
getSqlMap in interface DAOInterface
Returns:
A Map of the SQL statements used by the application.

setSqlMap

public void setSqlMap(java.util.Map sqlMap)
Specified by:
setSqlMap in interface DAOInterface

getImportExportSqlMap

public java.util.Map getImportExportSqlMap()

setImportExportSqlMap

public void setImportExportSqlMap(java.util.Map importExportSqlMap)

getDaoFactory

public DAOFactory getDaoFactory()
Description copied from interface: DAOInterface
Retrieves the application's DAOFactory.

Specified by:
getDaoFactory in interface DAOInterface
Returns:
The application's DAOFactory.

setDaoFactory

public void setDaoFactory(DAOFactory daoFactory)
Specified by:
setDaoFactory in interface DAOInterface

initialize

public void initialize(java.util.Map transferMap)
                throws java.lang.Exception
Description copied from interface: DAOInterface
Initializes this data access object by copying incoming parameters into its properties. This method is used by DAOFactory after object creation to copy the application's DAOFactory and Settings into the new object. The sqlMap and dataSource properties are also copied from the DAOFactory.

Specified by:
initialize in interface DAOInterface
Parameters:
transferMap - A Map containing objects such as the application's DAOFactory and Settings.
Throws:
java.lang.Exception

getSQL

public java.lang.String getSQL(java.lang.String module,
                               java.lang.String key)
                        throws java.lang.Exception
Legacy method that returns an SQL statement configured in the .properties files under "/WEB-INF/classes/resources".

Parameters:
module - The application module corresponding to the desired SQL statement, such as "core", "product", "order", or "customer".
key - A string key for the SQL statement corresponding to the keys in the .properties files.
Returns:
An SQL statement, or null if the requested statement could not be found.
Throws:
java.lang.Exception

getImportExportSQL

public java.lang.String getImportExportSQL(java.lang.String module,
                                           java.lang.String key)
                                    throws java.lang.Exception
Returns an SQL statement configured in the .properties files under "/WEB-INF/classes/resources/importexport".

Parameters:
module - The application module corresponding to the desired SQL statement. Must be "importexport".
key - A string key for the SQL statement corresponding to the keys in the .properties files.
Returns:
An SQL statement, or null if the requested statement could not be found.
Throws:
java.lang.Exception

formatDateTime

public java.lang.String formatDateTime(java.util.Date dateTime)
Formats a Date object into a string suitable for storage in the database.

Parameters:
dateTime -
Returns:
a String in the form of "yyyy-MM-dd HH:mm:ss:SSS" suitable for storage in the database.

parseDateTime

public java.util.Date parseDateTime(java.lang.String dateTime)
                             throws java.lang.Exception
Formats a Date object into a string suitable for storage in the database.

Parameters:
dateTime -
Returns:
a String in the form of "yyyy-MM-dd HH:mm:ss:SSS" suitable for storage in the database.
Throws:
java.lang.Exception

getDAOUtils

public DAOUtils getDAOUtils()
Description copied from interface: DAOInterface
Retrieves a utility object that provides useful methods for daos.

Specified by:
getDAOUtils in interface DAOInterface
Returns:
An implementation of DAOUtils.

setDAOUtils

public void setDAOUtils(DAOUtils daoUtils)
Specified by:
setDAOUtils in interface DAOInterface

getNamedQuery

public org.hibernate.Query getNamedQuery(org.hibernate.Session session,
                                         java.lang.String queryName)
                                  throws org.hibernate.HibernateException
Returns a custom named query with the "-custom" suffix if one exists, otherwise returns the normally named query.

Named queries can be overridden by creating a new query in one of the queries-custom.hbm.xml files. The new query must have the same name as the query it's replacing, but with "-custom" appended to the name. This method looks to see if a custom query exists before returning the regular query.

Parameters:
session - The current Hibernate session.
queryName - The name of the query to return (without the "-custom" suffix).
Returns:
A Query object.
Throws:
org.hibernate.HibernateException

evictCache

public void evictCache()

loadObject

public java.lang.Object loadObject(java.lang.Object object)
                            throws java.lang.Exception
Specified by:
loadObject in interface DAOInterface
Throws:
java.lang.Exception

updateObject

public java.lang.Object updateObject(java.lang.Object object,
                                     boolean commit)
                              throws java.lang.Exception
Specified by:
updateObject in interface DAOInterface
Throws:
java.lang.Exception

deleteObject

public boolean deleteObject(java.lang.Object object,
                            boolean commit)
                     throws java.lang.Exception
Specified by:
deleteObject in interface DAOInterface
Throws:
java.lang.Exception

insertObject

public java.lang.Object insertObject(java.lang.Object object,
                                     boolean commit)
                              throws java.lang.Exception
Specified by:
insertObject in interface DAOInterface
Throws:
java.lang.Exception

loadAll

public java.util.Collection loadAll()
                             throws java.lang.Exception
Specified by:
loadAll in interface DAOInterface
Throws:
java.lang.Exception

loadAll

public java.util.Collection loadAll(org.hibernate.Filter filter)
                             throws java.lang.Exception
Specified by:
loadAll in interface DAOInterface
Throws:
java.lang.Exception


Copyright ? SoftSlate, LLC 2003?2005