|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.melloware.jukes.db.HibernateUtil
public final class HibernateUtil
Basic Hibernate helper class for Hibernate configuration and startup.
Uses a static initializer to read startup options and initialize Configuration and SessionFactory.
This class also tries to figure out if JNDI binding of the SessionFactory is used, otherwise it falls back to a global static variable (Singleton). If you use this helper class to obtain a SessionFactory in your code, you are shielded from these deployment differences.
Another advantage of this class is access to the Configuration object that was used to build the current SessionFactory. You can access mapping metadata programmatically with this API, and even change it and rebuild the SessionFactory.
If you want to assign a global interceptor, set its fully qualified class name with the system (or hibernate.properties/hibernate.cfg.xml) property hibernate.util.interceptor_class. It will be loaded and instantiated on static initialization of HibernateUtil; it has to have a no-argument constructor. You can call HibernateUtil.getInterceptor() if you need to provide settings before using the interceptor.
Note: This class supports annotations by default, hence needs JDK 5.0 and the Hibernate Annotations library on the classpath. Change the single commented line in the source to make it compile and run on older JDKs with XML mapping files only.
Note: This class supports only one data store. Support for several
SessionFactory instances can be easily added (through a static
Map, for example). You could then lookup a
SessionFactory by its name. Copyright (c) 1999-2007 Melloware,
Inc.
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().
The only other method that can be called on HibernateUtil after this one
is rebuildSessionFactory(Configuration).
Method Summary
static voidbeginTransaction()
Start a new database transaction.
static voidcloseSession()
Closes the Session local to the thread.
static voidcommitTransaction()
Commit the database transaction.
static org.hibernate.SessiondisconnectSession()
Disconnect and return Session from current Thread.
static org.hibernate.cfg.ConfigurationgetConfiguration()
Returns the original Hibernate configuration.
static java.lang.StringgetRemoteUrl()
Gets the remoteUrl.
static org.hibernate.SessiongetSession()
Retrieves the current Session local to the thread.
static org.hibernate.SessionFactorygetSessionFactory()
Returns the SessionFactory used for this static class.
static voidinitialize()
Static initializer to startup Hibernate.
static booleanisCompact()
Gets the compact.
static booleanisHSQLDialect()
Gets the isHSQLDialect.
static voidrebuildSessionFactory()
Rebuild the SessionFactory with the static Configuration.
static voidrebuildSessionFactory(org.hibernate.cfg.Configuration cfg)
Rebuild the SessionFactory with the given Hibernate Configuration.
static voidregisterInterceptor(org.hibernate.Interceptor interceptor)
Register a Hibernate interceptor with the current thread.
static voidrollbackTransaction()
Commit the database transaction.
static voidsetCompact(boolean aCompact)
Sets the compact.
static voidsetRemoteUrl(java.lang.String aRemoteUrl)
Sets the remoteUrl.
static voidshutdown()
Closes the current SessionFactory and releases all resources.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Method Detail
getConfiguration
public static org.hibernate.cfg.Configuration getConfiguration()
getRemoteUrl
public static java.lang.String getRemoteUrl()
getSession
public static org.hibernate.Session getSession()
throws InfrastructureException
InfrastructureException
getSessionFactory
public static org.hibernate.SessionFactory getSessionFactory()
setCompact
public static void setCompact(boolean aCompact)
aCompact - The compact to set.
setRemoteUrl
public static void setRemoteUrl(java.lang.String aRemoteUrl)
aRemoteUrl - The remoteUrl to set.
isCompact
public static boolean isCompact()
isHSQLDialect
public static boolean isHSQLDialect()
beginTransaction
public static void beginTransaction()
throws InfrastructureException
InfrastructureException
closeSession
public static void closeSession()
throws InfrastructureException
InfrastructureException
commitTransaction
public static void commitTransaction()
throws InfrastructureException
InfrastructureException
disconnectSession
public static org.hibernate.Session disconnectSession()
throws InfrastructureException
InfrastructureException
initialize
public static void initialize()
rebuildSessionFactory
public static void rebuildSessionFactory()
throws InfrastructureException
InfrastructureException
rebuildSessionFactory
public static void rebuildSessionFactory(org.hibernate.cfg.Configuration cfg)
throws InfrastructureException
cfg -
InfrastructureException
registerInterceptor
public static void registerInterceptor(org.hibernate.Interceptor interceptor)
rollbackTransaction
public static void rollbackTransaction()
throws InfrastructureException
InfrastructureException
shutdown
public static void shutdown()
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
Copyright © 1999-2008 Melloware Inc. All Rights Reserved.