Class ImmutableAggregateRoot<T>
java.lang.Object
io.fluxzero.sdk.modeling.ImmutableEntity<T>
io.fluxzero.sdk.modeling.ImmutableAggregateRoot<T>
- Type Parameters:
T- the type of the domain object represented by this aggregate root
- All Implemented Interfaces:
AggregateRoot<T>, Entity<T>
Immutable representation of an
AggregateRoot, extending ImmutableEntity with additional metadata for
event sourcing.
The previous field stores a reference to the prior state, enabling recursive traversal of historical states.
When aggregate caching with a caching depth is enabled, older states may be replaced
by a LazyAggregateRoot, which holds a reference but defers loading the full state.
This allows memory-efficient checkpointing of long-lived aggregates: once the maximum caching depth is reached, earlier states are no longer retained in memory and must be reloaded via event sourcing when accessed.
- 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 TypeMethodDescriptionapply(DeserializingMessage message) Applies the given deserializing message to the entity.static <T> ImmutableAggregateRoot<T> from(Entity<T> a, EntityHelper entityHelper, Serializer serializer, EventStore eventStore) update(UnaryOperator<T> function) Updates the current entity's value using the specified unary operator and returns a new entity containing the updated value.withEventIndex(Long index, String messageId) Updates the event index and message ID of the entity and returns the updated version of the entity.withSequenceNumber(long sequenceNumber) Returns an updated entity based on this with the specified sequence number.Methods inherited from class ImmutableEntity
apply, assertLegal, commit, computeAliases, computeEntities, get, type, withTypeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AggregateRoot
lastEventId, lastEventIndex, parent, previous, sequenceNumber, timestampMethods inherited from interface Entity
aliases, allEntities, ancestors, ancestorValue, apply, apply, apply, apply, apply, assertAndApply, assertAndApply, assertAndApply, assertAndApply, assertLegal, associations, commit, depth, dissociations, entities, get, getEntity, highestEventIndex, id, idProperty, ifPresent, isEmpty, isPresent, isRoot, mapIfPresent, playBackToCondition, playBackToEvent, possibleTargets, relationships, root, rootAnnotation, type, withType
-
Constructor Details
-
ImmutableAggregateRoot
public ImmutableAggregateRoot()
-
-
Method Details
-
from
public static <T> ImmutableAggregateRoot<T> from(Entity<T> a, EntityHelper entityHelper, Serializer serializer, EventStore eventStore) -
apply
Description copied from interface:EntityApplies the given deserializing 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. -
withEventIndex
Description copied from interface:EntityUpdates the event index and message ID of the entity and returns the updated version of the entity.- Specified by:
withEventIndexin interfaceAggregateRoot<T>- Specified by:
withEventIndexin interfaceEntity<T>- Parameters:
index- the event index to set for the root entitymessageId- the message ID associated with the event- Returns:
- the updated entity corresponding to the current entity's ID and type, or null if no such entity can be found
-
withSequenceNumber
Description copied from interface:EntityReturns an updated entity based on this with the specified sequence number.- Specified by:
withSequenceNumberin interfaceAggregateRoot<T>- Specified by:
withSequenceNumberin interfaceEntity<T>- Parameters:
sequenceNumber- the sequence number to assign to the entity- Returns:
- the updated entity with the specified sequence number, or null if the entity could not be found in the entity hierarchy
-