Class BranchMergeService

java.lang.Object
ai.chatur.cortex.core.branch.BranchMergeService

public class BranchMergeService extends Object
Resolves a branch pending review by merging its staged assertions into the default graph or discarding them.
  • Constructor Details

    • BranchMergeService

      public BranchMergeService(org.apache.jena.query.Dataset assertions, BranchRepository branchRepository, ProvenanceRecorder provenanceRecorder)
      Creates the service.
      Parameters:
      assertions - the dataset holding the approved assertions and the staged branches
      branchRepository - guards every operation against an unknown branch
      provenanceRecorder - builds the provenance recorded when a branch is approved
  • Method Details

    • approve

      public org.apache.jena.rdf.model.Model approve(String branch)
      Merges the assertions staged on the given branch into the default graph, closing the provenance activity of the ingestion and recording the reification of every merged statement, linked to the activity, in the provenance graph, and deletes the branch.

      The novelty diff, the merge, and the branch deletion all happen inside one write transaction on the assertions dataset: TDB2 serializes writers, so two branches can never be approved concurrently, and a failure partway through aborts the whole transaction rather than leaving the data merged while the branch is still pending (which used to risk a second, duplicate prov:Activity on a retried approval). Staged triples that were approved through another branch in the meantime are skipped, so a statement is never merged or reified twice — this is now guaranteed by that same serialization, rather than a best-effort race with the other branch's approval.

      Parameters:
      branch - the branch name
      Returns:
      the newly approved assertions — empty if every staged triple was approved through another branch in the meantime — or null if the branch does not exist
    • reject

      public void reject(String branch)
      Rejects the given branch, discarding its staged assertions, if it exists.
      Parameters:
      branch - the branch name