com.ferri.persistence.dao.commons
Class GenericBaseDAOImpl<E extends BaseVO,PK extends Serializable>

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.hibernate3.support.HibernateDaoSupport
          extended by com.ferri.persistence.dao.commons.GenericBaseDAOImpl<E,PK>
All Implemented Interfaces:
Initializable, GenericBaseDAO<E,PK>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
BaseAdministradorDAO, BaseClientDAO, BaseConstantsDAO, BaseContadorDAO, BaseContracteDAO, BaseEstatDAO, BaseFacturaDAO, BaseGestoriaDAO, BaseIntervencioDAO, BasePressupostDAO, BaseTipusClientDAO, BaseTipusPeriodeDAO

public abstract class GenericBaseDAOImpl<E extends BaseVO,PK extends Serializable>
extends org.springframework.orm.hibernate3.support.HibernateDaoSupport
implements GenericBaseDAO<E,PK>

Author:
dferri

Field Summary
private  Class<E> internalClassType
           
protected  org.apache.log4j.Logger logger
           
 
Fields inherited from interface com.ferri.persistence.dao.commons.GenericBaseDAO
ORDER_BY, SEPARATOR_COMMA, SEPARATOR_DOT
 
Constructor Summary
GenericBaseDAOImpl()
           
 
Method Summary
 Collection<E> create(Collection<E> entities)
          Persist the given transient collection instance, first assigning a generated identifier.
 PK create(E entity)
          Persist the given transient instance, first assigning a generated identifier.
 Collection<E> find(String queryString, Object[] values)
          find Entity instances.
 Collection<E> findByCriteria(org.hibernate.criterion.DetachedCriteria criteria)
          findByExample Entity instances.
 Collection<E> findByExample(E entity)
          findByExample Entity instances.
 org.hibernate.criterion.DetachedCriteria getCriteria()
          Obtain a criteria for the entity class
 Class<E> getEntityClass()
          Specify a Class entity.
protected  String getEntityClassName()
           
 String getQueryOrderedBy(String entityName, String query, org.hibernate.criterion.Order... orders)
          Contruct order by from entityName, query and OrderOrder
protected  String headEntityClassNameTo(String message)
          Append the message after the Entity Class Name.
 void initialize()
          Execute the first operations to complete the instanciation.
private  void initiateEntityType()
           
 E load(PK key)
          Loads a Entity instance by identifier.
 Collection<E> loadAll()
          Return all objects related to the implementation of this DAO with no filter.
 Collection<E> loadAllOrderBy(org.hibernate.criterion.Order... orders)
          Return all objects related to the implementation of this DAO with no filter and ordered by orders.
 Collection<E> loadAllOrderby(String propertyName, Boolean ascending)
          Return all objects related to the implementation of this DAO with no filter, ordered by propertyName and ascending.
 void remove(Collection<E> entities)
          Removes all entities in the given entities collection.
 void remove(E entity)
          Remove a persistent instance from the datastore.
 void removeByPk(PK id)
          Remove a persistent instance from the datastore.
 void save(E entity)
          Save the persistent state associated with the given identifier.
 void saveOrUpdate(Collection<E> entities)
          saveOrUpdate the persistent collection state associated with the given identifier.
 void saveOrUpdate(E entity)
          saveOrUpdate the persistent state associated with the given identifier.
 void update(E entity)
          Update a persistent instance from the datastore.
 
Methods inherited from class org.springframework.orm.hibernate3.support.HibernateDaoSupport
checkDaoConfig, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.apache.log4j.Logger logger

internalClassType

private Class<E extends BaseVO> internalClassType
Constructor Detail

GenericBaseDAOImpl

public GenericBaseDAOImpl()
Method Detail

getEntityClass

public Class<E> getEntityClass()
Specify a Class entity.

Returns:
a Class entity.

initiateEntityType

private void initiateEntityType()
                         throws GenericClassNotFound,
                                GenericTypeNotFound
Throws:
GenericClassNotFound - if the given class dont have the expected parent class
GenericTypeNotFound - if the given type is not found

initialize

public void initialize()
                throws GenericClassNotFound,
                       GenericTypeNotFound
Description copied from interface: Initializable
Execute the first operations to complete the instanciation.

Specified by:
initialize in interface Initializable
Throws:
GenericClassNotFound - if the given class dont have the expected parent class
GenericTypeNotFound - if the given type is not found
See Also:
Initializable.initialize()

getEntityClassName

protected String getEntityClassName()
Returns:
Return the Entity Class Name.

headEntityClassNameTo

protected String headEntityClassNameTo(String message)
Append the message after the Entity Class Name.

Parameters:
message - the message to append.
Returns:
Return the Entity Class Name with the message appended.

