This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
Implementing the PersistenceEagerStoringFieldEvaluator
interface allows you to handle the eager/lazy storing behavior of any known member. The default implementation of the MicroStream engine threads all fields as lazy storing. See Lazy and Eager Storing for details on lazy and eager storing.
The PersistenceEagerStoringFieldEvaluator
has only one method to be implemented: public boolean isEagerStoring(Class<?> t, Field u)
return true if the field has to be eager, otherwise return false.
To register the customized PersistenceEagerStoringFieldEvaluator
add it using the one.microstream.persistence.types.PersistenceFoundation
.setReferenceFieldEagerEvaluator(PersistenceEagerStoringFieldEvaluator)
method during the storage initialization.
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
Custom type handlers allow taking control over the storing and loading procedure of specific java types. This is useful to optimize the performance for storing complex objects or in the rare case that it is not possible to store a type with the default type handlers.
There are two strategies for a simplified type handler implementation.
Implementing a class that extends CustomBinaryHandler
and defines a sequence of BinaryField
s via the #Field~
static pseudo-constructor methods. Everything else like setting the name, calculating the binary offsets, etc. is then done implicitly via reflection.
This example implements a custom type handler for the java.awt.image.BufferedImage
class. Instead of storing the rather complex object structure of that class the image is serialized as PNG image format using javax.imageio.ImageIO
into a byte array. This byte array is then stored by MicroStream.
The custom type handler must be registered in the CustomTypeHandlerRegistry
to enable it:
Implementing a class can be skipped altogether by using the method Binary#TypeHandler
and passing the BinaryField
s directly.
Registering such a generically created TypeHandler is not required, either, since Version 3 of MicroStream brought a solution to just define a static method in the entity class that will be recognized and used by MicroStream.
The following is a simple technical example on how a custom binary handler can be easily defined and technically leveraged to optimize storage behavior. E.g. imagine having millions of such objects that now only create 1 database record with a fraction of the required storage space instead of 4 records but hold the same information.
Full example is available on GitHub.
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
In certain environments or setups it is necessary to provide specific ClassLoader
instances. This can be done by customizing the connection foundation.
If a single ClassLoader
is sufficient, just create a new provider by handing over the instance:
Or return a ClassLoader
depending on the requested type:
Most application servers load the session's classes with the context class loader. Just use the one of the current thread:
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
In addition to the methods for legacy type mapping described in chapter Legacy Type Mapping there is also the possibility to implement custom legacy type handlers. Those handlers are the most flexible way to do the mapping from old to new types.
The basic interface that has to be implemented is one.microstream.persistence.types.PersistenceLegacyTypeHandler.
Fortunately the standard persistence implementation provides the abstract class one.microstream.persistence.binary.types.BinaryLegacyTypeHandler.AbstractCustom
that should be sufficient to start with a custom implementation in most cases.
See the example customLegacyTypeHandler on GitHub
Please note the this example requires manual code modifications as described in it's main class.
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
When a reference to the loading storage is needed in entities, e.g. usage of different tenants or to store its internal state in a tailored fashion, this can be done by this little trick.
If an entity type contains one or more transient fields with field type compatible to Persister
, the updating processing during loading will set the Persister
instance (e.g. an EmbeddedStorageManager
instance) used to load the entity instance to those fields.
The fields must be transient to exclude them from the persistent form of the entity.
Checking for transient fields is only the default implementation. The checking logic can be customized via PersistenceFoundation#setFieldEvaluatorPersistable
.
A more precise check for Persister
fields can be customized via PersistenceFoundation#setFieldEvaluatorPersister
.
Note, however, that the check for compatibility with the Persister
type is done in any case to avoid inconsistencies/crashes.
If no applicable field is found, nothing happens and no additional meta data is kept in memory. This feature is completely optional.
Upon loading an instance of class MyEntity
, a reference to the EmbeddedStorageManager
used to load it is set to its field storage
.
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at: