jhomenet.server.dao.hibernate
Class GenericHibernateDAO<T,ID extends java.io.Serializable>

java.lang.Object
  extended by jhomenet.server.dao.hibernate.GenericHibernateDAO<T,ID>
All Implemented Interfaces:
GenericDao<T,ID>
Direct Known Subclasses:
HardwareDataDaoHibernate, HibernateDAOFactory.ConditionDaoHibernate, HibernateDAOFactory.EventDaoHibernate, HibernateDAOFactory.HardwareDaoHibernate, HibernateDAOFactory.PlanDaoHibernate, HibernateDAOFactory.ResponseDaoHibernate, HibernateDAOFactory.TriggerDaoHibernate, UserDaoHibernate

public abstract class GenericHibernateDAO<T,ID extends java.io.Serializable>
extends java.lang.Object
implements GenericDao<T,ID>

Implements the generic CRUD data access operations using Hibernate APIs.

To write a DAO, subclass and parameterize this class with your persistent class. Of course, assuming that you have a traditional 1:1 appraoch for Entity:DAO design.

You have to inject a current Hibernate Session to use a DAO. Otherwise, this generic implementation will use HibernateUtil.getSessionFactory() to obtain the curren Session.

Author:
Christian Bauer, Dave Irwin (jhomenet at gmail dot com)
See Also:
HibernateDAOFactory

Constructor Summary
GenericHibernateDAO()
           
 
Method Summary
 void clear()
          Affects every managed instance in the current persistence context!
 java.util.List<T> findAll()
          List of all of the entities.
protected  java.util.List<T> findByCriteria(Criterion... criterion)
          Use this inside subclasses as a convenience method.
 java.util.List<T> findByExample(T exampleInstance, java.lang.String... excludeProperty)
          Find an entity by example.
 T findById(ID id, boolean lock)
          Find an entity object given the entity's ID.
 void flush()
          Affects every managed instance in the current persistence context!
 java.lang.Class<T> getPersistentClass()
           
protected  Session getSession()
           
 T makePersistent(T entity)
          Make an entity object persistent.
 void makeTransient(T entity)
          Make a currently persistent entity object transient.
 void setSession(Session s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericHibernateDAO

public GenericHibernateDAO()
Method Detail

setSession

public void setSession(Session s)
Parameters:
s -

getSession

protected Session getSession()
Returns:

getPersistentClass

public java.lang.Class<T> getPersistentClass()
Returns:

findById

public T findById(ID id,
                  boolean lock)
Description copied from interface: GenericDao
Find an entity object given the entity's ID.

Specified by:
findById in interface GenericDao<T,ID extends java.io.Serializable>
Returns:
See Also:
GenericDao.findById(java.io.Serializable, boolean)

findAll

public java.util.List<T> findAll()
Description copied from interface: GenericDao
List of all of the entities.

Specified by:
findAll in interface GenericDao<T,ID extends java.io.Serializable>
Returns:
A list of the entities.
See Also:
GenericDao.findAll()

findByExample

public java.util.List<T> findByExample(T exampleInstance,
                                       java.lang.String... excludeProperty)
Description copied from interface: GenericDao
Find an entity by example.

Specified by:
findByExample in interface GenericDao<T,ID extends java.io.Serializable>
Returns:
See Also:
GenericDao.findByExample(java.lang.Object, java.lang.String[])

makePersistent

public T makePersistent(T entity)
Description copied from interface: GenericDao
Make an entity object persistent.

Specified by:
makePersistent in interface GenericDao<T,ID extends java.io.Serializable>
Parameters:
entity - The entity object to persist
Returns:
A reference to the persisted entity object
See Also:
GenericDao.makePersistent(java.lang.Object)

makeTransient

public void makeTransient(T entity)
Description copied from interface: GenericDao
Make a currently persistent entity object transient.

Specified by:
makeTransient in interface GenericDao<T,ID extends java.io.Serializable>
Parameters:
entity - The entity object to make persistent
See Also:
GenericDao.makeTransient(java.lang.Object)

findByCriteria

protected java.util.List<T> findByCriteria(Criterion... criterion)
Use this inside subclasses as a convenience method.


flush

public void flush()
Description copied from interface: GenericDao
Affects every managed instance in the current persistence context!

Specified by:
flush in interface GenericDao<T,ID extends java.io.Serializable>
See Also:
GenericDao.flush()

clear

public void clear()
Description copied from interface: GenericDao
Affects every managed instance in the current persistence context!

Specified by:
clear in interface GenericDao<T,ID extends java.io.Serializable>
See Also:
GenericDao.clear()


Copyright © 2004-2007 David Irwin. All Rights Reserved.