Class BinaryStorer.Default
- All Implemented Interfaces:
BinaryStorer
,PersistenceFunction
,PersistenceLocalObjectIdRegistry<Binary>
,PersistenceObjectIdRequestor<Binary>
,PersistenceStoreHandler<Binary>
,PersistenceStorer
,PersistenceStoring
,Storer
- Direct Known Subclasses:
BinaryStorer.Eager
- Enclosing interface:
- BinaryStorer
public static class BinaryStorer.Default extends Object implements BinaryStorer, PersistenceStoreHandler<Binary>, PersistenceLocalObjectIdRegistry<Binary>
BinaryStorer.Eager
.For a more differentiated solution between the two simple, but extreme strategies, see
PersistenceEagerStoringFieldEvaluator
.-
Nested Class Summary
Nested classes/interfaces inherited from interface one.microstream.persistence.binary.types.BinaryStorer
BinaryStorer.Creator, BinaryStorer.Default, BinaryStorer.Eager, BinaryStorer.Item
Nested classes/interfaces inherited from interface one.microstream.persistence.types.PersistenceObjectIdRequestor
PersistenceObjectIdRequestor.NoOp<D>
-
Constructor Summary
Constructors Constructor Description Default()
-
Method Summary
Modifier and Type Method Description <T> long
apply(T instance)
The "natural" way of handling an instance as defined by the implementation.<T> long
apply(T instance, PersistenceTypeHandler<Binary,T> localTypeHandler)
<T> long
applyEager(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.<T> long
applyEager(T instance, PersistenceTypeHandler<Binary,T> localTypeHandler)
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.PersistenceStorer
ensureCapacity(long desiredCapacity)
Ensures that the instance's internal state is prepared for handling an amount of unique instance equal to the passed value.ObjectSwizzling
getObjectRetriever()
void
iterateMergeableEntries(PersistenceAcceptor iterator)
<T> long
lookupObjectId(T object, PersistenceObjectIdRequestor<Binary> objectIdRequestor, PersistenceTypeHandler<Binary,T> optionalHandler)
long
lookupOid(Object object)
long
maximumCapacity()
The maximum value thatStorer.currentCapacity()
can reach.PersistenceObjectManager<Binary>
parentObjectManager()
<T> void
registerEagerOptional(long objectId, T instance, PersistenceTypeHandler<Binary,T> optionalHandler)
<T> void
registerGuaranteed(long objectId, T instance, PersistenceTypeHandler<Binary,T> optionalHandler)
<T> void
registerLazyOptional(long objectId, T instance, PersistenceTypeHandler<Binary,T> optionalHandler)
PersistenceStorer
reinitialize()
Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary.PersistenceStorer
reinitialize(long initialCapacity)
Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary.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.long
store(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.void
storeAll(Iterable<?> instances)
Convenience method toPersistenceStoring.store(Object)
all instances of anIterable
type, 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 passedIterable
cannot 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.void
synchRebuildStoreItems()
void
synchRebuildStoreItems(int newLength)
<T> BinaryStorer.Item
synchRegisterObjectId(T instance, PersistenceTypeHandler<Binary,? super T> typeHandler, long objectId)
-
Constructor Details
-
Default
public Default()
-
-
Method Details
-
parentObjectManager
- Specified by:
parentObjectManager
in interfacePersistenceLocalObjectIdRegistry<Binary>
-
getObjectRetriever
- Specified by:
getObjectRetriever
in interfacePersistenceStoreHandler<Binary>
-
maximumCapacity
public final long maximumCapacity()Description copied from interface:Storer
The maximum value thatStorer.currentCapacity()
can reach. For more explanation on the exact meaning of the capacity, see there.- Specified by:
maximumCapacity
in interfaceBinaryStorer
- Specified by:
maximumCapacity
in interfaceStorer
- Returns:
- the maximum of the implementation-specific "capacity" value.
-
currentCapacity
public final long currentCapacity()Description copied from interface:Storer
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).- Specified by:
currentCapacity
in interfaceBinaryStorer
- Specified by:
currentCapacity
in interfaceStorer
- Returns:
- the current implementation-specific "capacity" value.
-
size
public final long size()- Specified by:
size
in interfaceStorer
- 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:
Storer.skip(Object)
,Storer.skipMapped(Object,long)
-
reinitialize
Description copied from interface:PersistenceStorer
Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary.- Specified by:
reinitialize
in interfaceBinaryStorer
- Specified by:
reinitialize
in interfacePersistenceStorer
- Specified by:
reinitialize
in interfaceStorer
- Returns:
- this.
-
reinitialize
Description copied from interface:PersistenceStorer
Enforces the instance to be initialized, discarding any previous state (clearing it) if necessary.- Specified by:
reinitialize
in interfaceBinaryStorer
- Specified by:
reinitialize
in interfacePersistenceStorer
- Specified by:
reinitialize
in interfaceStorer
- Returns:
- this.
-
clear
public void clear()Description copied from interface:Storer
Clears all internal state regarding collected data and/or registered skips. -
ensureCapacity
Description copied from interface:PersistenceStorer
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.- Specified by:
ensureCapacity
in interfaceBinaryStorer
- Specified by:
ensureCapacity
in interfacePersistenceStorer
- Specified by:
ensureCapacity
in interfaceStorer
- Parameters:
desiredCapacity
- the amount of unique instances that this instance shall prepare to handle.- Returns:
- this
-
apply
public <T> long apply(T instance)Description copied from interface:PersistenceStoreHandler
The "natural" way of handling an instance as defined by the implementation.- Specified by:
apply
in interfacePersistenceFunction
- Specified by:
apply
in interfacePersistenceStoreHandler<Binary>
- Parameters:
instance
- the instance to which the function shall be applied.- Returns:
- the object ID (OID) that is associated with the passed instance.
-
apply
- Specified by:
apply
in interfacePersistenceStoreHandler<Binary>
-
applyEager
public final <T> long applyEager(T instance)Description copied from interface:PersistenceStoreHandler
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.- Specified by:
applyEager
in interfacePersistenceStoreHandler<Binary>
-
applyEager
- Specified by:
applyEager
in interfacePersistenceStoreHandler<Binary>
-
store
Description copied from interface:PersistenceStoring
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. 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:
store
in interfacePersistenceStoring
- Parameters:
root
- the root instance of the subgraph of required instances to be stored.- Returns:
- the object id representing the passed instance.
-
storeAll
Description copied from interface:PersistenceStoring
Convenience method toPersistenceStoring.store(Object)
multiple instances. The passed array (maybe implicitely created by the compiler) itself is NOT stored.- Specified by:
storeAll
in 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
Description copied from interface:PersistenceStoring
Convenience method toPersistenceStoring.store(Object)
all instances of anIterable
type, 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 passedIterable
cannot 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:
storeAll
in interfacePersistenceStoring
- Parameters:
instances
- multiple root instances of the subgraphs of required instances to be stored.
-
iterateMergeableEntries
- Specified by:
iterateMergeableEntries
in interfacePersistenceLocalObjectIdRegistry<Binary>
-
commit
Description copied from interface:Storer
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.
-
lookupOid
-
lookupObjectId
public final <T> long lookupObjectId(T object, PersistenceObjectIdRequestor<Binary> objectIdRequestor, PersistenceTypeHandler<Binary,T> optionalHandler)- Specified by:
lookupObjectId
in interfacePersistenceLocalObjectIdRegistry<Binary>
-
registerGuaranteed
public final <T> void registerGuaranteed(long objectId, T instance, PersistenceTypeHandler<Binary,T> optionalHandler)- Specified by:
registerGuaranteed
in interfacePersistenceObjectIdRequestor<Binary>
-
registerLazyOptional
public <T> void registerLazyOptional(long objectId, T instance, PersistenceTypeHandler<Binary,T> optionalHandler)- Specified by:
registerLazyOptional
in interfacePersistenceObjectIdRequestor<Binary>
-
registerEagerOptional
public <T> void registerEagerOptional(long objectId, T instance, PersistenceTypeHandler<Binary,T> optionalHandler)- Specified by:
registerEagerOptional
in interfacePersistenceObjectIdRequestor<Binary>
-
skipMapped
Description copied from interface:Storer
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:Storer.skip(Object)
Storer.skipNulled(Object)
- Specified by:
skipMapped
in 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)
-
skip
Description copied from interface:Storer
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 asStorer.skipNulled(Object)
.- Specified by:
skip
in 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:Storer
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, useStorer.skip(Object)
.- Specified by:
skipNulled
in 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)
-
synchRegisterObjectId
public final <T> BinaryStorer.Item synchRegisterObjectId(T instance, PersistenceTypeHandler<Binary,? super T> typeHandler, long objectId) -
synchRebuildStoreItems
public final void synchRebuildStoreItems() -
synchRebuildStoreItems
public final void synchRebuildStoreItems(int newLength)
-