Class ModifiableEntity<T>
java.lang.Object
io.fluxcapacitor.javaclient.modeling.DelegatingEntity<T>
io.fluxcapacitor.javaclient.modeling.ModifiableEntity<T>
- Type Parameters:
T
- the type of the entity’s value
- All Implemented Interfaces:
Entity<T>
A mutable view on a nested entity within a
ModifiableAggregateRoot
.
This class wraps a delegate Entity
and maintains a reference to the root ModifiableAggregateRoot
,
enabling mutating operations—such as update(UnaryOperator)
, apply(Message)
, and
assertLegal(Object)
—to be routed through the root context.
This ensures that:
- All changes are tracked and committed through the root aggregate’s lifecycle.
- Relationship resolution and legality checks are coordinated at the aggregate level.
- Nested child entities participate in the aggregate’s commit process transparently.
The ModifiableEntity
is typically returned when loading or navigating to a non-root entity
(i.e., a member or child entity) of an aggregate. Despite being indirectly updatable,
such child entities share the same mutation and commit infrastructure as the root.
Any invocation of update()
, apply()
, assertAndApply()
, or commit()
will cause the root aggregate to manage the lifecycle and capture any applied events or state changes.
- See Also:
-
Field Summary
Fields inherited from class io.fluxcapacitor.javaclient.modeling.DelegatingEntity
delegate
Fields inherited from interface io.fluxcapacitor.javaclient.modeling.Entity
AGGREGATE_ID_METADATA_KEY, AGGREGATE_SN_METADATA_KEY, AGGREGATE_TYPE_METADATA_KEY, applying, loading
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionApplies the given message to the entity.assertAndApply
(Object payloadOrMessage) Verifies that the provided update is legal given the current state of the aggregate and on success applies it to the aggregate.assertLegal
(Object update) Verifies that the provided update is legal given the current state of the aggregate.commit()
Commits the current state of the entity, persisting any changes made to it.Collection
<? extends Entity<?>> entities()
Retrieves child entities of this entity.Entity
<?> parent()
Retrieves the parent entity of the current entity.previous()
Retrieves the previous version of this entity.update
(UnaryOperator<T> function) Updates the current entity's value using the specified unary operator and returns a new entity containing the updated value.Methods inherited from class io.fluxcapacitor.javaclient.modeling.DelegatingEntity
aliases, get, id, idProperty, lastEventId, lastEventIndex, sequenceNumber, timestamp, type, withEventIndex, withSequenceNumber, withType
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.modeling.Entity
allEntities, ancestors, ancestorValue, apply, apply, apply, apply, apply, assertAndApply, assertAndApply, assertAndApply, associations, depth, dissociations, getEntity, highestEventIndex, ifPresent, isEmpty, isPresent, isRoot, mapIfPresent, playBackToCondition, playBackToEvent, possibleTargets, relationships, root, rootAnnotation
-
Constructor Details
-
ModifiableEntity
-
-
Method Details
-
assertLegal
Description copied from interface:Entity
Verifies that the provided update is legal given the current state of the aggregate. If so, the entity is returned; otherwise, it throws an appropriate exception.- Type Parameters:
E
- the type of exception expected if the update is not legal- Parameters:
update
- the update to be validated for compliance with the required rules- Returns:
- the entity if the update is legal
- Throws:
E
- if the update fails to meet legal requirements
-
update
Description copied from interface:Entity
Updates the current entity's value using the specified unary operator and returns a new entity containing the updated value.- Parameters:
function
- the unary operator to apply to the current entity's value- Returns:
- a new entity containing the updated value after applying the function
-
apply
Description copied from interface:Entity
Applies the given message to the entity.- Parameters:
eventMessage
- the message representing the event to be applied- Returns:
- the updated or newly created Entity of type T
-
commit
Description copied from interface:Entity
Commits the current state of the entity, persisting any changes made to it. This method ensures that the modifications are saved. Typically, it is unnecessary to invoke this manually as it is automatically invoked after the current handler or consumer batch has completed.- Returns:
- The updated entity after the commit operation is successfully completed.
-
assertAndApply
Description copied from interface:Entity
Verifies that the provided update is legal given the current state of the aggregate and on success applies it to the aggregate. If not, it throws an appropriate exception.- Parameters:
payloadOrMessage
- the input object to be applied; can be a payload or a message- Returns:
- the resulting entity after application
-
entities
Description copied from interface:Entity
Retrieves child entities of this entity. -
parent
Description copied from interface:Entity
Retrieves the parent entity of the current entity. -
previous
Description copied from interface:Entity
Retrieves the previous version of this entity.
-