org.unitils.reflectionassert.util
Class HibernateUtil

java.lang.Object
  extended by org.unitils.reflectionassert.util.HibernateUtil

public class HibernateUtil
extends Object

Utility class for handling Hibernate proxies during the comparison.

Every operation is performed through reflection to avoid a direct link to Hibernate. This way you do not need Hibernate in the classpath to use the reflection comparator.

Author:
Tim Ducheyne, Filip Neven

Field Summary
protected static Class<?> hibernateProxyClass
          The hibernate proxy type, null if the class is not found in the classpath
 
Constructor Summary
HibernateUtil()
           
 
Method Summary
static String getEntitiyName(Object object)
          Gets the class name of the proxied object
static Object getIdentifier(Object object)
          Gets the unique identifier of the given proxy object.
static Object getUnproxiedValue(Object object)
          Gets (and loads) the wrapped object out of a given hibernate proxy.
protected static Object invokeLazyInitializerMethod(String methodName, Object proxy)
          Invokes the given method on the LazyInitializer that is associated with the given proxy.
static boolean isHibernateProxy(Object object)
          Checks whether the given ojbect is a HibernateProxy instance.
static boolean isUninitialized(Object object)
          Checks whether the given proxy object has been loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hibernateProxyClass

protected static Class<?> hibernateProxyClass
The hibernate proxy type, null if the class is not found in the classpath

Constructor Detail

HibernateUtil

public HibernateUtil()
Method Detail

isHibernateProxy

public static boolean isHibernateProxy(Object object)
Checks whether the given ojbect is a HibernateProxy instance.

Parameters:
object - The object
Returns:
True if the object is a proxy

isUninitialized

public static boolean isUninitialized(Object object)
Checks whether the given proxy object has been loaded.

Parameters:
object - The object or proxy
Returns:
True if the object is a proxy and has been loaded

getEntitiyName

public static String getEntitiyName(Object object)
Gets the class name of the proxied object

Parameters:
object - The object or proxy
Returns:
The class name of the object, null if the object is null

getIdentifier

public static Object getIdentifier(Object object)
Gets the unique identifier of the given proxy object.

Parameters:
object - The object or proxy
Returns:
The identifier or null if the object was not a proxy

getUnproxiedValue

public static Object getUnproxiedValue(Object object)
Gets (and loads) the wrapped object out of a given hibernate proxy.

If the given object is not a proxy or if Hibernate is not found in the classpath, this method just returns the given object. If the given object is a proxy, the proxy is initialized (loaded) and the un-wrapped object is returned.

Parameters:
object - The object or proxy
Returns:
The uproxied object or the object itself if it was no proxy

invokeLazyInitializerMethod

protected static Object invokeLazyInitializerMethod(String methodName,
                                                    Object proxy)
Invokes the given method on the LazyInitializer that is associated with the given proxy.

Parameters:
methodName - The method to invoke, not null
proxy - The hibernate proxy instance, not null
Returns:
The result value of the method call


Copyright © 2011. All Rights Reserved.