net.smartlab.web
Class BusinessObjectFactory

java.lang.Object
  extended by net.smartlab.web.BusinessObjectFactory
All Implemented Interfaces:
DataAccessObject
Direct Known Subclasses:
HistorizedBusinessObjectFactory

public abstract class BusinessObjectFactory
extends java.lang.Object
implements DataAccessObject

This class provides basic template for an Hibernate based implementation of the DAO pattern.

Author:
rlogiacco,gperrone

Nested Class Summary
 class BusinessObjectFactory.Paginator
          TODO documentation
 
Nested classes/interfaces inherited from interface net.smartlab.web.DataAccessObject
DataAccessObject.SearchInfo
 
Field Summary
protected  org.hibernate.SessionFactory factory
          Caches a reference to the Hibernate Session Factory to avoid further lookups.
protected  org.apache.commons.logging.Log logger
          Provides logging capabilities to the factory.
 
Constructor Summary
protected BusinessObjectFactory()
          Protected default constructor to allow subclassing.
 
Method Summary
 void begin()
          TODO documentation
static void close()
          Closes the connection to the persistence tier.
 void commit()
          TODO documentation
 java.io.Serializable convertKey(java.io.Serializable key)
          Converts a generic serializable object to the type used as unique key identifier for this type of BusinessObject.
 java.util.Set convertKeys(java.util.Collection keys)
          Converts a generic set of serializable objects to a set containing objects of the type used as unique key identifier for this type of BusinessObject using the convertKey() method.
 org.hibernate.Criteria createCriteria(DataAccessObject.SearchInfo info)
          Creates an Hibernate Criteria instance using filtering and ordering rules defined through the SearchInfo structure.
protected  org.hibernate.Session current()
          Returns the current Hibernate Session.
 java.lang.Object findByKey(java.io.Serializable key)
          Retrieves from the persistence tier the object which primary key equals the one specified.
 java.lang.Object findByKey(java.io.Serializable key, java.lang.String[] fetch)
           
static void flush()
           
abstract  java.lang.Class getMappedClass()
          TODO documentation
 java.util.Collection list(DataAccessObject.SearchInfo info)
          Returns a collection of objects representing all the persistence tier informations matching the specified search criterias.
 java.util.Collection list(DataAccessObject.SearchInfo info, java.lang.String[] fetch)
           
 java.util.Collection listByKeySet(java.util.Set keys, DataAccessObject.SearchInfo info)
          Returns a collection of objects representing all the persistence tier informations matching the specified set of unique identification keys and search criterias.
 java.util.Collection listByKeySet(java.util.Set keys, DataAccessObject.SearchInfo info, boolean exclude)
          Returns a collection of objects representing all the persistence tier informations matching the specified set of unique identification keys and search criterias.
 java.util.Collection listByKeySet(java.lang.String keyFieldName, java.util.Set keys, DataAccessObject.SearchInfo info)
          Deprecated. the keyFieldName parameter is no more needed
 java.util.Collection page(DataAccessObject.SearchInfo info)
          Returns a paginable collection of objects representing all the persistence tier informations matching the specified search criterias.
 java.util.Collection page(DataAccessObject.SearchInfo info, java.lang.String[] fetch)
           
 void remove(java.lang.Object object)
          Permanently deletes an instance from the persistence tier.
 void rollback()
          TODO documentation
static void setConfigurationStrategy(FactoryConfigurationStrategy strategy)
          Changes the strategy used to configure the framework.
 void update(java.lang.Object object)
          Ensures the persistence tier representation of the object is consistent with the in memory representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Provides logging capabilities to the factory.


factory

protected org.hibernate.SessionFactory factory
Caches a reference to the Hibernate Session Factory to avoid further lookups.

Constructor Detail

BusinessObjectFactory

protected BusinessObjectFactory()
Protected default constructor to allow subclassing. Provides the startup initialization and the Hibernate Session Factory lookup. The Hibernate configuration file used must reside into the META-INF directory of the topmost packaging archive and should be named smartweb.jar.hcf or have the name of the JAR file containing the subclass followed by the .hcf suffix. TODO example

Method Detail

setConfigurationStrategy

public static void setConfigurationStrategy(FactoryConfigurationStrategy strategy)
Changes the strategy used to configure the framework.

Parameters:
strategy - an implementation of the FactoryConfigurationStrategy interface.

close

public static void close()
                  throws DAOException
Closes the connection to the persistence tier.

Throws:
DAOException - if the persistence tier generates any error while performing the resource release.

flush

public static void flush()
                  throws DAOException
Throws:
DAOException
To do:
documentation

current

protected org.hibernate.Session current()
                                 throws DAOException
Returns the current Hibernate Session. If a Session was previously established during the same request the already established instance is returned otherwise a new instance is retrieved from the Session Factory.

Returns:
the current connection to the persistence layer or a new one if not previously established.
Throws:
DAOException - if an error occurs trying to establish the connection.

findByKey

public java.lang.Object findByKey(java.io.Serializable key)
                           throws DAOException
Description copied from interface: DataAccessObject
Retrieves from the persistence tier the object which primary key equals the one specified.

Specified by:
findByKey in interface DataAccessObject
Parameters:
key - the primary key used to search the instance into the persistence tier.
Returns:
an object representing the datas stored in the persistence tier associated with the specified key.
Throws:
DAOException - if an error occur while accessing the persistence tier.
UndefinedKeyException - if the specified primary key is not present on the persistence tier.
See Also:
DataAccessObject.findByKey(java.io.Serializable)

findByKey

public java.lang.Object findByKey(java.io.Serializable key,
                                  java.lang.String[] fetch)
                           throws DAOException