getCriteria

public org.hibernate.criterion.DetachedCriteria getCriteria()
Description copied from interface: GenericBaseDAO
Obtain a criteria for the entity class

Specified by:
getCriteria in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Returns:
a criteria for the entity class.

getQueryOrderedBy

public String getQueryOrderedBy(String entityName,
                                String query,
                                org.hibernate.criterion.Order... orders)
Contruct order by from entityName, query and OrderOrder

Specified by:
getQueryOrderedBy in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entityName - the entity name
query - the query
orders - the orders
Returns:
the resulted orderby

load

public E load(PK key)
Description copied from interface: GenericBaseDAO
Loads a Entity instance by identifier.

Specified by:
load in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Returns:
Entity the requested instance.

loadAll

public Collection<E> loadAll()
Description copied from interface: GenericBaseDAO
Return all objects related to the implementation of this DAO with no filter.

Specified by:
loadAll in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Returns:
Collection all non filtered objects.

loadAllOrderby

public Collection<E> loadAllOrderby(String propertyName,
                                    Boolean ascending)
Description copied from interface: GenericBaseDAO
Return all objects related to the implementation of this DAO with no filter, ordered by propertyName and ascending.

Specified by:
loadAllOrderby in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Returns:
Collection all non filtered objects.

loadAllOrderBy

public Collection<E> loadAllOrderBy(org.hibernate.criterion.Order... orders)
Description copied from interface: GenericBaseDAO
Return all objects related to the implementation of this DAO with no filter and ordered by orders.

Specified by:
loadAllOrderBy in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Returns:
Collection all non filtered objects.

findByExample

public Collection<E> findByExample(E entity)
Description copied from interface: GenericBaseDAO
findByExample Entity instances.

Specified by:
findByExample in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entity - the identifier
Returns:
Collection all filtered objects.

find

public Collection<E> find(String queryString,
                          Object[] values)
Description copied from interface: GenericBaseDAO
find Entity instances.

Specified by:
find in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Returns:
Collection all filtered objects.

findByCriteria

public Collection<E> findByCriteria(org.hibernate.criterion.DetachedCriteria criteria)
Description copied from interface: GenericBaseDAO
findByExample Entity instances.

Specified by:
findByCriteria in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Returns:
Collection all filtered objects.

create

public PK create(E entity)
Description copied from interface: GenericBaseDAO
Persist the given transient instance, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.)

Specified by:
create in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entity - a transient instance of a persistent class.
Returns:
the class identifier.

create

public Collection<E> create(Collection<E> entities)
Description copied from interface: GenericBaseDAO
Persist the given transient collection instance, first assigning a generated identifier. (Or using the current value of the identifier property if the assigned generator is used.)

Specified by:
create in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entities - the collection to persist.
Returns:
Collection the created entities.

saveOrUpdate

public void saveOrUpdate(E entity)
Description copied from interface: GenericBaseDAO
saveOrUpdate the persistent state associated with the given identifier. An exception is thrown if there is a persistent instance with the same identifier in the current session.

Specified by:
saveOrUpdate in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entity - a transient instance containing saved Or Updated state.

saveOrUpdate

public void saveOrUpdate(Collection<E> entities)
Description copied from interface: GenericBaseDAO
saveOrUpdate the persistent collection state associated with the given identifier. An exception is thrown if there is a persistent instance with the same identifier in the current session.

Specified by:
saveOrUpdate in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entities - the collection to saveOrUpdate.

save

public void save(E entity)
Description copied from interface: GenericBaseDAO
Save the persistent state associated with the given identifier. An exception is thrown if there is a persistent instance with the same identifier in the current session.

Specified by:
save in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entity - a transient instance containing saved Or Updated state.

update

public void update(E entity)
Description copied from interface: GenericBaseDAO
Update a persistent instance from the datastore. The argument may be an instance associated with the receiving Session or a transient instance with an identifier associated with existing persistent state.

Specified by:
update in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entity - the instance to be updated.

removeByPk

public void removeByPk(PK id)
Description copied from interface: GenericBaseDAO
Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving Session or a transient instance with an identifier associated with existing persistent state.

Specified by:
removeByPk in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
id - the instance ID to be removed.

remove

public void remove(E entity)
Description copied from interface: GenericBaseDAO
Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving Session or a transient instance with an identifier associated with existing persistent state.

Specified by:
remove in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entity - the instance to be removed.

remove

public void remove(Collection<E> entities)
Description copied from interface: GenericBaseDAO
Removes all entities in the given entities collection.

Specified by:
remove in interface GenericBaseDAO<E extends BaseVO,PK extends Serializable>
Parameters:
entities - the collection remove.