Class PersistenceStorerDeactivatable
- All Implemented Interfaces:
PersistenceStorer,PersistenceStoring,Storer
public class PersistenceStorerDeactivatable extends Object implements PersistenceStorer
PersistenceStorer implementation that allows
switching between the supplied PersistenceStorer instance and a
PersistenceStorerDeactivated
instance.-
Nested Class Summary
Nested classes/interfaces inherited from interface one.microstream.persistence.types.PersistenceStorer
PersistenceStorer.CreationObserver, PersistenceStorer.Creator<D> -
Constructor Summary
Constructors Constructor Description PersistenceStorerDeactivatable(PersistenceStorer persistenceStorer) -
Method Summary
Modifier and Type Method Description voidclear()Clears all internal state regarding collected data and/or registered skips.Objectcommit()Ends the data collection process and causes all collected data to be persisted.longcurrentCapacity()Returns the internal state's value significant for its capacity of unique instances.voiddisableWrites()Disable writing supportvoidenableWrites()Enable writing support.PersistenceStorerensureCapacity(long desiredCapacity)Ensures that the instance's internal state is prepared for handling an amount of unique instance equal to the passed value.booleanisEmpty()Queries, whether thisStorerinstance has no instances / references registered.booleanisWriteEnabled()Check if writing support is enabled.longmaximumCapacity()The maximum value thatStorer.currentCapacity()can reach.PersistenceStorerreinitialize()Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary.PersistenceStorerreinitialize(long initialCapacity)Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary.voidsetWriteEnabled(boolean enableWrites)Enable or disable writing support.longsize()booleanskip(Object instance)Registers the passed instance to be skipped from the data persisting process.booleanskipMapped(Object instance, long objectId)Registers the passed instance under the passed objectId without persisting its data.booleanskipNulled(Object instance)Registers the passed instance to be skipped from the data persisting process.longstore(Object instance)Stores the passed instance in any case and all referenced instances of persistable references recursively, but stores referenced instances only if they are newly encountered (e.g.voidstoreAll(Iterable<?> instances)Convenience method toPersistenceStoring.store(Object)all instances of anIterabletype, usually a collection.
The passed instance itself is NOT stored.
Note that this method does not return an array of objectIds, since the amount of instances supplied by the passedIterablecannot be known until after all instances have been stored and the memory and performance overhead to collect them dynamically would not be worth it in most cases since the returned array is hardly ever needed.long[]storeAll(Object... instances)Convenience method toPersistenceStoring.store(Object)multiple instances.
-
Constructor Details
-
Method Details
-
setWriteEnabled
public void setWriteEnabled(boolean enableWrites)Enable or disable writing support.- Parameters:
enableWrites- true to enable writing, false to disable.
-
isWriteEnabled
public boolean isWriteEnabled()Check if writing support is enabled.- Returns:
- true if writes are enabled
-
enableWrites
public void enableWrites()Enable writing support. -
disableWrites
public void disableWrites()Disable writing support -
reinitialize
Description copied from interface:PersistenceStorerEnforces the instance to be initialized, discarding any previous state (clearing it) if necessary.- Specified by:
reinitializein interfacePersistenceStorer- Specified by:
reinitializein interfaceStorer- Returns:
- this.
-
store
Description copied from interface:PersistenceStoringStores the passed instance in any case and all referenced instances of persistable references recursively, but stores referenced instances only if they are newly encountered (e.g. don't have an id associated with them in the object registry, yet and are therefore required to be handled). This is useful for the common case of just storing an updated instance and potentially newly created instances along with it while skipping all existing (and normally unchanged) referenced instances.- Specified by:
storein interfacePersistenceStoring- Parameters:
instance- the root instance of the subgraph of required instances to be stored.- Returns:
- the object id representing the passed instance.
-
reinitialize
Description copied from interface:PersistenceStorerEnforces the instance to be initialized, discarding any previous state (clearing it) if necessary.- Specified by:
reinitializein interfacePersistenceStorer- Specified by:
reinitializein interfaceStorer- Parameters:
initialCapacity- the amount of unique instances that this instance shall prepare to handle.- Returns:
- this.
-
commit
Description copied from interface:StorerEnds 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.
-
ensureCapacity
Description copied from interface:PersistenceStorerEnsures 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.- Specified by:
ensureCapacityin interfacePersistenceStorer- Specified by:
ensureCapacityin interfaceStorer- Parameters:
desiredCapacity- the amount of unique instances that this instance shall prepare to handle.- Returns:
- this
-
clear
public void clear()Description copied from interface:StorerClears all internal state regarding collected data and/or registered skips. -
storeAll
Description copied from interface:PersistenceStoringConvenience method toPersistenceStoring.store(Object)multiple instances. The passed array (maybe implicitely created by the compiler) itself is NOT stored.- Specified by:
storeAllin interfacePersistenceStoring- Parameters:
instances- multiple root instances of the subgraphs of required instances to be stored.- Returns:
- an array containing the object ids representing the passed instances.
-
skipMapped
Description copied from interface:StorerRegisters 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:Storer.skip(Object)Storer.skipNulled(Object)- Specified by:
skipMappedin interfaceStorer- 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:
Storer.skip(Object),Storer.skipNulled(Object)
-
storeAll
Description copied from interface:PersistenceStoringConvenience method toPersistenceStoring.store(Object)all instances of anIterabletype, usually a collection.
The passed instance itself is NOT stored.
Note that this method does not return an array of objectIds, since the amount of instances supplied by the passedIterablecannot be known until after all instances have been stored and the memory and performance overhead to collect them dynamically would not be worth it in most cases since the returned array is hardly ever needed. If it should be needed, the desired behavior can be easily achieved with a tiny custom-made utility method.- Specified by:
storeAllin interfacePersistenceStoring- Parameters:
instances- multiple root instances of the subgraphs of required instances to be stored.
-
skip
Description copied from interface:StorerRegisters 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 asStorer.skipNulled(Object).- Specified by:
skipin interfaceStorer- Parameters:
instance- the instance / reference to be skipped.- Returns:
- true if the instance has been newly registered, false if it already was.
- See Also:
Storer.skipNulled(Object),Storer.skipMapped(Object, long)
-
skipNulled
Description copied from interface:StorerRegisters 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, useStorer.skip(Object).- Specified by:
skipNulledin interfaceStorer- 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:
Storer.skip(Object),Storer.skipMapped(Object, long)
-
size
public long size()- Specified by:
sizein interfaceStorer- Returns:
- the amount of unique instances / references that have already been registered by this
Storerinstance. This includes both instances encountered during the data collection process and instances that have explicitely been registered to be skipped. - See Also:
Storer.skip(Object),Storer.skipMapped(Object, long)
-
isEmpty
public boolean isEmpty()Description copied from interface:StorerQueries, whether thisStorerinstance has no instances / references registered.Calling this method is simply an alias for
this.size() == 0L. -
currentCapacity
public long currentCapacity()Description copied from interface:StorerReturns 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).- Specified by:
currentCapacityin interfaceStorer- Returns:
- the current implementation-specific "capacity" value.
-
maximumCapacity
public long maximumCapacity()Description copied from interface:StorerThe maximum value thatStorer.currentCapacity()can reach. For more explanation on the exact meaning of the capacity, see there.- Specified by:
maximumCapacityin interfaceStorer- Returns:
- the maximum of the implementation-specific "capacity" value.
-