Optional Storage Manager Reference in Entities
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
Persisterinstance (e.g. an
EmbeddedStorageManagerinstance) 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
A more precise check for
Persisterfields can be customized via
PersistenceFoundation#setFieldEvaluatorPersister. Note, however, that the check for compatibility with the
Persistertype 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.
String name ;
transient EmbeddedStorageManager storage;
Upon loading an instance of class
MyEntity, a reference to the
EmbeddedStorageManagerused to load it is set to its field