Class DefaultModelRepository

java.lang.Object
io.fluxzero.sdk.common.AbstractNamespaced<ModelRepository>
io.fluxzero.sdk.persisting.repository.DefaultModelRepository
All Implemented Interfaces:
Namespaced<ModelRepository>, ModelAncestorResolver, ModelRepository

public class DefaultModelRepository extends AbstractNamespaced<ModelRepository> implements ModelRepository, ModelAncestorResolver
Default repository for independently stored models.

Current document-based models use their synchronously maintained direct document. Event-sourced and historical loads use the model-stream protocol and reconstruct every selected stream at one pinned stateIndex.

  • Constructor Details

  • Method Details

    • createForNamespace

      protected ModelRepository createForNamespace(String namespace)
      Specified by:
      createForNamespace in class AbstractNamespaced<ModelRepository>
    • modelDefinitionCompiler

      public MutationPlan.Compiler modelDefinitionCompiler()
      Returns the model-definition compiler shared by live commits and stored-event replay.
    • followPublishedEventMigration

      public ModelRepository followPublishedEventMigration(@NonNull @NonNull String migrationName, @NonNull @NonNull Duration maxWait)
      Description copied from interface: ModelRepository
      Coordinates legacy-event reads with a migration consumer using a bounded wait before normal handler retry takes over.
      Specified by:
      followPublishedEventMigration in interface ModelRepository
      Parameters:
      migrationName - stable durable migration-consumer name
      maxWait - maximum time one read waits for the migration consumer to reach its event
      Returns:
      this repository
    • planDeletion

      public io.fluxzero.common.api.modeling.ModelDeletionPlan planDeletion(@NonNull @NonNull Object modelId, @NonNull @NonNull io.fluxzero.common.api.modeling.ModelDeletionCascade cascade)
      Description copied from interface: ModelRepository
      Creates a bounded, non-mutating plan for an explicit model hard deletion.

      A descendant cascade must be planned and confirmed before execution. The returned published-event count makes clear that globally published events are outside the model-stream erasure boundary.

      Specified by:
      planDeletion in interface ModelRepository
    • deleteModel

      public CompletableFuture<io.fluxzero.common.api.modeling.ModelDeletionResult> deleteModel(@NonNull @NonNull Object modelId, @NonNull @NonNull io.fluxzero.common.api.modeling.ModelDeletionCascade cascade)
      Description copied from interface: ModelRepository
      Hard-deletes exactly one model.

      Passing ModelDeletionCascade.DESCENDANTS without a confirmed plan is rejected. Use ModelRepository.deleteModel(ModelDeletionPlan) for descendant cascades.

      Specified by:
      deleteModel in interface ModelRepository
    • deleteModel

      public CompletableFuture<io.fluxzero.common.api.modeling.ModelDeletionResult> deleteModel(@NonNull @NonNull String deletionId, @NonNull @NonNull Object modelId, @NonNull @NonNull io.fluxzero.common.api.modeling.ModelDeletionCascade cascade)
      Description copied from interface: ModelRepository
      Executes or resumes an exact-model hard deletion using an explicit durable idempotency key. Descendant deletion still requires a confirmed plan.
      Specified by:
      deleteModel in interface ModelRepository
    • deleteModel

      public CompletableFuture<io.fluxzero.common.api.modeling.ModelDeletionResult> deleteModel(@NonNull @NonNull io.fluxzero.common.api.modeling.ModelDeletionPlan plan)
      Description copied from interface: ModelRepository
      Executes a previously confirmed hard-deletion plan with a new durable idempotency key.
      Specified by:
      deleteModel in interface ModelRepository
    • deleteModel

      public CompletableFuture<io.fluxzero.common.api.modeling.ModelDeletionResult> deleteModel(@NonNull @NonNull String deletionId, @NonNull @NonNull io.fluxzero.common.api.modeling.ModelDeletionPlan plan)
      Description copied from interface: ModelRepository
      Executes or resumes a confirmed plan using an explicit durable idempotency key.
      Specified by:
      deleteModel in interface ModelRepository
    • adoptModelMigrations

      public CompletableFuture<Integer> adoptModelMigrations()
      Description copied from interface: ModelRepository
      Verifies and adopts every staged direct Model migration known to this application. Materialized Graph projections declared by the application are rebuilt after every staged document has been adopted. The accepted normalized source remains isolated from later staging until the first ordinary Model write, so another legacy boundary can be re-adopted without exposing unverified state. Repeating the operation is also a safe way to resume projection rebuilds after a failure.
      Specified by:
      adoptModelMigrations in interface ModelRepository
      Returns:
      the number of staged Model documents adopted by this invocation
      See Also:
    • registerGraphProjection

      public CompletableFuture<io.fluxzero.common.api.modeling.ModelGraphProjectionStatus> registerGraphProjection(@NonNull @NonNull Class<?> modelType, boolean rebuild)
      Description copied from interface: ModelRepository
      Registers the graph projection declared by the supplied model type.
      Specified by:
      registerGraphProjection in interface ModelRepository
      Parameters:
      modelType - model carrying an enabled graph projection
      rebuild - whether all current roots should be scanned even if the definition is unchanged
    • configureModelTypes

      public void configureModelTypes(Supplier<List<Class<?>>> modelTypes)
      Configures the application-bound model catalog used to version materialized Graph schemas.
    • graphProjectionDefinition

      public io.fluxzero.common.api.modeling.ModelGraphProjectionConfiguration graphProjectionDefinition(@NonNull @NonNull Class<?> modelType)
      Returns the application-resolved durable definition owned by this repository.
    • awaitGraphProjections

      public CompletableFuture<Void> awaitGraphProjections(@NonNull @NonNull Map<Class<?>, Set<String>> projections, long firstStateIndex, long stateIndex)
      Completes when every affected durable graph projection has processed the supplied commit range.
    • graphProjectionStatus

      public io.fluxzero.common.api.modeling.ModelGraphProjectionStatus graphProjectionStatus(@NonNull @NonNull Class<?> modelType)
      Description copied from interface: ModelRepository
      Returns current graph-projection freshness for the supplied model type.
      Specified by:
      graphProjectionStatus in interface ModelRepository
    • load

      public <T> Entity<T> load(@NonNull @NonNull String modelId, @NonNull @NonNull Class<T> modelType)
      Description copied from interface: ModelRepository
      Loads a model by primary ID or current alias and expected type. A primary model ID always takes precedence over an alias with the same value.
      Specified by:
      load in interface ModelRepository
      Parameters:
      modelId - persisted model key or current alias; never decorated with model type metadata
      modelType - expected model type, or Object when it should be resolved from storage
    • loadCurrent

      public <T> Entity<T> loadCurrent(@NonNull @NonNull String modelId, @NonNull @NonNull Class<T> modelType)
      Description copied from interface: ModelRepository
      Loads the latest model state by exact persisted identity. Custom repositories without contextual historical reads retain their normal behavior by delegating to ModelRepository.load(String, Class).
      Specified by:
      loadCurrent in interface ModelRepository
    • loadAll

      public <T> List<Entity<T>> loadAll(@NonNull @NonNull List<?> modelIds, @NonNull @NonNull Class<T> modelType)
      Description copied from interface: ModelRepository
      Loads several models at one coherent state boundary, preserving input order.

      Repositories without coherent multi-model reconstruction reject this capability instead of emulating it with independent reads at different boundaries.

      Specified by:
      loadAll in interface ModelRepository
    • loadGraph

      public <T> Graph<T> loadGraph(@NonNull @NonNull String rootId, @NonNull @NonNull Class<T> rootType, @NonNull Graph.Options options)
      Description copied from interface: ModelRepository
      Reconstructs a model graph using exact persisted identity, root type, and optional caller-imposed limits. Pending changes from earlier messages in the same ordered tracking segment are included.
      Specified by:
      loadGraph in interface ModelRepository
    • loadGraph

      public <T> Graph<T> loadGraph(@NonNull @NonNull String rootId, @NonNull @NonNull Class<T> rootType, @NonNull @NonNull io.fluxzero.common.api.modeling.ModelReadBoundary boundary, @NonNull Graph.Options options)
      Description copied from interface: ModelRepository
      Reconstructs one model graph at the supplied current, state, commit, event, or before boundary.
      Specified by:
      loadGraph in interface ModelRepository
    • loadAncestorGraph

      public <A> Optional<Graph<A>> loadAncestorGraph(String modelId, Class<?> modelType, Class<A> ancestorType, io.fluxzero.common.api.modeling.ModelReadBoundary boundary)
      Description copied from interface: ModelAncestorResolver
      Resolves and loads only the closest ancestor assignable to ancestorType at the graph's read boundary. Intermediate parent values must remain unloaded.
      Specified by:
      loadAncestorGraph in interface ModelAncestorResolver
    • loadAncestorGraphs

      public <A> List<Graph<A>> loadAncestorGraphs(String modelId, Class<?> modelType, Class<A> ancestorType, io.fluxzero.common.api.modeling.ModelReadBoundary boundary)
      Description copied from interface: ModelAncestorResolver
      Resolves every reachable ancestor assignable to ancestorType at one boundary.

      The singular method remains the ergonomic default for normal graph traversal. Change subscriptions use this form because one changed model may be shared by multiple roots.

      Specified by:
      loadAncestorGraphs in interface ModelAncestorResolver
    • loadGraphAtIncludingMessageBatch

      public <T> Graph<T> loadGraphAtIncludingMessageBatch(@NonNull @NonNull String rootId, @NonNull @NonNull Class<T> rootType, long stateIndex, @NonNull Graph.Options options)
      Reconstructs a graph at an exact durable boundary and overlays pending values from earlier messages in the current message batch. This is used by atomic model planning that must retain read-your-writes semantics without advancing beyond its already pinned durable boundary.
    • loadContext

      public CommitAttempt loadContext(MutationPlan.Resolution resolution)
      Loads all direct commit targets at one state boundary.

      A null boundary pins the current event-store state once. Historical document-model dependencies are reconstructed from stored model events; current document-model targets retain their direct-document load path.

      Specified by:
      loadContext in interface ModelRepository
    • loadContext

      public CommitAttempt loadContext(MutationPlan.Resolution resolution, Long maxStateIndex, Map<String,Object> stagedValues, boolean includeMessageBatch)
      Loads a commit context with an explicit choice whether pending values from the surrounding tracking batch should be overlaid. Automatic model handling disables this generic overlay because its preplanned batch view already supplies exactly the required predecessors; explicit operations and ordinary handlers enable it.
    • loadContext

      public CommitAttempt loadContext(MutationPlan.Resolution resolution, Long maxStateIndex, Map<String,Object> stagedValues, boolean includeMessageBatch, boolean migration)
    • supplyCurrentModel

      public boolean supplyCurrentModel(String modelId, Class<?> modelType, DefaultModelRepository.CurrentModelSink sink)
      Supplies one independently proven current cache value without allocating an intermediate result object.
    • updateAfterCommit

      public void updateAfterCommit(List<DefaultModelRepository.Commit.Outcome> outcomes)
      Makes accepted local model transitions immediately visible through this repository.
    • beginLocalCommit

      public Runnable beginLocalCommit(Collection<String> modelIds)
      Marks model targets as belonging to an in-flight commit from this SDK so a concurrently observed tracker update does not race the authoritative accepted result into an unnecessary cache refresh.
      Returns:
      an idempotent completion callback
    • invalidateModels

      public void invalidateModels(Iterable<String> modelIds)
      Removes commit-scoped entries before a strict-policy retry reload.