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>

public class ModifiableEntity<T> extends DelegatingEntity<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:
  • Constructor Details

  • Method Details

    • assertLegal

      public <E extends Exception> Entity<T> assertLegal(Object update) throws E
      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

      public Entity<T> update(UnaryOperator<T> function)
      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

      public Entity<T> apply(Message eventMessage)
      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

      public Entity<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

      public Entity<T> assertAndApply(Object payloadOrMessage)
      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

      public Collection<? extends Entity<?>> entities()
      Description copied from interface: Entity
      Retrieves child entities of this entity.
      Specified by:
      entities in interface Entity<T>
      Overrides:
      entities in class DelegatingEntity<T>
      Returns:
      a collection containing child entities.
    • parent

      public Entity<?> parent()
      Description copied from interface: Entity
      Retrieves the parent entity of the current entity.
      Specified by:
      parent in interface Entity<T>
      Overrides:
      parent in class DelegatingEntity<T>
      Returns:
      the parent entity of the current entity, or null if this entity does not have a parent
    • previous

      public Entity<T> previous()
      Description copied from interface: Entity
      Retrieves the previous version of this entity.
      Specified by:
      previous in interface Entity<T>
      Overrides:
      previous in class DelegatingEntity<T>
      Returns:
      the previous state of the entity, or null if this is the first known version