org.dellroad.stuff.pobj
Class AbstractDelegate<T>

java.lang.Object
  extended by org.dellroad.stuff.pobj.AbstractDelegate<T>
Type Parameters:
T - type of the root persistent object
All Implemented Interfaces:
PersistentObjectDelegate<T>
Direct Known Subclasses:
SpringDelegate

public abstract class AbstractDelegate<T>
extends Object
implements PersistentObjectDelegate<T>

Support superclass for PersistentObjectDelegate classes, with implementations of all methods other than serialize() and deserialize().

See Also:
PersistentObject

Field Summary
protected  Logger log
           
 
Constructor Summary
AbstractDelegate()
           
 
Method Summary
 T copy(T original)
          Make a deep copy of the given object.
 void handleWritebackException(PersistentObject<T> pobj, Throwable t)
          Handle an exception thrown during a delayed write-back attempt.
 boolean isSameGraph(T root1, T root2)
          Compare two object graphs.
 Set<ConstraintViolation<T>> validate(T obj)
          Validate the given instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.dellroad.stuff.pobj.PersistentObjectDelegate
deserialize, serialize
 

Field Detail

log

protected final Logger log
Constructor Detail

AbstractDelegate

public AbstractDelegate()
Method Detail

copy

public T copy(T original)
Make a deep copy of the given object.

The implementation in AbstractDelegate does this by serializing and then deserializing the object graph. Subclasses are encouraged to provide a more efficient implementation.

Specified by:
copy in interface PersistentObjectDelegate<T>
Throws:
IllegalArgumentException - if original is null
PersistentObjectException - if an error occurs

isSameGraph

public boolean isSameGraph(T root1,
                           T root2)
Compare two object graphs.

The implementation in AbstractDelegate always returns true only if root1 and root2 are the same object.

Specified by:
isSameGraph in interface PersistentObjectDelegate<T>
Parameters:
root1 - root of first object graph
root2 - root of second object graph

validate

public Set<ConstraintViolation<T>> validate(T obj)
Validate the given instance.

The implementation in AbstractDelegate performs validation using ValidationContext.validate().

Specified by:
validate in interface PersistentObjectDelegate<T>
Returns:
set of zero or more constraint violations
Throws:
IllegalArgumentException - if obj is null

handleWritebackException

public void handleWritebackException(PersistentObject<T> pobj,
                                     Throwable t)
Handle an exception thrown during a delayed write-back attempt. ThreadDeath exceptions are not passed to this method, but all others are.

The implementation in AbstractDelegate simply logs an error to log.

Specified by:
handleWritebackException in interface PersistentObjectDelegate<T>
Parameters:
pobj - the instance that encountered the exception
t - the exception thrown