de.nava.informa.utils.manager.hibernate
Class HibernateUtil

java.lang.Object
  extended by de.nava.informa.utils.manager.hibernate.HibernateUtil

final class HibernateUtil
extends Object

Hibernate session utility. Using it to get sessions you will ensure that only session is created only once per thread.

Author:
Aleksey Gureev (spyromus@noizeramp.com)

Method Summary
static void closeSession()
          Closes previousely opened session.
static void deleteObject(Object object, Session session)
          Deletes object from database using existing session.
static void lock(Object o, Session s)
          Makes a try to lock object.
static Session openSession()
          Opens new session or returns currently open session for this thread.
static void saveObject(Object object)
          Saves object into storage.
static void saveObject(Object object, Session session)
          Saves object into storage.
static void updateObject(Object object)
          Updates object in storage.
static void updateObject(Object object, Session session)
          Updates object in storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

openSession

public static Session openSession()
                           throws HibernateException
Opens new session or returns currently open session for this thread.

Returns:
session object.
Throws:
HibernateException - if something with session creation goes wrong.

closeSession

public static void closeSession()
Closes previousely opened session.


lock

public static void lock(Object o,
                        Session s)
Makes a try to lock object. This will save us great number of SQL statements in several cases. It's not a big problem if locking is not possible.

Parameters:
o - object to lock.
s - session to lock object in.

saveObject

public static void saveObject(Object object)
                       throws PersistenceManagerException
Saves object into storage.

Parameters:
object - object to save.
Throws:
PersistenceManagerException - in case of any problems during saving.

saveObject

public static void saveObject(Object object,
                              Session session)
                       throws PersistenceManagerException
Saves object into storage.

Parameters:
object - object to save.
Throws:
PersistenceManagerException - in case of any problems during saving.

updateObject

public static void updateObject(Object object)
                         throws PersistenceManagerException
Updates object in storage.

Parameters:
object - object to update.
Throws:
PersistenceManagerException - in case of any problems during updating.

updateObject

public static void updateObject(Object object,
                                Session session)
                         throws PersistenceManagerException
Updates object in storage.

Parameters:
object - object to update.
session - session to use. If NULL then new session is opened.
Throws:
PersistenceManagerException - in case of any problems during updating.

deleteObject

public static void deleteObject(Object object,
                                Session session)
                         throws PersistenceManagerException
Deletes object from database using existing session.

Parameters:
object - object to delete.
session - session to use. If NULL then new session is opened.
Throws:
PersistenceManagerException - in case of any problems during deletion.


Copyright © 2002-2007 Niko Schmuck. All Rights Reserved.