net.sf.jzeno.aop
Class PersistencySupport

java.lang.Object
  extended by net.sf.jzeno.aop.PersistencySupport

public class PersistencySupport
extends java.lang.Object

Provides convenient access to Hibernate related stuff without the need of having any 'hook'. The methods on this class can be called from any part of the application.


Constructor Summary
PersistencySupport()
           
 
Method Summary
static void autoSync(java.util.Collection entities)
           
static void autoSync(Entity entity)
           
static void clearCache()
           This operation clears the entire second level cache, as well as the query cache of hibernate.
static java.lang.Object create(java.lang.Class clazz)
          Factory method for creating new entities.
static AutoSyncSession createAutoSyncSession()
           
static Criteria createCriteria(java.lang.Class queryClass)
           Convenience method to allow you to create a criteria query without requesting the hibernate session.
static Query createQuery(java.lang.String hql)
           Convenience method to allow you to create a query without requesting the hibernate session.
static Session createSession()
           Creates a new hibernate session.
static void delete(Entity entity)
          Register an entity for deletion
static java.util.List getAll(java.lang.Class clazz)
           This is a generic operation for retrieving all instances of a certain type of domain model class..
static AutoSyncSession getAutoSyncSession()
           
static java.lang.Object getEnumFromInt(int id, java.lang.Class type)
           
static org.hibernate.cfg.Configuration getHibernateConfig()
           Returns the hibernate Configuration object.
static org.hibernate.Interceptor getInterceptorInstance()
           
static Session getSession()
           Get the current session for your thread.
static org.hibernate.SessionFactory getSessionFactory()
           
static void initialize(java.lang.Object proxy)
           Swizzles in the given hibernate proxy.
static boolean isDeleted(Entity entity)
           
static boolean isInitialized(java.lang.Object proxy)
           
static boolean isMapped(java.lang.Class clazz)
           
static boolean isNew(Entity entity)
           
static boolean isStarted()
          Is hibernate allready started or not ?
static void releaseAutoSyncSession()
           
static void releaseSession()
           When a client does not require a hibernate session any longer, it should release the session by calling this operation.
static void swizzle(java.util.List rootEntities, java.lang.String propertyPathList)
           
static void swizzle(java.lang.Object rootEntity, java.lang.String propertyPathList)
           
static void swizzleOnePropertyPath(java.util.List rootEntities, java.lang.String propertyPath)
           
static void swizzleOnePropertyPathInternal(java.util.List rootEntities, java.lang.String propertyPath)
           
static java.util.List swizzleReadOnly(Entity rootEntity, java.lang.String propertyPathList)
           
static java.util.List swizzleReadOnly(java.util.List rootEntities, java.lang.String propertyPathList)
           
static java.util.List swizzleReadOnlyFromIds(java.util.List ids, java.lang.Class type, java.lang.String propertyPathList)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistencySupport

public PersistencySupport()
Method Detail

createSession

public static Session createSession()

Creates a new hibernate session.


releaseSession

public static void releaseSession()

When a client does not require a hibernate session any longer, it should release the session by calling this operation.


getSession

public static Session getSession()

Get the current session for your thread. When a session is started, it is also associated with the current thread (see createSession()). This operation allows for convenient access to the current session. For example from inside a business facade, when the session itself was created transparently by an aspect of that business facade.


createQuery

public static Query createQuery(java.lang.String hql)

Convenience method to allow you to create a query without requesting the hibernate session.


createCriteria

public static Criteria createCriteria(java.lang.Class queryClass)

Convenience method to allow you to create a criteria query without requesting the hibernate session.


isStarted

public static boolean isStarted()
Is hibernate allready started or not ?

Returns:

getSessionFactory

public static org.hibernate.SessionFactory getSessionFactory()
Returns:
the SessionFactory in the system. Handy for getting to meta data, for example.

getAll

public static java.util.List getAll(java.lang.Class clazz)

This is a generic operation for retrieving all instances of a certain type of domain model class.. Just supply the Class that indicates the model bean of interest, and you get back a list of all objects of that type in the system. It also works on PersistentEnums.

Parameters:
clazz - the type of object to look for.
Returns:
a list of all objects of the requested type.

getHibernateConfig

public static org.hibernate.cfg.Configuration getHibernateConfig()

Returns the hibernate Configuration object. This an objectified version of all your mapping files (hbm.xml). This method now also supports the use of an AnnotationConfiguration-object (available as of Hibernate 3.2). This is an expanded Configuration-object allowing the use of EJB3 annotations and the accompanying Hibernate 3.2 annotation extensions. The method automatically determines which version to use depending on the existence of a hibernate.cfg.xml-file. In that case the more powerful AnnotationConfiguration is used. Bear in mind that even in this case, regular usage of the classic hbm.xml mapping files is still allowed. You merely have the option to mix and match annotations and mapping files or go completely with annotations (for more information see the Hibernate 3.2 documentation).


initialize

public static void initialize(java.lang.Object proxy)

Swizzles in the given hibernate proxy.


clearCache

public static void clearCache()

This operation clears the entire second level cache, as well as the query cache of hibernate. It is primarily intended to be used in the unit testing to avoid interference between test cases...


getEnumFromInt

public static java.lang.Object getEnumFromInt(int id,
                                              java.lang.Class type)

delete

public static void delete(Entity entity)
Register an entity for deletion

Parameters:
entity -

create

public static java.lang.Object create(java.lang.Class clazz)
Factory method for creating new entities. Create an instance of the given class, which will be registered for save in the autosync session.

Parameters:
clazz -
Returns:

autoSync

public static void autoSync(java.util.Collection entities)
                     throws org.hibernate.ObjectDeletedException
Throws:
org.hibernate.ObjectDeletedException

autoSync

public static void autoSync(Entity entity)
                     throws org.hibernate.ObjectDeletedException
Throws:
org.hibernate.ObjectDeletedException

isDeleted

public static boolean isDeleted(Entity entity)

isNew

public static boolean isNew(Entity entity)

createAutoSyncSession

public static AutoSyncSession createAutoSyncSession()

releaseAutoSyncSession

public static void releaseAutoSyncSession()

getAutoSyncSession

public static AutoSyncSession getAutoSyncSession()

isInitialized

public static boolean isInitialized(java.lang.Object proxy)

swizzle

public static void swizzle(java.lang.Object rootEntity,
                           java.lang.String propertyPathList)

swizzleReadOnly

public static java.util.List swizzleReadOnly(Entity rootEntity,
                                             java.lang.String propertyPathList)

swizzleReadOnly

public static java.util.List swizzleReadOnly(java.util.List rootEntities,
                                             java.lang.String propertyPathList)

swizzleReadOnlyFromIds

public static java.util.List swizzleReadOnlyFromIds(java.util.List ids,
                                                    java.lang.Class type,
                                                    java.lang.String propertyPathList)

swizzle

public static void swizzle(java.util.List rootEntities,
                           java.lang.String propertyPathList)

swizzleOnePropertyPath

public static void swizzleOnePropertyPath(java.util.List rootEntities,
                                          java.lang.String propertyPath)

swizzleOnePropertyPathInternal

public static void swizzleOnePropertyPathInternal(java.util.List rootEntities,
                                                  java.lang.String propertyPath)

isMapped

public static boolean isMapped(java.lang.Class clazz)

getInterceptorInstance

public static org.hibernate.Interceptor getInterceptorInstance()