org.riotfamily.riot.hibernate.support
Class HibernateHelper

java.lang.Object
  extended by org.riotfamily.riot.hibernate.support.HibernateSupport
      extended by org.riotfamily.riot.hibernate.support.HibernateHelper

public class HibernateHelper
extends HibernateSupport

Class that provides helper methods to work with contextual sessions. All HibernateExceptions are caught and converted to DataAccessExceptions.

Since:
6.5
Author:
Felix Gnass [fgnass at neteye dot de]

Constructor Summary
HibernateHelper(org.hibernate.SessionFactory sessionFactory)
           
HibernateHelper(org.hibernate.SessionFactory sessionFactory, String defaultCacheReqion)
           
 
Method Summary
 org.hibernate.Criteria createCacheableCriteria(Class<?> clazz)
          Creates a cacheable Criteria for the given Class, using the helper's defaultCacheRegion.
 org.hibernate.Criteria createCacheableCriteria(String cacheRegion, Class<?> clazz)
          Creates a cacheable Criteria for the given Class, using the specified cache region.
 org.hibernate.Query createCacheableQuery(String hql)
          Creates a cacheable Query for the given HQL, using the helper's defaultCacheRegion.
 org.hibernate.Query createCacheableQuery(String cacheRegion, String hql)
          Creates a cacheable Query for the given HQL, using the specified cache region.
 org.hibernate.Criteria createCriteria(Class<?> clazz)
          Creates a Criteria for the given Class.
 org.hibernate.Query createFilter(Object object, String hql)
          Creates filter for the given object.
 org.hibernate.Query createQuery(String hql)
          Creates Query for the given HQL.
 void delete(Object object)
          Deletes the given persistent instance.
 void evict(Object object)
          Remove this instance from the session cache.
 int executeUpdate(org.hibernate.Query query)
           
 void flush()
          Forces the current session to flush.
<T> T
get(Class<T> clazz, Serializable id)
          Returns the persistent instance of the given Class, or null if no such instance exists.
 org.hibernate.Session getSession()
          Returns the current session.
<T> List<T>
list(org.hibernate.Criteria c)
           
<T> List<T>
list(org.hibernate.Query query)
           
<T> T
load(Class<T> clazz, Serializable id)
          Returns the persistent instance of the given Class, assuming that the instance exists.
 void lock(Object object, org.hibernate.LockMode lockMode)
          Obtain the specified lock leve upon the given object.
<T> T
merge(T object)
          Merges the given detached instance.
 void persist(Object object)
          Persists the given transient instance.
<T> T
reattach(T object)
          Re-attaches the given instance.
 void refresh(Object object)
          Re-reads the state of the given persistent or detached instance.
 Serializable save(Object object)
          Persists the given transient instance.
 void saveOrUpdate(Object object)
          Either saves or updates the given instance, depending upon resolution of the unsaved-value checks.
 void setParameter(org.hibernate.Query query, String name, Object val)
           
<T> T
uniqueResult(org.hibernate.Criteria c)
           
<T> T
uniqueResult(org.hibernate.Query query)
           
 void update(Object object)
          Updates the given persistent instance.
 
Methods inherited from class org.riotfamily.riot.hibernate.support.HibernateSupport
getSessionFactory, setSessionFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateHelper

public HibernateHelper(org.hibernate.SessionFactory sessionFactory)

HibernateHelper

public HibernateHelper(org.hibernate.SessionFactory sessionFactory,
                       String defaultCacheReqion)
Method Detail

getSession

public org.hibernate.Session getSession()
Returns the current session.

Overrides:
getSession in class HibernateSupport
See Also:
SessionFactory.getCurrentSession()

createCriteria

public org.hibernate.Criteria createCriteria(Class<?> clazz)
Creates a Criteria for the given Class.

Overrides:
createCriteria in class HibernateSupport

createCacheableCriteria

public org.hibernate.Criteria createCacheableCriteria(Class<?> clazz)
Creates a cacheable Criteria for the given Class, using the helper's defaultCacheRegion.


