Package org.dellroad.stuff.pobj
Class AbstractDelegate<T>
java.lang.Object
org.dellroad.stuff.pobj.AbstractDelegate<T>
- Type Parameters:
T- type of the root persistent object
- All Implemented Interfaces:
PersistentObjectDelegate<T>
- Direct Known Subclasses:
SpringDelegate
Support superclass for
PersistentObjectDelegate classes, with implementations of all methods
other than serialize() and deserialize().- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMake a deep copy of the given object.Get the default value for the root object graph.voidhandleWritebackException(PersistentObject<T> pobj, Throwable t) Handle an exception thrown during a delayed write-back attempt.booleanisSameGraph(T root1, T root2) Compare two object graphs.Validate the given instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.dellroad.stuff.pobj.PersistentObjectDelegate
deserialize, serialize
-
Field Details
-
log
-
-
Constructor Details
-
AbstractDelegate
public AbstractDelegate()
-
-
Method Details
-
copy
Make a deep copy of the given object.The implementation in
AbstractDelegatedoes this by serializing and then deserializing the object graph. Subclasses are encouraged to provide a more efficient implementation, for example, by implementingGraphCloneable.- Specified by:
copyin interfacePersistentObjectDelegate<T>- Parameters:
original- original object- Returns:
- deep copy of the object graph rooted at
original - Throws:
IllegalArgumentException- iforiginalis nullPersistentObjectException- if an error occurs
-
isSameGraph
Compare two object graphs.The implementation in
AbstractDelegateonly returns true ifroot1 == root2. This is a very conservative implementation. If your root object graph correctly implementsequals(), thenroot1.equals(root2)would be a more appropriate test.- Specified by:
isSameGraphin interfacePersistentObjectDelegate<T>- Parameters:
root1- first object graph (never null)root2- second object graph (never null)- Returns:
- true if
root1androot2represent equal object graphs
-
validate
Validate the given instance.The implementation in
AbstractDelegateperforms validation usingValidationContext.validate().- Specified by:
validatein interfacePersistentObjectDelegate<T>- Parameters:
obj- root object- Returns:
- set of zero or more constraint violations
- Throws:
IllegalArgumentException- ifobjis null
-
handleWritebackException
Handle an exception thrown during a delayed write-back attempt.ThreadDeathexceptions are not passed to this method, but all others are.The implementation in
AbstractDelegatesimply logs an error tolog.- Specified by:
handleWritebackExceptionin interfacePersistentObjectDelegate<T>- Parameters:
pobj- the instance that encountered the exceptiont- the exception thrown
-
getDefaultValue
Get the default value for the root object graph. This method is invoked at startup when the persistent file does not exist. If this method returns null, then an empty start occurs unless thePersistentObjectobject is configured to disallow them, in which case an exception is thrown.The implementation in
AbstractDelegatereturns null.- Specified by:
getDefaultValuein interfacePersistentObjectDelegate<T>- Returns:
- root object initial value, or null if there is no default value
-