com::cosylab::cdb::jdal::hibernate::HibernateUtil Class Reference

Collaboration diagram for com::cosylab::cdb::jdal::hibernate::HibernateUtil:
Collaboration graph
[legend]

List of all members.

Classes

class  HibernateUtilException

Public Member Functions

void setConfiguration (Properties extraProperties)
void setConfiguration (Configuration config)
SessionFactory getSessionFactory ()
Configuration getConfiguration ()
void rebuildSessionFactory () throws HibernateUtilException
void rebuildSessionFactory (Configuration cfg) throws HibernateUtilException
Session getSession () throws HibernateUtilException
void closeSession () throws HibernateUtilException
void beginTransaction () throws HibernateUtilException
void commitTransaction () throws HibernateUtilException
void rollbackTransaction () throws HibernateUtilException
void reconnect (Session session) throws HibernateUtilException
Session disconnectSession () throws HibernateUtilException
void registerInterceptor (Interceptor interceptor)
List getList (Class type) throws HibernateUtilException

Static Public Member Functions

static synchronized HibernateUtil getInstance (Logger logger)
static void clearInstance ()

Static Public Attributes

static final String HIBERNATE_FILENAME_DEFAULT = "cdb_rdb-hibernate.cfg.xml"

Private Member Functions

final String getConfigurationFileName ()
 HibernateUtil (Logger logger)
Interceptor getInterceptor ()

Private Attributes

final Logger logger
Configuration configuration
SessionFactory sessionFactory
final ThreadLocal threadSession = new ThreadLocal()
final ThreadLocal threadTransaction = new ThreadLocal()
final ThreadLocal threadInterceptor = new ThreadLocal()

Static Private Attributes

static HibernateUtil instance
static final String HIBERNATE_FILENAME_KEY = "cdb_rdb.hibernate.cfg.filename"

Detailed Description

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

Holds Session and Transactions in thread local variables. All exceptions are wrapped in an unchecked HibernateUtilException.


Constructor & Destructor Documentation

com::cosylab::cdb::jdal::hibernate::HibernateUtil::HibernateUtil ( Logger  logger  )  [inline, private]

Member Function Documentation

void com::cosylab::cdb::jdal::hibernate::HibernateUtil::beginTransaction (  )  throws HibernateUtilException [inline]
static void com::cosylab::cdb::jdal::hibernate::HibernateUtil::clearInstance (  )  [inline, static]

Nulls the instance field, so that subsequent calls to getInstance(Logger) will create a new instance. This probably only makes sense between junit tests that want to start out fresh.

void com::cosylab::cdb::jdal::hibernate::HibernateUtil::closeSession (  )  throws HibernateUtilException [inline]
void com::cosylab::cdb::jdal::hibernate::HibernateUtil::commitTransaction (  )  throws HibernateUtilException [inline]
Session com::cosylab::cdb::jdal::hibernate::HibernateUtil::disconnectSession (  )  throws HibernateUtilException [inline]

Disconnect and return Session from current Thread.

Returns:
Session the disconnected Session
Configuration com::cosylab::cdb::jdal::hibernate::HibernateUtil::getConfiguration (  )  [inline]
final String com::cosylab::cdb::jdal::hibernate::HibernateUtil::getConfigurationFileName (  )  [inline, private]
static synchronized HibernateUtil com::cosylab::cdb::jdal::hibernate::HibernateUtil::getInstance ( Logger  logger  )  [inline, static]
Interceptor com::cosylab::cdb::jdal::hibernate::HibernateUtil::getInterceptor (  )  [inline, private]
List com::cosylab::cdb::jdal::hibernate::HibernateUtil::getList ( Class  type  )  throws HibernateUtilException [inline]
Session com::cosylab::cdb::jdal::hibernate::HibernateUtil::getSession (  )  throws HibernateUtilException [inline]

Retrieves the current Session local to the thread.

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

Returns:
Session

