Interface AggregateRepository
- All Known Implementing Classes:
CachingAggregateRepository, DefaultAggregateRepository
public interface AggregateRepository
Repository interface for loading, managing, and repairing aggregates in Fluxzero.
Aggregates in Fluxzero can be persisted using different storage strategies, including event sourcing and
document-based storage (e.g., DocumentStore). The AggregateRepository abstracts these details and
provides a unified API to interact with aggregate instances as Entity wrappers.
Core capabilities include:
- Loading aggregates by ID, whether event-sourced or document-based.
- Mapping entities to their associated aggregates (e.g., for child-to-parent traversal).
- Repairing relationships between entities and aggregates (especially useful after structural refactors).
- Deleting aggregates and their associated data.
Note: While this interface is accessible directly, most typical usage is through the static
Fluxzero.loadAggregate(...) or via delegation
in Entity classes.
-
Method Summary
Modifier and TypeMethodDescription<T> Entity<T> asEntity(T entity) Wrap an existing aggregate instance into anEntity, initializing tracking and identity information.deleteAggregate(Object aggregateId) Deletes the persisted state for an aggregate, including its events or document and relationships.getAggregatesFor(Object entityId) Returns a map of aggregate IDs and their types that are associated with a given entity ID.getLatestAggregateId(Object entityId) Returns the most recently created aggregate ID associated with a given entity ID, if any.default <T> Entity<T> Load an aggregate by a typed identifier.default <T> Entity<T> Load an aggregate by its identifier.<T> Entity<T> Load an aggregate by its identifier and type.<T> Entity<T> Load the aggregate that owns the specified entity.repairRelationships(Entity<?> aggregate) Repairs the internal relationship model for a loaded aggregate.default CompletableFuture<Void> repairRelationships(Id<?> aggregateId) Repairs the relationships of the aggregate corresponding to the given typed ID.default CompletableFuture<Void> repairRelationships(Object aggregateId) Repairs the relationships of the aggregate with the given ID.
-
Method Details
-
load
-
load
Load an aggregate by its identifier. If the aggregate exists, it will be loaded and returned with its respective type, if not, an emptyEntityof typeObjectwill be returned.- Type Parameters:
T- the aggregate type.- Parameters:
aggregateId- the aggregate identifier.- Returns:
- the loaded aggregate wrapped in an
Entity.
-
load
Load an aggregate by its identifier and type.- Type Parameters:
T- the aggregate type.- Parameters:
aggregateId- the aggregate identifier.aggregateType- the expected class type.- Returns:
- the loaded aggregate wrapped in an
Entity.
-
loadFor
Load the aggregate that owns the specified entity.If no ownership is found in the relationship index, this method may fall back to loading the entity as if it were an aggregate itself.
- Type Parameters:
T- the aggregate type.- Parameters:
entityId- the child or nested entity.defaultType- fallback type to use when no aggregate mapping is available.- Returns:
- the loaded aggregate as an
Entity.
-
asEntity
-
repairRelationships
Repairs the relationships of the aggregate corresponding to the given typed ID.- Parameters:
aggregateId- the typed identifier of the aggregate.- Returns:
- a future that completes when the repair process is done.
-
repairRelationships
Repairs the relationships of the aggregate with the given ID.- Parameters:
aggregateId- the ID of the aggregate.- Returns:
- a future that completes when the repair process is done.
-
repairRelationships
Repairs the internal relationship model for a loaded aggregate.This is useful when refactoring entity hierarchies or recovering from inconsistent relationship state.
- Parameters:
aggregate- the aggregate to inspect.- Returns:
- a future that completes when the relationships are updated.
-
getAggregatesFor
-
getLatestAggregateId
-
deleteAggregate
Deletes the persisted state for an aggregate, including its events or document and relationships.- Parameters:
aggregateId- the ID of the aggregate to delete.- Returns:
- a future that completes when deletion has been confirmed.
-