org.archiviststoolkit.hibernate
Class HibernateUtil

java.lang.Object
  extended by org.archiviststoolkit.hibernate.HibernateUtil

public class HibernateUtil
extends java.lang.Object

Basic Hibernate helper class, handles SessionFactory, Session and Transaction.

Uses a static initializer for the initial SessionFactory creation and holds Session and Transactions in thread local variables. All exceptions are wrapped in an unchecked InfrastructureException.


Constructor Summary
HibernateUtil()
           
 
Method Summary
static void beginTransaction()
          Start a new database transaction.
static void closeSession()
          Closes the Session local to the thread.
static void commitTransaction()
          Commit the database transaction.
static org.hibernate.cfg.Configuration getConfiguration()
          Returns the original Hibernate configuration.
static org.hibernate.Session getSession()
          Retrieves the current Session local to the thread.
static org.hibernate.SessionFactory getSessionFactory()
          Returns the SessionFactory used for this static class.
static void rebuildSessionFactory()
          Rebuild the SessionFactory with the static Configuration.
static void rebuildSessionFactory(org.hibernate.cfg.Configuration cfg)
          Rebuild the SessionFactory with the given Hibernate Configuration.
static void registerInterceptor(org.hibernate.Interceptor interceptor)
          Register a Hibernate interceptor with the current thread.
static void rollbackTransaction()
          Rollback the database transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateUtil

public HibernateUtil()
Method Detail

getSessionFactory

public static org.hibernate.SessionFactory getSessionFactory()
Returns the SessionFactory used for this static class.

Returns:
SessionFactory

getConfiguration

public static org.hibernate.cfg.Configuration getConfiguration()
Returns the original Hibernate configuration.

Returns:
Configuration

rebuildSessionFactory

public static void rebuildSessionFactory()
                                  throws InfrastructureException
Rebuild the SessionFactory with the static Configuration.

Throws:
InfrastructureException

rebuildSessionFactory

public static void rebuildSessionFactory(org.hibernate.cfg.Configuration cfg)
                                  throws InfrastructureException
Rebuild the SessionFactory with the given Hibernate Configuration.

Parameters:
cfg -
Throws:
InfrastructureException

getSession

public static org.hibernate.Session getSession()
                                        throws InfrastructureException
Retrieves the current Session local to the thread.

If no Session is open, opens a new Session for the running thread.

Returns:
Session
Throws:
InfrastructureException

closeSession

public static void closeSession()
                         throws InfrastructureException
Closes the Session local to the thread.

Throws:
InfrastructureException

beginTransaction

public static void beginTransaction()
                             throws InfrastructureException
Start a new database transaction.

Throws:
InfrastructureException

commitTransaction

public static void commitTransaction()
                              throws InfrastructureException
Commit the database transaction.

Throws:
InfrastructureException

rollbackTransaction

public static void rollbackTransaction()
                                throws InfrastructureException
Rollback the database transaction.

Throws:
InfrastructureException

registerInterceptor

public static void registerInterceptor(org.hibernate.Interceptor interceptor)
Register a Hibernate interceptor with the current thread.

Every Session opened is opened with this interceptor after registration. Has no effect if the current Session of the thread is already open, effective on next close()/getSession().