Referenced by alma::acs::tmcdb::TestSnmpTables::createDB(), alma::acs::tmcdb::TestPojosPersistence::createDB(), alma::acs::tmcdb::TestPojosCascading::createDB(), alma::acs::tmcdb::TestSnmpTables::dropDB(), alma::acs::tmcdb::TestPojosPersistence::dropDB(), alma::acs::tmcdb::TestPojosCascading::dropDB(), com::cosylab::cdb::jdal::HibernateWDALImpl::getAlmaBranch(), com::cosylab::cdb::jdal::HibernateWDALImpl::getChannelsTableMap(), com::cosylab::cdb::jdal::HibernateWDALImpl::getComponentsTableMap(), com::cosylab::cdb::jdal::HibernateWDALImpl::getContainersTableMap(), com::cosylab::cdb::jdal::HibernateWDALImpl::initializeRootNode(), com::cosylab::cdb::jdal::HibernateWDALImpl::load(), com::cosylab::cdb::jdal::HibernateWDALImpl::loadXMLCDB(), com::cosylab::cdb::jdal::HibernateWDALImpl::reloadData(), alma::acs::tmcdb::TestPojosCascading::testCascadingAggregation(), alma::acs::tmcdb::TestPojosCascading::testCascadingInverseAggregation(), alma::acs::tmcdb::TestPojosCascading::testCascadingInverseComposition(), alma::acs::tmcdb::TestSnmpTables::testFillSnmpTmcdb(), alma::acs::tmcdb::TestPojosCascading::testNoCascading(), alma::acs::tmcdb::TestPojosPersistence::testSaveInheritance(), alma::acs::tmcdb::TestPojosPersistence::testShutdown(), alma::acs::tmcdb::TestPojosPersistence::testSimpleSave(), and alma::acs::tmcdb::TestPojosPersistence::testXmlTypeSave().

SessionFactory com::cosylab::cdb::jdal::hibernate::HibernateUtil::getSessionFactory (  )  [inline]
void com::cosylab::cdb::jdal::hibernate::HibernateUtil::rebuildSessionFactory ( Configuration  cfg  )  throws HibernateUtilException [inline]

Rebuild the SessionFactory with the given Hibernate Configuration.

Parameters:
cfg 
void com::cosylab::cdb::jdal::hibernate::HibernateUtil::rebuildSessionFactory (  )  throws HibernateUtilException [inline]

Rebuild the SessionFactory with the static Configuration.

void com::cosylab::cdb::jdal::hibernate::HibernateUtil::reconnect ( Session  session  )  throws HibernateUtilException [inline]

Reconnects a Hibernate Session to the current Thread.

Parameters:
session The Hibernate Session to be reconnected.
void com::cosylab::cdb::jdal::hibernate::HibernateUtil::registerInterceptor ( Interceptor  interceptor  )  [inline]

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().

void com::cosylab::cdb::jdal::hibernate::HibernateUtil::rollbackTransaction (  )  throws HibernateUtilException [inline]

Commit the database transaction.

Referenced by alma::acs::tmcdb::TestPojosPersistence::testSimpleSave().

void com::cosylab::cdb::jdal::hibernate::HibernateUtil::setConfiguration ( Configuration  config  )  [inline]

Set your own configuration and build session factory from it. Used to tests.

Parameters:
config 
void com::cosylab::cdb::jdal::hibernate::HibernateUtil::setConfiguration ( Properties  extraProperties  )  [inline]

Use default configuration and add properties from Properties. Build session factory from combined configuration.

Parameters:
config 

Referenced by alma::acs::tmcdb::TestSnmpTables::setUp(), alma::acs::tmcdb::TestPojosPersistence::setUp(), alma::acs::tmcdb::TestPojosCascading::setUp(), and com::cosylab::cdb::jdal::hibernate::HibernateDBUtil::setUp().


Member Data Documentation

final String com::cosylab::cdb::jdal::hibernate::HibernateUtil::HIBERNATE_FILENAME_DEFAULT = "cdb_rdb-hibernate.cfg.xml" [static]
final String com::cosylab::cdb::jdal::hibernate::HibernateUtil::HIBERNATE_FILENAME_KEY = "cdb_rdb.hibernate.cfg.filename" [static, private]
final ThreadLocal com::cosylab::cdb::jdal::hibernate::HibernateUtil::threadInterceptor = new ThreadLocal() [private]
final ThreadLocal com::cosylab::cdb::jdal::hibernate::HibernateUtil::threadSession = new ThreadLocal() [private]
final ThreadLocal com::cosylab::cdb::jdal::hibernate::HibernateUtil::threadTransaction = new ThreadLocal() [private]

The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2