br.com.arsmachina.dao.hibernate
Class GenericDAOImpl<T,K extends Serializable>

java.lang.Object
  extended by br.com.arsmachina.dao.hibernate.GenericDAOImpl<T,K>
Type Parameters:
T - the entity class related to this DAO.
K - the type of the field that represents the entity class' primary key.
All Implemented Interfaces:
br.com.arsmachina.dao.DAO<T,K>, br.com.arsmachina.dao.ReadableDAO<T,K>, br.com.arsmachina.dao.WriteableDAO<T,K>
Direct Known Subclasses:
ConcreteDAOImpl

public class GenericDAOImpl<T,K extends Serializable>
extends Object
implements br.com.arsmachina.dao.DAO<T,K>

AbstractDAO implementation using Hibernate. All methods use getSession() to get a Session. All methods delegate its calls to an internal ReadableDAOImpl or WriteableDAOImpl instance.

Author:
Thiago H. de Paula Figueiredo

Constructor Summary
GenericDAOImpl(org.hibernate.SessionFactory sessionFactory)
          Single public constructor.
 
Method Summary
protected  void addSortCriteria(org.hibernate.Criteria criteria)
          Invokes readableDAO.addSortCriteria().
 void addSortCriteria(org.hibernate.Criteria criteria, br.com.arsmachina.dao.SortCriterion... sortCriteria)
          Invokes delegate.addSortCriteria().
 int countAll()
           
protected  org.hibernate.Criteria createCriteria()
          Invokes readableDAO.createCriteria().
 org.hibernate.Criteria createCriteria(int firstIndex, int maximumResults, br.com.arsmachina.dao.SortCriterion... sortCriteria)
          Invokes delegate.createCriteria().
protected  org.hibernate.Criteria createCriteria(br.com.arsmachina.dao.SortCriterion... sortCriteria)
          Invokes delegate.createCriteria().
protected  org.hibernate.criterion.Example createExample(T entity)
          Invokes readableDAO.createExample().
 void delete(K id)
           
 void delete(T object)
           
 void evict(T object)
           
 List<T> findAll()
           
 List<T> findAll(int firstResult, int maximumResults, br.com.arsmachina.dao.SortCriterion... sortingConstraints)
           
 List<T> findByExample(T example)
           
 T findById(K id)
           
 List<T> findByIds(K... ids)
           
protected  org.hibernate.metadata.ClassMetadata getClassMetadata()
          Returns the ClassMetadata for the corresponding entity class.
 br.com.arsmachina.dao.SortCriterion[] getDefaultSortCriteria()
           
protected  Class<T> getEntityClass()
          Returns the entity class handled by this DAO.
 String getPrimaryKeyPropertyName()
          Returns the name of the property.
protected  org.hibernate.classic.Session getSession()
          Returns a Session.
protected  org.hibernate.SessionFactory getSessionFactory()
          Returns this DAO's SessionFactory.
 boolean isPersistent(T object)
           
 T reattach(T object)
           
 void refresh(T object)
           
 void save(T object)
           
 T update(T object)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericDAOImpl

public GenericDAOImpl(org.hibernate.SessionFactory sessionFactory)
Single public constructor.

Parameters:
sessionFactory - a SessionFactory. It cannot be null.
Method Detail

countAll

public int countAll()
Specified by:
countAll in interface br.com.arsmachina.dao.ReadableDAO<T,K extends Serializable>

findAll

public List<T> findAll()
Specified by:
findAll in interface br.com.arsmachina.dao.ReadableDAO<T,K extends Serializable>

findAll

public List<T> findAll(int firstResult,
                       int maximumResults,
                       br.com.arsmachina.dao.SortCriterion... sortingConstraints)
Specified by:
findAll in interface br.com.arsmachina.dao.ReadableDAO<T,K extends Serializable>

findByExample

public List<T> findByExample(T example)
Specified by:
findByExample in interface br.com.arsmachina.dao.ReadableDAO<T,K extends Serializable>

findById

public T findById(K id)
Specified by:
findById in interface br.com.arsmachina.dao.ReadableDAO<T,K extends Serializable>

findByIds

