MicroStream Reference Manual
MicroStream HomeAPI Docs
2.2
2.2
  • Preface
  • System Requirements
  • License
  • Changelog
  • Installation
  • Data-Store
    • Overview
    • Getting Started
    • Root Instances
    • Configuration
      • Properties
      • Storage Files and Directories
      • Using Channels
      • Housekeeping
      • Backup
      • Lock File
    • Storing Data
      • Convenience Methods and Explicit Storing (Transactions)
      • Lazy and Eager Storing
      • Transient Fields
      • Best Practice
    • Loading Data
      • Lazy Loading
        • Touched Timestamp, Null-Safe Variant
        • Clearing Lazy References
    • Deleting Data
    • Queries
    • Application Life-Cycle
    • Legacy Type Mapping
      • User Interaction
    • Backup Strategies
    • Import / Export
    • Housekeeping
    • FAQ
      • Data Model
      • Data Management
      • File Storage
      • Environment
      • Miscellaneous
    • Customizing
      • Custom Type Handler
      • Custom Legacy Type Handler
      • PersistenceEagerStoringFieldEvaluator
  • Basic Concepts
    • Layered Entities
      • Configuration
      • Defining Entities
      • Creating Entities
      • Updating Entities
      • Versioning
      • Logging
      • Multiple Layers
    • Wrapping
      • Configuration
      • Usage
Powered by GitBook
On this page
  • Implementation
  • Setup
Export as PDF
  1. Data-Store
  2. Customizing

Custom Type Handler

PreviousCustomizingNextCustom Legacy Type Handler

Last updated 3 years ago

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

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

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.

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.

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.

Setup

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

EmbeddedStorageManager storage = EmbeddedStorage
     .Foundation(WORKINGDIR)
     .onConnectionFoundation(f->
          f.registerCustomTypeHandlers(new CustomBufferedImageHandler()))
     .start(ROOT);
https://docs.microstream.one/
Example on GitHub