net.sf.derquinsej.hib3
Class GenericDAOImpl<T,ID extends Serializable>

java.lang.Object
  extended by net.sf.derquinsej.hib3.AbstractDAOImpl
      extended by net.sf.derquinsej.hib3.GenericDAOImpl<T,ID>
All Implemented Interfaces:
DAO, GenericDAO<T,ID>

public abstract class GenericDAOImpl<T,ID extends Serializable>
extends AbstractDAOImpl
implements GenericDAO<T,ID>

Implementation of the Generic DAO.

Author:
Andres Rodriguez

Constructor Summary
GenericDAOImpl()
          Constructs the DAO
GenericDAOImpl(Class<T> persistentClass)
          Constructs the DAO.
GenericDAOImpl(Class<T> persistentClass, org.hibernate.SessionFactory sessionFactory)
          Constructs the DAO.
GenericDAOImpl(org.hibernate.SessionFactory sessionFactory)
          Constructs the DAO
 
Method Summary
 void delete(T entity)
          Deletes an entity instance.
 void deleteById(ID id)
          Deletes an entity instance.
 List<T> findAll()
          Returns all entities of the persistent type.
protected  List<T> findByCriteria(org.hibernate.criterion.Criterion... criterion)
          Returns the list of entity instances that matches the provided crtieria.
 T findById(ID id, boolean lock)
          Finds an entity by ID.
protected  T first(org.hibernate.Query query)
          Returns the first result of a query returning instances of the persisted class.
protected  Class<T> getPersistentClass()
          Returns the persistent class.
protected  List<T> list(org.hibernate.Query query)
          Returns the results of a query as a list of the persisted class.
protected  org.hibernate.Criteria newCriteria()
          Returns a new criteria object.
 T save(T entity)
          Saves an entity.
 T saveOrUpdate(T entity)
          Saves or updates an entity, depending upon resolution of the unsaved-value checks.
protected  T unique(org.hibernate.Query query)
          Returns the unique result of a query returning instances of the persisted class.
 T update(T entity)
          Updates an entity.
 
Methods inherited from class net.sf.derquinsej.hib3.AbstractDAOImpl
clear, evict, first, flush, getNamedQuery, getSession, list, list, setSessionFactory, sync, unique, unique
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.derquinsej.hib3.DAO
clear, flush, sync
 

Constructor Detail

GenericDAOImpl

public GenericDAOImpl(org.hibernate.SessionFactory sessionFactory)
Constructs the DAO

Parameters:
sessionFactory - Hibernate Session factory.

GenericDAOImpl

public GenericDAOImpl(Class<T> persistentClass,
                      org.hibernate.SessionFactory sessionFactory)
Constructs the DAO.

Parameters:
persistentClass - Persistent class.
sessionFactory - Hibernate Session factory.

GenericDAOImpl

public GenericDAOImpl()
Constructs the DAO


GenericDAOImpl

public GenericDAOImpl(Class<T> persistentClass)
Constructs the DAO.

Parameters:
persistentClass - Persistent class.
Method Detail

getPersistentClass

protected final Class<T> getPersistentClass()
Returns the persistent class.

Returns:
The persistent class.

delete

public void delete(T entity)
Description copied from interface: GenericDAO
Deletes an entity instance.

Specified by:
delete in interface GenericDAO<T,ID extends Serializable>
Parameters:
entity - Instance to delete.

deleteById

public void deleteById(ID id)
Description copied from interface: GenericDAO
Deletes an entity instance.

Specified by:
deleteById in interface GenericDAO<T,ID extends Serializable>
Parameters:
id - Id of the instance to delete.

findAll

public List<T> findAll()
Description copied from interface: GenericDAO
Returns all entities of the persistent type.

Specified by:
findAll in interface GenericDAO<T,ID extends Serializable>
Returns:
A list with all the instances.

findById

public T findById(ID id,
                  boolean lock)
Description copied from interface: GenericDAO
Finds an entity by ID.

Specified by:
findById in interface GenericDAO<T,ID extends Serializable>
Parameters:
id - ID
lock - If the entity shall be locked.
Returns:
The requested entity or null if it is not found.

save

public T save(T entity)
Description copied from interface: GenericDAO
Saves an entity.

Specified by:
save in interface GenericDAO<T,ID extends Serializable>
Parameters:
entity - Entity to save.
Returns:
The persisted entity.

saveOrUpdate

public T saveOrUpdate(T entity)
Description copied from interface: GenericDAO
Saves or updates an entity, depending upon resolution of the unsaved-value checks.

Specified by:
saveOrUpdate in interface GenericDAO<T,ID extends Serializable>
Parameters:
entity - Entity to persist.
Returns:
The persisted entity.

update

public T update(T entity)
Description copied from interface: GenericDAO
Updates an entity.

Specified by:
update in interface GenericDAO<T,ID extends Serializable>
Parameters:
entity - Entity to update.
Returns:
The persisted entity.

newCriteria

protected final org.hibernate.Criteria newCriteria()
Returns a new criteria object.

Returns:
A new criteria object.

findByCriteria

protected final List<T> findByCriteria(org.hibernate.criterion.Criterion... criterion)
Returns the list of entity instances that matches the provided crtieria.

Parameters:
criterion - Search criteria.
Returns:
The results.

list

protected final List<T> list(org.hibernate.Query query)
Returns the results of a query as a list of the persisted class.

Parameters:
query - Query to execute.
Returns:
The results.

first

protected final T first(org.hibernate.Query query)
Returns the first result of a query returning instances of the persisted class.

Parameters:
query - Query to execute.
Returns:
The first result or null if there are no results.

unique

protected final T unique(org.hibernate.Query query)
Returns the unique result of a query returning instances of the persisted class.

Parameters:
query - Query to execute.
Returns:
The unique result or null if there are no results.
Throws:
org.hibernate.NonUniqueResultException - if there are more than one result.


Copyright © 2011. All Rights Reserved.