arrow-left

All pages
gitbookPowered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

Customizing

circle-exclamation

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/arrow-up-right

Custom Legacy Type Handler

circle-exclamation

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/arrow-up-right

In addition to the methods for legacy type mapping described in chapter 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.

circle-info

See the example customLegacyTypeHandler on

circle-info

Please note the this example requires manual code modifications as described in it's main class.

Custom Type Handler

circle-exclamation

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/arrow-up-right

Custom Type Handler 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.

hashtag
Implementation

Suitable base class to start the implementation of a custom type handler for the Microstream standard binary storage implementation are:

one.microstream.persistence.binary.internal.AbstractBinaryHandlerCustomValue for simpler custom type handling in case only value have to be stored or one.microstream.persistence.binary.internal.AbstractBinaryHandlerCustom if the object own references that have to be persisted too.

circle-info

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 an byte array. This byte array is stored by microstream.

hashtag
Setup

The custom type handler must be registered in the CustomTypeHandlerRegistry to enable it:

Legacy Type Mapping
GitHubarrow-up-right
Example on GitHubarrow-up-right
mbeddedStorageManager storage = EmbeddedStorage
     .Foundation(WORKINGDIR)
     .onConnectionFoundation(f->
          f.registerCustomTypeHandlers(new CustomBufferedImageHandler()))
     .start(ROOT);

PersistenceEagerStoringFieldEvaluator

circle-exclamation

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

https://docs.microstream.one/arrow-up-right

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 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.

public class CustomEagerStoringFieldEvaluator 
	implements PersistenceEagerStoringFieldEvaluator 
{
	@Override
	public boolean isEagerStoring(Class<?> clazz, Field field) 
	{
		if(clazz == MyClass.class && field.getName() == "eagerField")
		{
			return true;
		}
		
		return false;
	}
}
Lazy and Eager Storing
EmbeddedStorageManager storage = EmbeddedStorage        		
    .Foundation(Storage.ConfigurationBuilder()         				
        .setStorageFileProvider(Storage.FileProvider(WORKINGDIR))         				
        .createConfiguration())
    .onConnectionFoundation(f ->
    {
        f.setReferenceFieldEagerEvaluator(new CustomEagerStoringFieldEvaluator());
    })
    .start(ROOT);