I
- the entity ID typeE
- the entity typeS
- the entity state type@Experimental
public abstract class Migration<I,E extends TransactionalEntity<I,S,?>,S extends io.spine.base.EntityState>
extends java.lang.Object
implements java.util.function.Function<S,S>, io.spine.logging.Logging
Entity
transformation done to account for the domain model changes.
At its core the Migration
is a mapping of entity state
, from old
to new. It is also capable of performing basic entity modifications like
archiving and deleting it.
The process of applying the migration operation is always preceded by an Entity
load
by ID and may be finalized by either saving the
transformed entity back to the repository or by deleting the
entity record if the migration is configured to do so.
All entity modifications are applied under the opened entity Transaction
. The
last step of a migration operation is a transaction commit. As
a consequence, all entity lifecycle events occur as expected, having the
MigrationApplied
event as the producing message.
To create a user-defined Migration
in real life scenarios, consider inheriting from
ProjectionMigration
and
ProcessManagerMigration
types.
Constructor and Description |
---|
Migration() |
Modifier and Type | Method and Description |
---|---|
protected I |
id()
Returns the ID of an entity under migration.
|
protected boolean |
isArchived()
Returns
true if the entity under migration is
archived. |
protected boolean |
isDeleted()
Returns
true if the entity under migration is
deleted. |
protected void |
markArchived()
Marks the entity under migration as archived.
|
protected void |
markDeleted()
Marks the entity under migration as deleted.
|
protected void |
removeFromStorage()
Configures the migration operation to delete the entity record from the storage.
|
protected io.spine.core.Version |
version()
Returns the version of entity under migration.
|
protected final void markArchived()
protected final void markDeleted()
protected final void removeFromStorage()
All other configured entity modifications are still applied, allowing to trigger entity lifecycle events before the actual record deletion.
Depending on the storage implementation, this operation may be irreversible, so it should be used in the caller code with care.
protected final I id()
protected final io.spine.core.Version version()
protected final boolean isArchived()
true
if the entity under migration is
archived.protected final boolean isDeleted()
true
if the entity under migration is
deleted.