Class BinaryStorer.Default
- java.lang.Object
-
- one.microstream.persistence.binary.types.BinaryStorer.Default
-
- All Implemented Interfaces:
BinaryStorer,PersistenceAcceptor,PersistenceFunction,PersistenceStoreHandler,PersistenceStorer<Binary>,PersistenceStoring,Storer
- Direct Known Subclasses:
BinaryStorer.Eager
- Enclosing interface:
- BinaryStorer
public static class BinaryStorer.Default extends Object implements BinaryStorer, PersistenceStoreHandler, PersistenceAcceptor
Default implementation that stores referenced instances only if required (i.e. if they have no OID assigned yet, therefore have not been stored yet, therefore require to be stored). It can be seen as a "lazy" or "on demand" storer as opposed toBinaryStorer.Eager.
For a more differentiated solution between the two simple, but extreme strategies, seePersistenceEagerStoringFieldEvaluator.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface one.microstream.persistence.binary.types.BinaryStorer
BinaryStorer.Creator, BinaryStorer.Default, BinaryStorer.Eager, BinaryStorer.Item
-
-
Constructor Summary
Constructors Constructor Description Default()
-
Method Summary
Modifier and Type Method Description voidaccept(long objectId, Object instance)<T> longapply(T instance)The "natural" way of handling an instance as defined by the implementation.<T> longapplyEager(T instance)A way to signal to the implementation that the passed instance is supposed to be handled eagerly, meaning it shall be handled even if the handling implementation does not deem it necessary.
This is needed, for example, to store composition pattern instances without breaking OOP encapsulation concepts.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.PersistenceStorer<Binary>ensureCapacity(long desiredCapacity)Ensures that the instance's internal state is prepared for handling an amount of unique instance equal to the passed value.PersistenceObjectRetrievergetObjectRetriever()BinaryStorerinitialize()Ensures the storer instance is initialized, i.e.BinaryStorerinitialize(long initialCapacity)Ensures the storer instance is initialized, i.e.booleanisInitialized()Returns whether thisStorerinstance has been initialized.longlookupOid(Object instance)longmaximumCapacity()The maximum value thatStorer.currentCapacity()can reach.voidrebuildStoreItems()voidrebuildStoreItems(int newLength)BinaryStorer.ItemregisterobjectId(Object instance, PersistenceTypeHandler<Binary,Object> typeHandler, long objectId)voidregisterSkip(Object instance)Registers the passed instance to be skipped from the data persisting process.voidregisterSkip(Object instance, long objectId)Registers the passed instance under the passed objectId without persisting its data.PersistenceStorer<Binary>reinitialize()Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to callingStorer.initialize().PersistenceStorer<Binary>reinitialize(long initialCapacity)Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to callingStorer.initialize().longsize()longstore(Object root)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.voidstoreSelfStoring(SelfStoring storing)
-
-
-
Method Detail
-
apply
public <T> long apply(T instance)
Description copied from interface:PersistenceStoreHandlerThe "natural" way of handling an instance as defined by the implementation.- Specified by:
applyin interfacePersistenceFunction- Specified by:
applyin interfacePersistenceStoreHandler- Parameters:
instance- the instance to which the function shall be applied.- Returns:
- the object ID (OID) that is associated with the passed instance.
-
applyEager
public final <T> long applyEager(T instance)
Description copied from interface:PersistenceStoreHandlerA way to signal to the implementation that the passed instance is supposed to be handled eagerly, meaning it shall be handled even if the handling implementation does not deem it necessary.
This is needed, for example, to store composition pattern instances without breaking OOP encapsulation concepts.- Specified by:
applyEagerin interfacePersistenceStoreHandler
-
getObjectRetriever
public final PersistenceObjectRetriever getObjectRetriever()
- Specified by:
getObjectRetrieverin interfacePersistenceStoreHandler
-
initialize
public BinaryStorer initialize()
Description copied from interface:PersistenceStorerEnsures the storer instance is initialized, i.e. ready to perform storing. This method is idempotent. For a forced (re)initialization, seeStorer.reinitialize().- Specified by:
initializein interfaceBinaryStorer- Specified by:
initializein interfacePersistenceStorer<Binary>- Specified by:
initializein interfaceStorer- Returns:
- this.
-
initialize
public BinaryStorer initialize(long initialCapacity)
Description copied from interface:PersistenceStorerEnsures 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 passedinitialCapacityis 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, seeStorer.reinitialize(long).- Specified by:
initializein interfaceBinaryStorer- Specified by:
initializein interfacePersistenceStorer<Binary>- Specified by:
initializein interfaceStorer- Returns:
- this.
-
reinitialize
public PersistenceStorer<Binary> reinitialize()
Description copied from interface:PersistenceStorerEnforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to callingStorer.initialize().- Specified by:
reinitializein interfaceBinaryStorer- Specified by:
reinitializein interfacePersistenceStorer<Binary>- Specified by:
reinitializein interfaceStorer- Returns:
- this.
-
reinitialize
public PersistenceStorer<Binary> reinitialize(long initialCapacity)
Description copied from interface:PersistenceStorerEnforces the instance to be initialized, discarding any previous state (clearing it) if necessary prior to callingStorer.initialize().- Specified by:
reinitializein interfaceBinaryStorer- Specified by:
reinitializein interfacePersistenceStorer<Binary>- Specified by:
reinitializein interfaceStorer- Returns:
- this.
-
currentCapacity
public final 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 interfaceBinaryStorer- Specified by:
currentCapacityin interfaceStorer- Returns:
- the current implementation-specific "capacity" value.
-
maximumCapacity
public final 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 interfaceBinaryStorer- Specified by:
maximumCapacityin interfaceStorer- Returns:
- the maximum of the implementation-specific "capacity" value.
-
ensureCapacity
public PersistenceStorer<Binary> ensureCapacity(long desiredCapacity)
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 interfaceBinaryStorer- Specified by:
ensureCapacityin interfacePersistenceStorer<Binary>- Specified by:
ensureCapacityin interfaceStorer- Parameters:
desiredCapacity- the amount of unique instances that this instance shall prepare to handle.- Returns:
- this
-
isInitialized
public final boolean isInitialized()
Description copied from interface:StorerReturns whether thisStorerinstance 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.
- Specified by:
isInitializedin interfaceStorer- Returns:
- whether this
Storerinstance has been initialized.
-
size
public final 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.registerSkip(Object),Storer.registerSkip(Object,long)
-
store
public final long store(Object root)
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:
root- the root instance of the subgraph of required instances to be stored.- Returns:
- the object id representing the passed instance.
-
storeAll
public final long[] storeAll(Object... instances)
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.
-
storeAll
public void storeAll(Iterable<?> instances)
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.
-
storeSelfStoring
public void storeSelfStoring(SelfStoring storing)
- Specified by:
storeSelfStoringin interfacePersistenceStoring
-
commit
public final Object 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.
-
clear
public void clear()
Description copied from interface:StorerClears all internal state regarding collected data and/or registered skips.
-
lookupOid
public final long lookupOid(Object instance)
-
rebuildStoreItems
public final void rebuildStoreItems()
-
rebuildStoreItems
public final void rebuildStoreItems(int newLength)
-
accept
public final void accept(long objectId, Object instance)- Specified by:
acceptin interfacePersistenceAcceptor
-
registerobjectId
public final BinaryStorer.Item registerobjectId(Object instance, PersistenceTypeHandler<Binary,Object> typeHandler, long objectId)
-
registerSkip
public final void registerSkip(Object instance, long objectId)
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.
- Specified by:
registerSkipin interfaceStorer- Parameters:
instance- the instance / reference to be skipped.objectId- the objectId to be used as a reference to the skipped instance.- See Also:
Storer.registerSkip(Object)
-
registerSkip
public final void registerSkip(Object instance)
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.
- Specified by:
registerSkipin interfaceStorer- Parameters:
instance- the instance / reference to be skipped.- See Also:
Storer.registerSkip(Object,long)
-
-