Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
The layered entities code generator is an annotation processor, provided by the base
module.
The maven configuration looks like this:
If you don't want the HashEqualator
to be generated, just set the microstream.entity.hashequalator
argument to false
. You can leave it out otherwise, the default value is true
.
The same applies to the Appendable
.
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
Another predefined logic layer is for logging purposes. Since there is a myriad of loggers out there, MicroStream doesn't provide any special adapter, but a generic type which can be used to adapt to the logging framework of your choice.
Just create a class and implement EntityLogger
, and you are good to go.
Additional to afterUpdate
there are further hooks:
entityCreated
afterRead
beforeUpdate
Now just add the logger when creating entities:
When you call
the logger's output is
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
Entities can be created with an arbitrary amount of layers, so feel free to combine them as you like:
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
The data layer is always immutable. In order to update the values we have to replace the data layer completely. This is done with the updater. The property setter methods can be chained, so it is easy to update multiple properties, for example:
If only one property needs to be updated, the updater class offers static convenience methods for that:
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
Concept to separate the basic aspects of what defines an entity into separate instances of different layers:
Identity, a never to be replaced instance representing an entity in terms of references to it
Logic, nestable in an arbitrary number of dynamically created logic layers, e.g. logging, locking, versioning, etc.
Data, always immutable
Entity graphs are constructed by stricly only referencing identity instances (the "outer shell" of an entity), while every inner layer instance is unshared. This also allows the actual data instance to be immutable, while at the same time leaving referencial integrity of an entity graph intact.
MicroStream provides ready-to-use logic layers for:
Logging
Versioning
While the layers admittedly introduce considerable technical complexity and runtime overhead, this concept is a production ready solution for nearly all requirements regarding cross cutting concerns and aspects.
To use this concept in your code, there need to be at least implementations for the entity's identity and data.
Let's say the entity looks like this:
There needs to be a identity class:
And a data class:
A lot of code to write to get an entity with two properties!
But don't worry, there is a code generator for that. An annotation processor to be precise. The only code you have to provide are the entity interfaces, all the other stuff will be generated.
Just add the annotation processor typeone.microstream.entity.codegen.EntityProcessor
to your compiler configuration. That's it.
The generator also builds a creator:
An Updater:
An optional equalator, with equals
and hashCode
methods:
And an optional Appendable:
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
The entity types are just simple interfaces with value methods, which have following requirements:
A return type, no void
No parameters
No type parameters
No declared checked exceptions
You are not limited otherwise. Use any types you want. Inheritance and generics are supported as well.
There is one base type (Beeing
), one feature interface (Named
) and three entities (Animal
, Pet
, Human
).
The code generator takes care of the three entities, and its output looks like this:
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
An arbitrary amount of logic layers can be added to entities. Let's use the predefined versioning layer. It will keep track of all changes. Technically every new data layer which is added by the updater, will create a new version entry.
Let's have a look at the debugger:
Now the versioning layer is chained between the identity layer and the data layer.
If we update the entity a few times, we will see how the versioning layer works. In this case we use an auto-incrementing Long as key.
If you want to access older versions use the context:
To limit the amount of preserved versions, a cleaner can be utilized:
This will keep only the last ten versions of the person.
Additionally to number keys, timestamps can be used as well.
They can be preserved for a specific time range:
The version context can be used as a shared state object. So you can control versioning for multiple entities at once, or even for the hole entity graph.
The auto-incrementing contexts take care of the key creation. If you need to control it by yourself, use the mutable context. But be aware that you have to set the version before updating any data, otherwise the current one will be overwritten.
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
Given is the following entity:
So how is it done? Since the code generator provides a creator, we can use it to create a new Person
.
Let's see what the debugger displays if we run this code:
There's always an entity chain, with
The identity (PersonEntity
) as outer layer
Then the logic layers, none here in our example
And the inner most layer is always the data (PersonData
), which holds the properties.
The properties can be accessed like defined in the entity's interface:
The creator can also be used to create copies. Just hand over the existing one as template:
This will create a "Mike Doe".