Parameters:
key -
fetch -
Returns:
Throws:
DAOException
To do:
documentation

remove

public void remove(java.lang.Object object)
            throws DAOException
Description copied from interface: DataAccessObject
Permanently deletes an instance from the persistence tier.

Specified by:
remove in interface DataAccessObject
Parameters:
object - the instance representing the informations to be deleted from the store.
Throws:
DAOException - if an error occur while accessing the persistence tier.
See Also:
DataAccessObject.remove(java.lang.Object)

update

public void update(java.lang.Object object)
            throws DAOException
Description copied from interface: DataAccessObject
Ensures the persistence tier representation of the object is consistent with the in memory representation. If the object doesn't exist yet into the persistence tier it must be added and a new primary key assigned to the object.

Specified by:
update in interface DataAccessObject
Parameters:
object - the object to be persisted.
Throws:
DAOException - if an error occur while accessing the persistence tier
See Also:
DataAccessObject.update(java.lang.Object)

list

public java.util.Collection list(DataAccessObject.SearchInfo info)
                          throws DAOException
Description copied from interface: DataAccessObject
Returns a collection of objects representing all the persistence tier informations matching the specified search criterias.

Specified by:
list in interface DataAccessObject
Parameters:
info - the criterias to be used to search the persistence tier.
Returns:
a collection of matching entities.
Throws:
DAOException - if an error occur while accessing the persistence tier
See Also:
DataAccessObject.list(net.smartlab.web.DataAccessObject.SearchInfo)

list

public java.util.Collection list(DataAccessObject.SearchInfo info,
                                 java.lang.String[] fetch)
                          throws DAOException
Parameters:
info -
fetch -
Returns:
Throws:
DAOException
To do:
documentation

listByKeySet

public java.util.Collection listByKeySet(java.util.Set keys,
                                         DataAccessObject.SearchInfo info)
                                  throws DAOException
Returns a collection of objects representing all the persistence tier informations matching the specified set of unique identification keys and search criterias.

Parameters:
keys - the set of keys to be matched.
info - the additional criterias to be used to search the persistence tier.
Returns:
a collection of matching entities.
Throws:
DAOException - if an error occur while accessing the persistence tier

listByKeySet

public java.util.Collection listByKeySet(java.lang.String keyFieldName,
                                         java.util.Set keys,
                                         DataAccessObject.SearchInfo info)
                                  throws DAOException
Deprecated. the keyFieldName parameter is no more needed

Returns a collection of objects representing all the persistence tier informations matching the specified set of unique identification keys and search criterias.

Parameters:
keyFieldName - the fieldName to be matched for unique identification key.
keys - the set of keys to be matched.
info - the additional criterias to be used to search the persistence tier.
Returns:
a collection of matching entities.
Throws:
DAOException - if an error occur while accessing the persistence tier
See Also:
listByKeySet(java.util.Set, net.smartlab.web.DataAccessObject.SearchInfo, boolean)

listByKeySet

public java.util.Collection listByKeySet(java.util.Set keys,
                                         DataAccessObject.SearchInfo info,
                                         boolean exclude)
                                  throws DAOException
Returns a collection of objects representing all the persistence tier informations matching the specified set of unique identification keys and search criterias.

Parameters:
keys - the set of keys to be matched.
info - the additional criterias to be used to search the persistence tier.
exclude - if the keys should be included or excluded from the list.
Returns:
a collection of matching entities.
Throws:
DAOException - if an error occur while accessing the persistence tier

page

public java.util.Collection page(DataAccessObject.SearchInfo info)
                          throws DAOException
Returns a paginable collection of objects representing all the persistence tier informations matching the specified search criterias.

Parameters:
info - the criterias to be used filter the instances.
Returns:
a paginable collection of objects matching the specified search criterias.
Throws:
DAOException - if an error occur while accessing the persistence tier

page

public java.util.Collection page(DataAccessObject.SearchInfo info,
                                 java.lang.String[] fetch)
                          throws DAOException
Parameters:
info -
fetch -
Returns:
Throws:
DAOException
To do:
documentation

getMappedClass

public abstract java.lang.Class getMappedClass()
TODO documentation

Returns:

convertKey

public java.io.Serializable convertKey(java.io.Serializable key)
Converts a generic serializable object to the type used as unique key identifier for this type of BusinessObject. The default implementation converts String or Number to Long using the o value to identify non-persisted instances. If your business definition requires a different conversion you should override this method to provide your own conversion strategy.

Parameters:
key - the generic serializable key that needs to be converted.
Returns:
the key representation using the correct type or null if the providen key doesn't represent a valid identifier for a persisted BusinessObject.

convertKeys

public java.util.Set convertKeys(java.util.Collection keys)
Converts a generic set of serializable objects to a set containing objects of the type used as unique key identifier for this type of BusinessObject using the convertKey() method.

Parameters:
keys - the java.util.Set of serializable objects to be converted.
Returns:
a java.util.Set containing appropriately converted keys.

createCriteria

public org.hibernate.Criteria createCriteria(DataAccessObject.SearchInfo info)
                                      throws DAOException
Creates an Hibernate Criteria instance using filtering and ordering rules defined through the SearchInfo structure.

Parameters:
info -
Returns:
Throws:
DAOException

begin

public void begin()
           throws DAOException
TODO documentation

Throws:
DAOException

commit

public void commit()
            throws DAOException
TODO documentation

Throws:
DAOException

rollback

public void rollback()
              throws DAOException
TODO documentation

Throws:
DAOException


Copyright © 2004-2009 The SmartWeb Team. All Rights Reserved.