com.anasoft.os.daofusion
Class BaseHibernateDataAccessor

java.lang.Object
  extended by com.anasoft.os.daofusion.BaseHibernateDataAccessor
Direct Known Subclasses:
AbstractHibernateEntityDao

public abstract class BaseHibernateDataAccessor
extends java.lang.Object

Base class for persistent entity DAO implementations providing data access through JPA / Hibernate persistence APIs.

Author:
vojtech.szocs
See Also:
Persistable

Constructor Summary
BaseHibernateDataAccessor()
           
 
Method Summary
protected  org.hibernate.Criteria getCriteria(PersistentEntityCriteria entityCriteria, java.lang.Class<? extends Persistable<? extends java.io.Serializable>> entityClass)
          Returns the Criteria instance corresponding to query constraints defined within the entityCriteria.
protected  org.hibernate.Criteria getHibernateCriteria(java.lang.Class<? extends Persistable<? extends java.io.Serializable>> entityClass)
          Convenience method for retrieving a new Criteria instance bound to the current Session.
protected abstract  org.hibernate.ejb.HibernateEntityManager getHibernateEntityManager()
          Returns an open HibernateEntityManager instance providing access to the Hibernate Session.
protected  org.hibernate.Session getSession()
          Convenience method for retrieving the current Session from the entity manager.
protected  int rowCount(org.hibernate.Criteria criteria)
          Convenience method for counting the number of rows returned by the given criteria, based on Hibernate rowCount projection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseHibernateDataAccessor

public BaseHibernateDataAccessor()
Method Detail

getHibernateEntityManager

protected abstract org.hibernate.ejb.HibernateEntityManager getHibernateEntityManager()
Returns an open HibernateEntityManager instance providing access to the Hibernate Session.

The most convenient method implementation pattern is to rely on entity manager instance injection via the PersistenceContext annotation within a JPA persistence context. Alternatively, the entity manager instance can be created directly via the EntityManagerFactory.

Returns:
Open HibernateEntityManager instance.

getSession

protected final org.hibernate.Session getSession()
Convenience method for retrieving the current Session from the entity manager.

Returns:
Session obtained from the entity manager.

getHibernateCriteria

protected final org.hibernate.Criteria getHibernateCriteria(java.lang.Class<? extends Persistable<? extends java.io.Serializable>> entityClass)
Convenience method for retrieving a new Criteria instance bound to the current Session.

Parameters:
entityClass - Persistent entity class for which to create the Criteria instance.
Returns:
New Criteria instance obtained from the session.

rowCount

protected final int rowCount(org.hibernate.Criteria criteria)
Convenience method for counting the number of rows returned by the given criteria, based on Hibernate rowCount projection.

Note that the criteria shouldn't contain any paging constraints since the method relies on a result set with its "shape" defined by the projection itself.

Parameters:
criteria - Criteria instance for which to perform the row count.
Returns:
Number of rows returned by the given criteria.

getCriteria

protected org.hibernate.Criteria getCriteria(PersistentEntityCriteria entityCriteria,
                                             java.lang.Class<? extends Persistable<? extends java.io.Serializable>> entityClass)
Returns the Criteria instance corresponding to query constraints defined within the entityCriteria.

Parameters:
entityCriteria - PersistentEntityCriteria instance defining persistent entity query constraints.
entityClass - Persistent entity class for which to create the Criteria instance.
Returns:
Criteria instance corresponding to query constraints.


Copyright © 2008-2009 ANASOFT and contributors. All Rights Reserved.