Class SideEffectFreeEntity<T>
java.lang.Object
io.fluxzero.sdk.modeling.SideEffectFreeEntity<T>
- Type Parameters:
T- the type of the entity's value
- All Implemented Interfaces:
Entity<T>
A functional, non-persistent
Entity wrapper that enables safe state mutation and validation without producing
side effects such as event publication or snapshot creation.
SideEffectFreeEntity allows invocation of methods like apply(Message),
update(UnaryOperator), and assertLegal(Object), making it suitable for scenarios where domain logic
or legality checks are needed without committing the resulting changes.
This entity is returned from AggregateRepository.asEntity(Object) or
Fluxzero.asEntity(Object) to allow ad-hoc interaction with domain objects
outside of the lifecycle of an active aggregate. It is particularly useful for:
- Performing validations with
@AssertLegal - Executing
@Applyhandlers to derive a new state - Analyzing projected changes without actually modifying persisted state
Entity.isLoading() to remain true during apply() and update()
invocations to suppress unintended side effects like event publication or committing.
However, the returned state reflects the result of applying the logic, allowing chaining or inspection.
Unlike NoOpEntity, which disables all state changes entirely, SideEffectFreeEntity evaluates them
fully but simply discards any side effects. The commit() operation is a no-op.
- See Also:
-
Field Summary
Fields inherited from interface Entity
AGGREGATE_ID_METADATA_KEY, AGGREGATE_SN_METADATA_KEY, AGGREGATE_TYPE_METADATA_KEY, applying, loading -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCollection<?> aliases()Retrieves a collection of aliases associated with this entity.Applies the given message to the entity.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.get()Retrieves the current instance of the entity.id()Retrieves the unique identifier of the entity.Retrieves the name of the property that serves as the unique identifier for the entity.Entity<?> parent()Retrieves the parent entity of the current entity.previous()Retrieves the previous version of this entity.type()Retrieves the type of the 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.Sets the type of the entity to the specified class and returns the updated entity.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Entity
allEntities, ancestors, ancestorValue, apply, apply, apply, apply, apply, assertAndApply, assertAndApply, assertAndApply, assertAndApply, associations, depth, dissociations, entities, getEntity, highestEventIndex, ifPresent, isEmpty, isPresent, isRoot, lastEventId, lastEventIndex, mapIfPresent, playBackToCondition, playBackToEvent, possibleTargets, relationships, root, rootAnnotation, sequenceNumber, timestamp, withEventIndex, withSequenceNumber
-
Constructor Details
-
SideEffectFreeEntity
-
-
Method Details
-
apply
Description copied from interface:EntityApplies the given message to the entity. -
update
Description copied from interface:EntityUpdates the current entity's value using the specified unary operator and returns a new entity containing the updated value. -
commit
Description copied from interface:EntityCommits 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. -
assertLegal
Description copied from interface:EntityVerifies 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.- Specified by:
assertLegalin interfaceEntity<T>- 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
-
parent
-
aliases
Description copied from interface:EntityRetrieves a collection of aliases associated with this entity. -
previous
-
id
-
type
-
withType
Description copied from interface:EntitySets the type of the entity to the specified class and returns the updated entity. -
get
-
idProperty
Description copied from interface:EntityRetrieves the name of the property that serves as the unique identifier for the entity.- Specified by:
idPropertyin interfaceEntity<T>- Returns:
- the name of the identification property as a string
-