Class Change<T>

java.lang.Object
io.permazen.change.Change<T>
Type Parameters:
T - the type of the object that changed
Direct Known Subclasses:
FieldChange, ObjectCreate, ObjectDelete

public abstract class Change<T> extends Object
Object change notification.
  • Constructor Details

    • Change

      protected Change(T jobj)
      Constructor.
      Parameters:
      jobj - Java model object that changed
      Throws:
      IllegalArgumentException - if jobj is null
  • Method Details

    • getObject

      public T getObject()
      Get the Java model object containing the field that changed.

      Although not declared as such to allow flexibility in Java model types, the returned object will always be a PermazenObject instance.

      Returns:
      the changed object
    • getJObject

      public PermazenObject getJObject()
      Get the Java model object containing the field that changed.

      This is a convenience method, equivalent to:

       (PermazenObject)getObject()
       
      Returns:
      the changed object as a PermazenObject
    • visit

      public abstract <R> R visit(ChangeSwitch<R> target)
      Apply visitor pattern. Invokes the method of target corresponding to this instance's type.
      Type Parameters:
      R - visitor return type
      Parameters:
      target - visitor pattern target
      Returns:
      value returned by the selected method of target
    • apply

      public abstract void apply(PermazenTransaction jtx, PermazenObject jobj)
      Apply this change to the given object in the given transaction.
      Parameters:
      jobj - the target object to which to apply this change
      jtx - the transaction in which to apply this change
      Throws:
      DeletedObjectException - if jobj does not exist in jtx
      UnknownFieldException - if jobj has a schema that does not contain the affected field, or in which the affected field has a different type
      RuntimeException - if there is some other incompatibility between this change and the target object, for example, setting a list element at an index that is out of bounds
      StaleTransactionException - if jtx is no longer usable
      IllegalArgumentException - if jtx or jobj is null
    • apply

      public void apply(PermazenTransaction jtx)
      Apply this change to the object associated with this instance in the given transaction.

      This is a convenience method, equivalent to:

       apply(jtx, this.getJObject());
       
      Parameters:
      jtx - transaction in which to apply this change
      Throws:
      IllegalArgumentException - if jtx is null
    • apply

      public void apply()
      Apply this change to the transaction associated with the current thread.

      This is a convenience method, equivalent to:

       apply(PermazenTransaction.getCurrent())
       
      Throws:
      IllegalStateException - if there is no PermazenTransaction associated with the current thread
    • apply

      public void apply(PermazenObject jobj)
      Apply this change to the specified object.

      This is a convenience method, equivalent to:

       apply(obj.getTransaction(), jobj);
       
      Parameters:
      jobj - object to which to apply this change
      Throws:
      IllegalStateException - if there is no PermazenTransaction associated with jobj
      IllegalArgumentException - if jobj is null
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object