org.unitils.reflectionassert.comparator.impl
Class HibernateProxyComparator

java.lang.Object
  extended by org.unitils.reflectionassert.comparator.impl.HibernateProxyComparator
All Implemented Interfaces:
Comparator

public class HibernateProxyComparator
extends Object
implements Comparator

Comparator that can handle Hibernate proxies.

Special thanks to Tim Peeters for helping us with the implementation.

Author:
Tim Ducheyne, Filip Neven, Tim Peeters

Constructor Summary
HibernateProxyComparator()
           
 
Method Summary
 boolean canCompare(Object left, Object right)
          Returns true if one or both of the objects is a Hibernate proxy.
 Difference compare(Object left, Object right, boolean onlyFirstDifference, ReflectionComparator reflectionComparator)
          Compares the given objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateProxyComparator

public HibernateProxyComparator()
Method Detail

canCompare

public boolean canCompare(Object left,
                          Object right)
Returns true if one or both of the objects is a Hibernate proxy.

Specified by:
canCompare in interface Comparator
Parameters:
left - The left object
right - The right object
Returns:
True if one is a proxy

compare

public Difference compare(Object left,
                          Object right,
                          boolean onlyFirstDifference,
                          ReflectionComparator reflectionComparator)
Compares the given objects. If one of the objects is a proxy, the proxy is initialized and the wrapped values are compared. If both objects are proxies and both objects are not yet loaded (initialized) only the idendtifiers are compared. This avoids unitils performing unnecessary loads from the database (potentially retrieving a huge amount of data). If the ids of the proxies are identical, the objects are considered identical, if not the objects are considered different.

Specified by:
compare in interface Comparator
Parameters:
left - The left object, not null
right - The right object, not null
onlyFirstDifference - True if only the first difference should be returned
reflectionComparator - The root comparator for inner comparisons, not null
Returns:
A ObjectDifference or null if both maps are equal


Copyright © 2011. All Rights Reserved.