createCacheableCriteria

public org.hibernate.Criteria createCacheableCriteria(String cacheRegion,
                                                      Class<?> clazz)
Creates a cacheable Criteria for the given Class, using the specified cache region.


createQuery

public org.hibernate.Query createQuery(String hql)
Creates Query for the given HQL.

Overrides:
createQuery in class HibernateSupport

createCacheableQuery

public org.hibernate.Query createCacheableQuery(String hql)
Creates a cacheable Query for the given HQL, using the helper's defaultCacheRegion.


createCacheableQuery

public org.hibernate.Query createCacheableQuery(String cacheRegion,
                                                String hql)
Creates a cacheable Query for the given HQL, using the specified cache region.


createFilter

public org.hibernate.Query createFilter(Object object,
                                        String hql)
Creates filter for the given object.

Overrides:
createFilter in class HibernateSupport

load

public <T> T load(Class<T> clazz,
                  Serializable id)
       throws DataAccessException
Returns the persistent instance of the given Class, assuming that the instance exists.

Throws:
DataAccessException
See Also:
Session.load(Class, Serializable)

get

public <T> T get(Class<T> clazz,
                 Serializable id)
      throws DataAccessException
Returns the persistent instance of the given Class, or null if no such instance exists.

Throws:
DataAccessException
See Also:
Session.get(Class, Serializable)

save

public Serializable save(Object object)
                  throws DataAccessException
Persists the given transient instance.

Throws:
DataAccessException
See Also:
Session.save(Object)

persist

public void persist(Object object)
             throws DataAccessException
Persists the given transient instance.

Throws:
DataAccessException
See Also:
Session.persist(Object)

saveOrUpdate

public void saveOrUpdate(Object object)
                  throws DataAccessException
Either saves or updates the given instance, depending upon resolution of the unsaved-value checks.

Throws:
DataAccessException

update

public void update(Object object)
            throws DataAccessException
Updates the given persistent instance.

Throws:
DataAccessException
See Also:
Session.update(Object)

merge

public <T> T merge(T object)
        throws DataAccessException
Merges the given detached instance.

Throws:
DataAccessException
See Also:
Session.merge(Object)

reattach

public <T> T reattach(T object)
           throws DataAccessException
Re-attaches the given instance. The method first tries to call Session.update() which will fail if persistent instance with the same identifier has already been loaded in the session. In that case the state of the detached object is merged into the persistent instance using Session.merge(). Therefore callers should continue working with the returned object.

Throws:
DataAccessException

lock

public void lock(Object object,
                 org.hibernate.LockMode lockMode)
          throws DataAccessException
Obtain the specified lock leve upon the given object.

Throws:
DataAccessException
See Also:
Session.lock(Object, LockMode)

delete

public void delete(Object object)
            throws DataAccessException
Deletes the given persistent instance.

Throws:
DataAccessException
See Also:
Session.delete(Object)

refresh

public void refresh(Object object)
             throws DataAccessException
Re-reads the state of the given persistent or detached instance.

Throws:
DataAccessException
See Also:
Session.refresh(Object)

flush

public void flush()
           throws DataAccessException
Forces the current session to flush.

Throws:
DataAccessException
See Also:
Session.flush()

evict

public void evict(Object object)
           throws DataAccessException
Remove this instance from the session cache.

Throws:
DataAccessException
See Also:
Session.evict(Object)

list

public <T> List<T> list(org.hibernate.Query query)
             throws DataAccessException
Throws:
DataAccessException

uniqueResult

public <T> T uniqueResult(org.hibernate.Query query)
               throws DataAccessException
Throws:
DataAccessException

list

public <T> List<T> list(org.hibernate.Criteria c)
             throws DataAccessException
Throws:
DataAccessException

uniqueResult

public <T> T uniqueResult(org.hibernate.Criteria c)
               throws DataAccessException
Throws:
DataAccessException

setParameter

public void setParameter(org.hibernate.Query query,
                         String name,
                         Object val)

executeUpdate

public int executeUpdate(org.hibernate.Query query)