Package io.permazen

Class CopyState

java.lang.Object
io.permazen.CopyState

@NotThreadSafe public class CopyState extends Object
Holds state during a multi-object copy operation.

This class keeps tracks of which objects have already been copied when copying objects between transactions.

It also supports assigning different object ID's to objects as they are copied into the destination transaction.

Instances are not thread safe.

See Also:
  • Constructor Details

    • CopyState

      public CopyState(boolean suppressNotifications)
      Simple constructor.

      No object ID's will be remapped.

      Equivalent to: CopyState(new ObjIdSet(), null, suppressNotifications).

      Parameters:
      suppressNotifications - true to suppress create and change notifications, otherwise false
    • CopyState

      public CopyState(ObjIdMap<ObjId> objectIdMap, boolean suppressNotifications)
      Parameters:
      objectIdMap - mapping from source object ID to destination object ID
      suppressNotifications - true to suppress create and change notifications, otherwise false
      Throws:
      IllegalArgumentException - if objectIdMap is null
    • CopyState

      public CopyState(ObjIdSet copied, ObjIdMap<ObjId> objectIdMap, boolean suppressNotifications)
      Primary constructor.

      Objects whose object ID's are in copied will not be copied.

      Otherwise, copied objects will have their object ID's remapped based on objectIdMap:

      • If an object's ID does not exist in objectIdMap, then the same ID is used for the copy
      • If an object's ID is mapped to a non-null value in objectIdMap, then that ID is used for the copy
      • Otherwise, a new, unused ID is allocated for the copy, and objectIdMap is updated if/when that occurs
      Parameters:
      copied - the ID's of objects that have already been copied
      objectIdMap - optional mapping from source object ID to remapped destination object ID
      suppressNotifications - true to suppress create and change notifications, otherwise false
      Throws:
      IllegalArgumentException - if either parameter is null
    • CopyState

      public CopyState(CopyState original)
      Copy constructor.
      Parameters:
      original - instance to copy
  • Method Details

    • markCopied

      public boolean markCopied(ObjId srcId)
      Determine if an object has already been copied, and if not mark it so.
      Parameters:
      srcId - object ID (in the source transaction) of the object being copied
      Returns:
      true if srcId was not previously marked copied, otherwise false
      Throws:
      IllegalArgumentException - if srcId is null
    • isCopied

      public boolean isCopied(ObjId srcId)
      Determine if an object has been marked as copied.
      Parameters:
      srcId - object ID (in the source transaction) of the object being copied
      Returns:
      true if srcId has been marked copied, otherwise false
      Throws:
      IllegalArgumentException - if srcId is null
    • isSuppressNotifications

      public boolean isSuppressNotifications()
      Determine whether to suppress @OnCreate and @OnChange notifications in the destination transaction.
      Returns:
      true if @OnCreate and @OnChange notifications should be suppressed, otherwise false
    • getObjectIdMap

      public ObjIdMap<ObjId> getObjectIdMap()
      Get the mapping from object ID in the source transaction to object ID to use in the destination transaction.

      This method returns the objectIdMap parameter given to the constructor.

      Returns:
      mapping from source transaction object ID to destination transaction object ID
    • getDestId

      public ObjId getDestId(ObjId srcId)
      Get the object ID for the copy of the given source object.

      This assumes the object has already been copied, so its new, remapped object ID (if any) has already been updated in the object ID map. This can be verified using isCopied().

      Parameters:
      srcId - source transaction object ID of an object that has been copied
      Returns:
      destination transaction object ID corresponding to srcId, never null
      Throws:
      IllegalArgumentException - if srcId is null