Class DatasetPatch

java.lang.Object
ai.chatur.cortex.core.jena.DatasetPatch

public final class DatasetPatch extends Object
Collects additions and deletions as an RDF patch and applies them to a Dataset in one write transaction.

Recording the changes and applying them are two separate steps: add(org.apache.jena.graph.Node, org.apache.jena.graph.Node, org.apache.jena.graph.Node, org.apache.jena.graph.Node) and delete(org.apache.jena.graph.Node, org.apache.jena.graph.Node, org.apache.jena.graph.Node, org.apache.jena.graph.Node) only record the change, and the patch is played onto the dataset — as a single write transaction on dataset — only once the recording Consumer returns. This lets callers build up a patch from several sources — several models, a filtered stream of a live graph — without holding the dataset's write lock while they do it.

  • Method Summary

    Modifier and Type
    Method
    Description
    add(org.apache.jena.graph.Node graph, org.apache.jena.graph.Node subject, org.apache.jena.graph.Node predicate, org.apache.jena.graph.Node object)
    Records the addition of a triple to the given graph.
    addAll(org.apache.jena.graph.Node graph, org.apache.jena.rdf.model.Model model)
    Records the addition of every triple of the model to the given graph.
    static void
    apply(org.apache.jena.query.Dataset dataset, Consumer<DatasetPatch> changes)
    Records changes and applies them to the dataset as a single patch.
    static void
    applyReading(org.apache.jena.query.Dataset dataset, Consumer<DatasetPatch> changes)
    Records changes inside a read transaction on the dataset, then applies them as one patch.
    delete(org.apache.jena.graph.Node graph, org.apache.jena.graph.Node subject, org.apache.jena.graph.Node predicate, org.apache.jena.graph.Node object)
    Records the deletion of a triple from the given graph.
    deleteAll(org.apache.jena.graph.Node graph, org.apache.jena.rdf.model.Model model)
    Records the deletion of every triple of the model from the given graph.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • apply

      public static void apply(org.apache.jena.query.Dataset dataset, Consumer<DatasetPatch> changes)
      Records changes and applies them to the dataset as a single patch.
      Parameters:
      dataset - the dataset to patch
      changes - records the additions and deletions to apply
    • applyReading

      public static void applyReading(org.apache.jena.query.Dataset dataset, Consumer<DatasetPatch> changes)
      Records changes inside a read transaction on the dataset, then applies them as one patch.

      Use this instead of apply(org.apache.jena.query.Dataset, java.util.function.Consumer<ai.chatur.cortex.core.jena.DatasetPatch>) when recording the changes needs to read the dataset being patched — for example, streaming the triples of a live named graph to decide what to delete. The read transaction covers only the recording; applying the resulting patch is a separate write transaction, opened after the read transaction has closed.

      Parameters:
      dataset - the dataset to patch
      changes - records the additions and deletions to apply, with a read transaction on dataset held open for the duration
    • add

      public DatasetPatch add(org.apache.jena.graph.Node graph, org.apache.jena.graph.Node subject, org.apache.jena.graph.Node predicate, org.apache.jena.graph.Node object)
      Records the addition of a triple to the given graph.
      Parameters:
      graph - the named graph the triple belongs to, or Quad.defaultGraphIRI for the default graph
      subject - the subject of the triple
      predicate - the predicate of the triple
      object - the object of the triple
      Returns:
      this patch, for chaining
    • delete

      public DatasetPatch delete(org.apache.jena.graph.Node graph, org.apache.jena.graph.Node subject, org.apache.jena.graph.Node predicate, org.apache.jena.graph.Node object)
      Records the deletion of a triple from the given graph.
      Parameters:
      graph - the named graph the triple belongs to, or Quad.defaultGraphIRI for the default graph
      subject - the subject of the triple
      predicate - the predicate of the triple
      object - the object of the triple
      Returns:
      this patch, for chaining
    • addAll

      public DatasetPatch addAll(org.apache.jena.graph.Node graph, org.apache.jena.rdf.model.Model model)
      Records the addition of every triple of the model to the given graph.
      Parameters:
      graph - the named graph to add the triples to, or Quad.defaultGraphIRI for the default graph
      model - the model whose triples are added
      Returns:
      this patch, for chaining
    • deleteAll

      public DatasetPatch deleteAll(org.apache.jena.graph.Node graph, org.apache.jena.rdf.model.Model model)
      Records the deletion of every triple of the model from the given graph.
      Parameters:
      graph - the named graph to delete the triples from, or Quad.defaultGraphIRI for the default graph
      model - the model whose triples are deleted
      Returns:
      this patch, for chaining