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

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:
  • Field Details

    • log

      protected final Logger log
  • Constructor Details

    • AbstractDelegate

      public AbstractDelegate()
  • Method Details

    • 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, for example, by implementing GraphCloneable.

      Specified by:
      copy in interface PersistentObjectDelegate<T>
      Parameters:
      original - original object
      Returns:
      deep copy of the object graph rooted at original
      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 only returns true if root1 == root2. This is a very conservative implementation. If your root object graph correctly implements equals(), then root1.equals(root2) would be a more appropriate test.

      Specified by:
      isSameGraph in interface PersistentObjectDelegate<T>
      Parameters:
      root1 - first object graph (never null)
      root2 - second object graph (never null)
      Returns:
      true if root1 and root2 represent equal object graphs
    • validate

      public Set<jakarta.validation.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>
      Parameters:
      obj - root object
      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
    • getDefaultValue

      public T 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 the PersistentObject object is configured to disallow them, in which case an exception is thrown.

      The implementation in AbstractDelegate returns null.

      Specified by:
      getDefaultValue in interface PersistentObjectDelegate<T>
      Returns:
      root object initial value, or null if there is no default value