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 simplePersistenceStoring
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. Seeskip(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.Storer
initialize()
Ensures the storer instance is initialized, i.e.Storer
initialize(long initialCapacity)
Ensures the storer instance is initialized, i.e.default boolean
isEmpty()
Queries, whether thisStorer
instance has no instances / references registered.boolean
isInitialized()
Returns whether thisStorer
instance has been initialized.long
maximumCapacity()
The maximum value thatcurrentCapacity()
can reach.Storer
reinitialize()
Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to callinginitialize()
.Storer
reinitialize(long initialCapacity)
Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to callinginitialize()
.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 Detail
-
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 asskipNulled(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
PersistenceObjectRegistry
or not.
To make the skipping consider existing object id registrations, useskip(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 this
Storer
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 thisStorer
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 thatcurrentCapacity()
can reach. For more explanation on the exact meaning of the capacity, see there.- Returns:
- the maximum of the implementation-specific "capacity" value.
-
isInitialized
boolean isInitialized()
Returns whether thisStorer
instance has been initialized.That being initialized means exactely depends on the implementation. The general contract means to bring the instance's internal data into a state with which the instance can be used to perform its actual tasks.
- Returns:
- whether this
Storer
instance has been initialized.
-
initialize
Storer initialize()
Ensures the storer instance is initialized, i.e. ready to perform storing. This method is idempotent. For a forced (re)initialization, seereinitialize()
.- Returns:
- this.
-
initialize
Storer initialize(long initialCapacity)
Ensures the storer instance is initialized, i.e. ready to perform storing. If the storer instance needs to be initialized as a consequence of this call, the passedinitialCapacity
is considered as an estimate for the number of unique instances to be handled until the next commit. This method is idempotent, meaning if this instance is already initialized, the passed value might not have any effect. For a forced (re)initialization, seereinitialize(long)
.- Returns:
- this.
-
reinitialize
Storer reinitialize()
Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to callinginitialize()
.- Returns:
- this.
-
reinitialize
Storer reinitialize(long initialCapacity)
Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to callinginitialize()
.- 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
-
-