Interface Storer

All Superinterfaces:
PersistenceStoring
All Known Subinterfaces:
BinaryStorer, PersistenceStorer
All Known Implementing Classes:
BinaryStorer.Default, BinaryStorer.Eager

public interface Storer
extends PersistenceStoring
A type extending the simple PersistenceStoring to enable stateful store handling. This can be used to do what is generally called "transactions": preprocess data to be stored and then store either all or nothing.
It can also be used to skip certain references. See skip(Object)
The deviating naming (missing "Persistence" prefix) is intentional to support convenience on the application code level.
  • Method Summary

    Modifier and Type Method Description
    void clear()
    Clears all internal state regarding collected data and/or registered skips.
    Object commit()
    Ends the data collection process and causes all collected data to be persisted.
    long currentCapacity()
    Returns the internal state's value significant for its capacity of unique instances.
    Storer ensureCapacity​(long desiredCapacity)
    Ensures that the instance's internal state is prepared for handling an amount of unique instance equal to the passed value.
    default boolean isEmpty()
    Queries, whether this Storer instance has no instances / references registered.
    long maximumCapacity()
    The maximum value that currentCapacity() can reach.
    Storer reinitialize()
    Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to calling #initialize().
    Storer reinitialize​(long initialCapacity)
    Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to calling #initialize().
    long size()  
    boolean skip​(Object instance)
    Registers the passed instance to be skipped from the data persisting process.
    boolean skipMapped​(Object instance, long objectId)
    Registers the passed instance under the passed objectId without persisting its data.
    boolean skipNulled​(Object instance)
    Registers the passed instance to be skipped from the data persisting process.

    Methods inherited from interface one.microstream.persistence.types.PersistenceStoring

    store, storeAll, storeAll
  • Method Details

    • commit

      Object commit()
      Ends the data collection process and causes all collected data to be persisted.

      This is an atomatic all-or-nothing operation: either all collected data will be persisted successfully, or non of it will be persisted. Partially persisted data will be reverted / rolled back in case of a failure.

      Returns:
      some kind of status information, potentially null.
    • clear

      void clear()
      Clears all internal state regarding collected data and/or registered skips.
    • skipMapped

      boolean skipMapped​(Object instance, long objectId)
      Registers the passed instance under the passed objectId without persisting its data.

      This skip means that if the passed instance is encountered while collecting data to be persisted, its data will NOT be collected. References to the passed instance will be persisted as the passed objectId.

      Warning:
      This method can be very useful to rearrange object graphs on the persistence level, but it can also cause inconsistencies if not used perfectly correctly.
      It is strongly advised to use one of the following alternatives instead: skip(Object)skipNulled(Object)

      Parameters:
      instance - the instance / reference to be skipped.
      objectId - the objectId to be used as a reference to the skipped instance.
      Returns:
      true if the instance has been newly registered, false if it already was.
      See Also:
      skip(Object), skipNulled(Object)
    • skip

      boolean skip​(Object instance)
      Registers the passed instance to be skipped from the data persisting process.

      This skip means that if the passed instance is encountered while collecting data to be persisted, its data will NOT be collected. If the instance is already registered under a certain object id at the used PersistenceObjectRegistry, then is associated object id will be used. Otherwise, the null-Id will be used, effectively "nulling out" all references to this instance on the persistent level.
      The latter behavior is exactly the same as skipNulled(Object).

      Parameters:
      instance - the instance / reference to be skipped.
      Returns:
      true if the instance has been newly registered, false if it already was.
      See Also:
      skipNulled(Object), skipMapped(Object,long)
    • skipNulled

      boolean skipNulled​(Object instance)
      Registers the passed instance to be skipped from the data persisting process.

      This skip means that if the passed instance is encountered while collecting data to be persisted, its data will NOT be collected. References to this instance will always be persisted as null, no matter if the instance is already registered for a certain object id at the used PersistenceObjectRegistryor not.
      To make the skipping consider existing object id registrations, use skip(Object).

      Parameters:
      instance - the instance / reference to be skipped by using .
      Returns:
      true if the instance has been newly registered, false if it already was.
      See Also:
      skip(Object), skipMapped(Object,long)
    • size

      long size()
      Returns:
      the amount of unique instances / references that have already been registered by thisStorer instance. This includes both instances encountered during the data collection process and instances that have explicitely been registered to be skipped.
      See Also:
      skip(Object), skipMapped(Object,long)
    • isEmpty

      default boolean isEmpty()
      Queries, whether this Storer instance has no instances / references registered.

      Calling this method is simply an alias for this.size() == 0L.

      Returns:
      whether this Storer instance is empty.
    • currentCapacity

      long currentCapacity()
      Returns the internal state's value significant for its capacity of unique instances. Note that the exact meaning of this value is implementation dependant, e.g. it might just be a hash table's length, while the actual amount of unique instances that can be handled by that hash table might be much higher (infinite).
      Returns:
      the current implementation-specific "capacity" value.
    • maximumCapacity

      long maximumCapacity()
      The maximum value that currentCapacity() can reach. For more explanation on the exact meaning of the capacity, see there.
      Returns:
      the maximum of the implementation-specific "capacity" value.
    • reinitialize

      Storer reinitialize()
      Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to calling #initialize().
      Returns:
      this.
    • reinitialize

      Storer reinitialize​(long initialCapacity)
      Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to calling #initialize().
      Returns:
      this.
    • ensureCapacity

      Storer ensureCapacity​(long desiredCapacity)
      Ensures that the instance's internal state is prepared for handling an amount of unique instance equal to the passed value. Note that is explicitly does not have to mean that the instance's internal state actually reserves as much space, only makes a best effort to prepare for that amount. Example: an internal hash table's hash length might still remain at 2^30, despite the passed value being much higher.
      Parameters:
      desiredCapacity - the amount of unique instances that this instance shall prepare to handle.
      Returns:
      this