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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionMake a deep copy of the given object.Get the default value for the root object graph.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.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 Details
-
log
-
-
Constructor Details
-
AbstractDelegate
public AbstractDelegate()
-
-
Method Details
-
copy
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, for example, by implementingGraphCloneable
.- Specified by:
copy
in interfacePersistentObjectDelegate<T>
- Parameters:
original
- original object- Returns:
- deep copy of the object graph rooted at
original
- Throws:
IllegalArgumentException
- iforiginal
is nullPersistentObjectException
- if an error occurs
-
isSameGraph
Compare two object graphs.The implementation in
AbstractDelegate
only 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:
isSameGraph
in interfacePersistentObjectDelegate<T>
- Parameters:
root1
- first object graph (never null)root2
- second object graph (never null)- Returns:
- true if
root1
androot2
represent equal object graphs
-
validate
Validate the given instance.The implementation in
AbstractDelegate
performs validation usingValidationContext.validate()
.- Specified by:
validate
in interfacePersistentObjectDelegate<T>
- Parameters:
obj
- root object- Returns:
- set of zero or more constraint violations
- Throws:
IllegalArgumentException
- ifobj
is null
-
handleWritebackException
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 tolog
.- Specified by:
handleWritebackException
in 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 thePersistentObject
object is configured to disallow them, in which case an exception is thrown.The implementation in
AbstractDelegate
returns null.- Specified by:
getDefaultValue
in interfacePersistentObjectDelegate<T>
- Returns:
- root object initial value, or null if there is no default value
-