public List<T> findByIds(K... ids)
Specified by:
findByIds in interface br.com.arsmachina.dao.ReadableDAO<T,K extends Serializable>

refresh

public void refresh(T object)
Specified by:
refresh in interface br.com.arsmachina.dao.ReadableDAO<T,K extends Serializable>

delete

public void delete(T object)
Specified by:
delete in interface br.com.arsmachina.dao.WriteableDAO<T,K extends Serializable>

delete

public void delete(K id)
Specified by:
delete in interface br.com.arsmachina.dao.WriteableDAO<T,K extends Serializable>

evict

public void evict(T object)
Specified by:
evict in interface br.com.arsmachina.dao.WriteableDAO<T,K extends Serializable>

isPersistent

public boolean isPersistent(T object)
Specified by:
isPersistent in interface br.com.arsmachina.dao.WriteableDAO<T,K extends Serializable>

save

public void save(T object)
Specified by:
save in interface br.com.arsmachina.dao.WriteableDAO<T,K extends Serializable>

update

public T update(T object)
Specified by:
update in interface br.com.arsmachina.dao.WriteableDAO<T,K extends Serializable>

reattach

public T reattach(T object)
Specified by:
reattach in interface br.com.arsmachina.dao.ReadableDAO<T,K extends Serializable>

getDefaultSortCriteria

public br.com.arsmachina.dao.SortCriterion[] getDefaultSortCriteria()
Specified by:
getDefaultSortCriteria in interface br.com.arsmachina.dao.ReadableDAO<T,K extends Serializable>

addSortCriteria

protected void addSortCriteria(org.hibernate.Criteria criteria)
Invokes readableDAO.addSortCriteria().

Parameters:
criteria -
See Also:
ReadableDAOImpl.addSortCriteria(org.hibernate.Criteria)

addSortCriteria

public final void addSortCriteria(org.hibernate.Criteria criteria,
                                  br.com.arsmachina.dao.SortCriterion... sortCriteria)
Invokes delegate.addSortCriteria().

Parameters:
criteria -
sortCriteria -
See Also:
ReadableDAOImpl.addSortCriteria(org.hibernate.Criteria, br.com.arsmachina.dao.SortCriterion[])

createCriteria

protected org.hibernate.Criteria createCriteria()
Invokes readableDAO.createCriteria().

Returns:
See Also:
ReadableDAOImpl.createCriteria()

createCriteria

protected org.hibernate.Criteria createCriteria(br.com.arsmachina.dao.SortCriterion... sortCriteria)
Invokes delegate.createCriteria().

Parameters:
sortCriteria -
Returns:
See Also:
ReadableDAOImpl.createCriteria(br.com.arsmachina.dao.SortCriterion[])

createCriteria

public org.hibernate.Criteria createCriteria(int firstIndex,
                                             int maximumResults,
                                             br.com.arsmachina.dao.SortCriterion... sortCriteria)
Invokes delegate.createCriteria().

Parameters:
firstIndex -
maximumResults -
sortCriteria -
Returns:
See Also:
ReadableDAOImpl.createCriteria(int, int, br.com.arsmachina.dao.SortCriterion[])

createExample

protected org.hibernate.criterion.Example createExample(T entity)
Invokes readableDAO.createExample().

Parameters:
entity -
Returns:
See Also:
ReadableDAOImpl.createExample(java.lang.Object)

getEntityClass

protected final Class<T> getEntityClass()
Returns the entity class handled by this DAO.

Returns:
a Class.

getSession

protected org.hibernate.classic.Session getSession()
Returns a Session. This implementation returns SessionFactory.getCurrentSession() and can be overriden if needed.

Returns:
a Session.

getSessionFactory

protected final org.hibernate.SessionFactory getSessionFactory()
Returns this DAO's SessionFactory.

Returns:
a SessionFactory.

getClassMetadata

protected final org.hibernate.metadata.ClassMetadata getClassMetadata()
Returns the ClassMetadata for the corresponding entity class.

Returns:
a ClassMetadata.

getPrimaryKeyPropertyName

public String getPrimaryKeyPropertyName()
Returns the name of the property.

Returns:
a String.


Copyright © 2008-2009 Thiago H. de Paula Figueiredo. All Rights Reserved.