uk.co.concise.maven.hdc.dao
Class HibernateUtil

java.lang.Object
  extended by uk.co.concise.maven.hdc.dao.HibernateUtil

public abstract class HibernateUtil
extends java.lang.Object

Super class for all our data accessor objects.

Author:
martenssonb

Field Summary
static java.lang.ThreadLocal session
           
 
Constructor Summary
HibernateUtil()
           
 
Method Summary
static void closeSession()
          Closes the session for the running thread.
static void configure(java.lang.String dbDriverClass, java.lang.String dbUrl, java.lang.String dbUser, java.lang.String dbPass, java.lang.String dbHibernateDialect)
          Configures hibernate programmatically.
static net.sf.hibernate.Session currentSession()
          Returns a session for the calling thread.
static void handleHibernateException(net.sf.hibernate.Transaction tx, net.sf.hibernate.HibernateException e)
          Handles if there is a hibernate exception during a transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

public static final java.lang.ThreadLocal session
Constructor Detail

HibernateUtil

public HibernateUtil()
Method Detail

configure

public static void configure(java.lang.String dbDriverClass,
                             java.lang.String dbUrl,
                             java.lang.String dbUser,
                             java.lang.String dbPass,
                             java.lang.String dbHibernateDialect)
Configures hibernate programmatically. This method initialises the session factory exactly once.

Parameters:
dbDriverClass - the JDBC driver used for persistance.
dbUrl - the URL to the database.
dbUser - the user used to login to the database.
dbPass - the password used to login to the database.
dbHibernateDialect - the database dialect that Hibernate will use.

currentSession

public static net.sf.hibernate.Session currentSession()
Returns a session for the calling thread. Creates a session if none exists.

Returns:
a session for the calling thread.

closeSession

public static void closeSession()
Closes the session for the running thread.


handleHibernateException

public static void handleHibernateException(net.sf.hibernate.Transaction tx,
                                            net.sf.hibernate.HibernateException e)
Handles if there is a hibernate exception during a transaction.

Parameters:
tx - the transaction.
e - the hibernate exception.


Copyright © 2004-2005 Concise. All Rights Reserved.