Class DefaultModelRepository

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

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>
    • configureReplayRestoration

      public void configureReplayRestoration(UnaryOperator<DeserializingMessage> restoration)
      Configures application-owned event payload restoration before this repository is made available to callers.
    • 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.
    • configureAutomaticModelRouting

      public void configureAutomaticModelRouting(boolean enabled)
      Configures the single-Model event-routing fallback before this repository starts handling commits.
    • modelName

      public String modelName(Class<?> modelType)
      Description copied from interface: ModelTypeResolver
      Returns and registers the stable logical name for one concrete Model type.
      Specified by:
      modelName in interface ModelTypeResolver
    • modelType

      public Class<?> modelType(String modelName, String modelId)
      Description copied from interface: ModelTypeResolver
      Resolves a stored logical name to a registered concrete Model type.
      Specified by:
      modelType in interface ModelTypeResolver
    • knownModelType

      public Optional<Class<?>> knownModelType(String modelName, String modelId)
      Description copied from interface: ModelTypeResolver
      Looks up a logical name without interpreting missing local registration as corrupt stored data. Implementations that do not support unknown types retain their strict resolution; application or registry failures still fail.
      Specified by:
      knownModelType in interface ModelTypeResolver
    • 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
    • graphStagedValues

      public ModelBatchScope.Snapshot graphStagedValues(io.fluxzero.common.api.modeling.ModelReadBoundary boundary)
      Description copied from interface: ModelGraphResolver
      Captures the current message-batch overlay once for a new navigation view.
      Specified by:
      graphStagedValues in interface ModelGraphResolver
    • loadGraphProjection

      public Graph<?> loadGraphProjection(String rootId, Class<?> rootType, io.fluxzero.common.api.modeling.ModelReadBoundary boundary, boolean historical)
      Description copied from interface: ModelGraphResolver
      Strictly materializes a full graph at the selected boundary without consulting later batch state.
      Specified by:
      loadGraphProjection in interface ModelGraphResolver
    • loadGraphProjection

      public Graph<?> loadGraphProjection(String rootId, Class<?> rootType, io.fluxzero.common.api.modeling.ModelReadBoundary boundary, boolean historical, Entity<?> resolvedRoot)
      Description copied from interface: ModelGraphResolver
      Materializes relationships while retaining a root value whose identity or absence was already resolved. A resolver opting into metadata-only identity resolution must implement this operation for absent roots; silently resolving the supplied identity again could bind it to a different model.
      Specified by:
      loadGraphProjection in interface ModelGraphResolver
    • loadCurrentGraphValue

      public ModelGraphResolver.Value loadCurrentGraphValue(Object modelId, Class<?> modelType)
      Description copied from interface: ModelGraphResolver
      Loads deliberately current state with its namespace boundary, ignoring any active handler boundary.
      Specified by:
      loadCurrentGraphValue in interface ModelGraphResolver
    • loadGraphValue

      public ModelGraphResolver.Value loadGraphValue(Object modelId, boolean exact, Class<?> modelType, io.fluxzero.common.api.modeling.ModelReadBoundary boundary)
      Description copied from interface: ModelGraphResolver
      Loads a source value and retains the coherent boundary that ordinary single-value APIs do not expose.
      Specified by:
      loadGraphValue in interface ModelGraphResolver
    • resolveGraphIdentity

      public ModelGraphResolver.Identity resolveGraphIdentity(Object modelId, Class<?> modelType, io.fluxzero.common.api.modeling.ModelReadBoundary boundary)
      Description copied from interface: ModelGraphResolver
      Resolves an identity without requiring its value. The returned supplier must retain the resolved identity, absence and boundary even if the alias changes later. Returning null (the default) retains a custom repository's existing value-based identity lookup, without opting into metadata-only identity resolution.
      Specified by:
      resolveGraphIdentity in interface ModelGraphResolver
    • resolveGraphIdentity

      public ModelGraphResolver.Identity resolveGraphIdentity(Object modelId, boolean exact, Class<?> modelType, io.fluxzero.common.api.modeling.ModelReadBoundary boundary)
      Description copied from interface: ModelGraphResolver
      Resolves an exact persisted key without applying functional-ID affixes a second time.
      Specified by:
      resolveGraphIdentity in interface ModelGraphResolver
    • resolveCurrentGraphIdentity

      public ModelGraphResolver.Identity resolveCurrentGraphIdentity(Object modelId, Class<?> modelType)
      Description copied from interface: ModelGraphResolver
      Optional metadata-first current root; the default retains the existing current-value route.
      Specified by:
      resolveCurrentGraphIdentity in interface ModelGraphResolver
    • resolveUntypedGraphIdentity

      public ModelGraphResolver.Identity resolveUntypedGraphIdentity(Object modelId)
      Description copied from interface: ModelGraphResolver
      Optional untyped root discovery; an implementation supplies its resolved class through ModelGraphResolver.HeadValue.
      Specified by:
      resolveUntypedGraphIdentity in interface ModelGraphResolver
    • loadGraphValues

      public Map<String, Entity<?>> loadGraphValues(Map<String,Class<?>> modelTypes, io.fluxzero.common.api.modeling.ModelReadBoundary boundary, Map<String, Entity<?>> staged, boolean historical)
      Description copied from interface: ModelGraphResolver
      Reconstructs explicitly requested values together; unrelated metadata nodes must remain unloaded.
      Specified by:
      loadGraphValues in interface ModelGraphResolver
    • loadGraphRelations

      public ModelGraphResolver.Relations loadGraphRelations(List<String> modelIds, io.fluxzero.common.api.modeling.ModelRelationshipRead.Direction direction, io.fluxzero.common.api.modeling.ModelReadBoundary boundary, Map<String, Entity<?>> staged, boolean historical)
      Description copied from interface: ModelGraphResolver
      Reads direct relationships and heads without loading values. The supplied staged snapshot takes precedence over durable relationships and must also be used by returned value suppliers. No implicit later batch reads.
      Specified by:
      loadGraphRelations in interface ModelGraphResolver
    • 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
    • loadAncestorGraph

      public <A> Optional<Graph<A>> loadAncestorGraph(String modelId, Class<?> modelType, Class<A> ancestorType, io.fluxzero.common.api.modeling.ModelReadBoundary boundary, Consumer<ModelAncestorResolver.AncestorReads> observer)
      Description copied from interface: ModelAncestorResolver
      Resolves an ancestor while reporting the identities inspected by the relationship traversal, including a negative result. Implementations can override this to preserve identity-only traversal for transactional Graph reads. The default reports no proof; the Graph then gathers dependencies through its ordinary parents.
      Specified by:
      loadAncestorGraph 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)
    • loadRebaseContext

      public CommitAttempt loadRebaseContext(MutationPlan.Resolution resolution, Long maxStateIndex, Map<String,Object> stagedValues, boolean includeMessageBatch, boolean migration)
      Reloads an ACCEPT rebase while allowing an incomplete authoritative document to advance the exact boundary. Ordinary historical reads never enable this retry mode.
    • 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.
    • loadCurrentState

      public <T> ModelState<T> loadCurrentState(@NonNull @NonNull String modelId, @NonNull @NonNull Class<T> modelType)
      Description copied from interface: ModelRepository
      Reads a current document-backed Model value without replaying historical events. The returned state is read-only, independently current (not handler-historical), and not an implicit commit dependency. A missing/deleted Model has no value; a live Model with an unavailable, stale or unversioned document fails explicitly. No automatic replay, event skipping or ordinary Model-cache update takes place. The Runtime must attest a body/head proof captured with trusted Model materialization/adoption; older unproven documents require a new eligible trusted write and are never retroactively certified by a read. Custom repositories must implement the verified document capability; the default never emulates it by replay. This overload uses the exact persisted identity, not an alias.
      Specified by:
      loadCurrentState in interface ModelRepository