org.unitils.reflectionassert.comparator.impl
Class HibernateProxyComparator
java.lang.Object
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
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
HibernateProxyComparator
public HibernateProxyComparator()
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 objectright
- 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 nullright
- The right object, not nullonlyFirstDifference
- True if only the first difference should be returnedreflectionComparator
- The root comparator for inner comparisons, not null
- Returns:
- A ObjectDifference or null if both maps are equal
Copyright © 2011. All Rights Reserved.