Layered Entities

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:

public interface Person extends Entity
{
	public String firstName();
	 
	public String lastName();
}

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:

Last updated