net.sf.gilead.core.hibernate
Class HibernateUtil

java.lang.Object
  extended by net.sf.gilead.core.hibernate.HibernateUtil
All Implemented Interfaces:
IPersistenceUtil
Direct Known Subclasses:
HibernateJBossUtil, HibernateJpaUtil, HibernateSpringUtil

public class HibernateUtil
extends java.lang.Object
implements IPersistenceUtil

Persistent helper for Hibernate implementation Centralizes the SessionFactory and add some needed methods. Not really a singleton, since there can be as many HibernateUtil instance as different sessionFactories

Author:
BMARCHESSON

Constructor Summary
HibernateUtil()
          Default constructor
 
Method Summary
 void closeCurrentSession()
          Close the session opened with 'openSession' call
 java.lang.Object createEntityProxy(java.util.Map<java.lang.String,java.io.Serializable> proxyInformations)
          Create a proxy for the argument class and id
 java.lang.Object createPersistentCollection(java.util.Map<java.lang.String,java.io.Serializable> proxyInformations, java.lang.Object underlyingCollection)
          Create a persistent collection
 java.io.Serializable getId(java.lang.Object pojo)
           
 java.io.Serializable getId(java.lang.Object pojo, java.lang.Class<?> hibernateClass)
           
static HibernateUtil getInstance()
           
 SessionFactory getSessionFactory()
           
 java.lang.Class<?> getUnenhancedClass(java.lang.Class<?> clazz)
          Get the persistent class without proxy
 void initialize(java.lang.Object proxy)
          Initialize the argument if not
 boolean isEnhanced(java.lang.Class<?> clazz)
          Indicated if the argument class is enhanced or not
 boolean isInitialized(java.lang.Object proxy)
          Indicates it the argument is initialized not
 boolean isPersistentClass(java.lang.Class<?> clazz)
          Indicates if the class is managed by the persistance container of not
 boolean isPersistentCollection(java.lang.Class<?> collectionClass)
          Indicates if the argument collection is persistent or not
 boolean isPersistentPojo(java.lang.Object pojo)
          Indicates if the pojo is persistent or not.
 java.lang.Object load(java.io.Serializable id, java.lang.Class<?> persistentClass)
          Load a fresh instance of the persistent Pojo
 void openSession()
          Open a new session
 java.util.Map<java.lang.String,java.io.Serializable> serializeEntityProxy(java.lang.Object proxy)
          Serialize proxy informations of the argument entity into a map of properties
 java.util.Map<java.lang.String,java.io.Serializable> serializePersistentCollection(java.lang.Object persistentCollection)
          Serialize a persistent collection
 void setSessionFactory(SessionFactory sessionFactory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateUtil

public HibernateUtil()
Default constructor

Method Detail

getInstance

public static HibernateUtil getInstance()
Returns:
the unique instance of the singleton

getSessionFactory

public SessionFactory getSessionFactory()
Returns:
the hibernate session Factory

setSessionFactory

public void setSessionFactory(SessionFactory sessionFactory)
Parameters:
sessionFactory - the factory to set

getId

public java.io.Serializable getId(java.lang.Object pojo)
Specified by:
getId in interface IPersistenceUtil
Returns:
the ID of the argument Hibernate Pojo

getId

public java.io.Serializable getId(java.lang.Object pojo,
                                  java.lang.Class<?> hibernateClass)
Specified by:
getId in interface IPersistenceUtil
Returns:
the ID of the argument DTO with the same name than the persistent class

isPersistentPojo

public boolean isPersistentPojo(java.lang.Object pojo)
Description copied from interface: IPersistenceUtil
Indicates if the pojo is persistent or not. Its class must be declared as persistent and the pojo must have an ID

Specified by:
isPersistentPojo in interface IPersistenceUtil

isPersistentClass

public boolean isPersistentClass(java.lang.Class<?> clazz)
Description copied from interface: IPersistenceUtil
Indicates if the class is managed by the persistance container of not

Specified by:
isPersistentClass in interface IPersistenceUtil

getUnenhancedClass

public java.lang.Class<?> getUnenhancedClass(java.lang.Class<?> clazz)
Description copied from interface: IPersistenceUtil
Get the persistent class without proxy

Specified by:
getUnenhancedClass in interface IPersistenceUtil
Returns:
the underlying persistent class

isEnhanced

public boolean isEnhanced(java.lang.Class<?> clazz)
Description copied from interface: IPersistenceUtil
Indicated if the argument class is enhanced or not

Specified by:
isEnhanced in interface IPersistenceUtil
Parameters:
clazz - the persistent class
Returns:
true is the class is enhanced, false otherwise

openSession

public void openSession()
Description copied from interface: IPersistenceUtil
Open a new session

Specified by:
openSession in interface IPersistenceUtil

closeCurrentSession

public void closeCurrentSession()
Description copied from interface: IPersistenceUtil
Close the session opened with 'openSession' call

Specified by:
closeCurrentSession in interface IPersistenceUtil

load

public java.lang.Object load(java.io.Serializable id,
                             java.lang.Class<?> persistentClass)
Description copied from interface: IPersistenceUtil
Load a fresh instance of the persistent Pojo

Specified by:
load in interface IPersistenceUtil
persistentClass - the persistent class
Returns:
the loaded instance

serializeEntityProxy

public java.util.Map<java.lang.String,java.io.Serializable> serializeEntityProxy(java.lang.Object proxy)
Description copied from interface: IPersistenceUtil
Serialize proxy informations of the argument entity into a map of properties

Specified by:
serializeEntityProxy in interface IPersistenceUtil
Parameters:
proxy - the proxy to serialize
Returns:
a map of properties

createEntityProxy

public java.lang.Object createEntityProxy(java.util.Map<java.lang.String,java.io.Serializable> proxyInformations)
Create a proxy for the argument class and id

Specified by:
createEntityProxy in interface IPersistenceUtil
Parameters:
proxyInformations - the serialized proxy informations
Returns:
the generated proxy

serializePersistentCollection

public java.util.Map<java.lang.String,java.io.Serializable> serializePersistentCollection(java.lang.Object persistentCollection)
Description copied from interface: IPersistenceUtil
Serialize a persistent collection

Specified by:
serializePersistentCollection in interface IPersistenceUtil
Parameters:
persistentCollection - the persistent collection
Returns:
a Map with mininmum informations needed to re-create the persistent info

createPersistentCollection

public java.lang.Object createPersistentCollection(java.util.Map<java.lang.String,java.io.Serializable> proxyInformations,
                                                   java.lang.Object underlyingCollection)
Create a persistent collection

Specified by:
createPersistentCollection in interface IPersistenceUtil
Parameters:
proxyInformations - serialized proxy informations
underlyingCollection - the filled underlying collection
Returns:

isPersistentCollection

public boolean isPersistentCollection(java.lang.Class<?> collectionClass)
Description copied from interface: IPersistenceUtil
Indicates if the argument collection is persistent or not

Specified by:
isPersistentCollection in interface IPersistenceUtil
Parameters:
collectionClass - the collection class
Returns:

isInitialized

public boolean isInitialized(java.lang.Object proxy)
Description copied from interface: IPersistenceUtil
Indicates it the argument is initialized not

Specified by:
isInitialized in interface IPersistenceUtil
Parameters:
proxy - the instance to check
Returns:

initialize

public void initialize(java.lang.Object proxy)
Description copied from interface: IPersistenceUtil
Initialize the argument if not

Specified by:
initialize in interface IPersistenceUtil
Parameters:
proxy - the instance to initialize