java.lang.Object
org.eclipse.rdf4j.sail.helpers.SailWrapper
org.eclipse.rdf4j.sail.helpers.NotifyingSailWrapper
it.uniroma2.art.semanticturkey.changetracking.sail.ChangeTracker
All Implemented Interfaces:
org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedServiceResolverClient, org.eclipse.rdf4j.repository.RepositoryResolverClient, org.eclipse.rdf4j.repository.sail.config.RepositoryResolverClient, org.eclipse.rdf4j.sail.NotifyingSail, org.eclipse.rdf4j.sail.Sail, org.eclipse.rdf4j.sail.StackableSail

public class ChangeTracker extends org.eclipse.rdf4j.sail.helpers.NotifyingSailWrapper implements org.eclipse.rdf4j.repository.sail.config.RepositoryResolverClient
A NotifyingSail keeping track of changes to an underlying Sail. Each commit containing at least one relevant update is recorded into the support repository. The representation of the history conforms to the vocabulary CHANGELOG.

A change is recorded only if it is an effective update to the underlying data: i.e. either adding a triple that wasn't already assert, or removing a previously asserted triples. Self-canceling operations are ignored as well.

The client of this Sail can manage the tracking system, by reading/writing appropriate contexts: these operations are intercepted by this Sail, so that they are not executed against the underlying data. Currently, only addStatement(..), removeStatements(...) and getStatements(..) are supported. In particular, SPARQL Queries cannot be used to read the special-purpose contexts defined by this Sail.

The contexts CHANGETRACKER.STAGED_ADDITIONS and CHANGETRACKER.STAGED_REMOVALS can be used to list the triples being staged for addition and removal, respectively.

The context CHANGETRACKER.GRAPH_MANAGEMENT contains the description of a homonymous resource, which is associated with the graphs to include and exclude, via the properties CHANGETRACKER.INCLUDE_GRAPH and CHANGETRACKER.EXCLUDE_GRAPH, respectively. An update is recorded into the history only if its context is a graph such that it satisfies the inclusion criterion and it does not satisfy the exclusion criterion. An empty set of included graphs is equivalent to include all graphs, while an empty set of excluded graphs is equivalent to not rejecting any graph. The resource CHANGELOG.NULL (formerly SESAME.NIL) represents the null context, while SESAME.WILDCARD is another mechanism to specify all graphs.

By default, the history ignores the null context and includes other contexts. Excluding the null context is a simple mechanism to ignore inferred triples.

It is possible to write additional metadata about a commit through the context CHANGETRACKER.COMMIT_METADATA. Since the client doesn't know which resource will represent the commit in the history repository, the client may identify the commit via the IRI CHANGETRACKER.COMMIT_METADATA: when the commit metadata is written into the history, this identifier will be replace with the actual identifier of the commit.

When validation is enabled, write operations are first logged inside the validation graph (in the support repository) and applied to the staging graphs (in the core repository).

To accept/reject a previous transaction, it is sufficient to write in the context CHANGETRACKER.VALIDATION, as follows: conn.add(commitIRI, CHANGETRACKER.VALIDATION, CHANGETRACKER.ACCEPT | CHANGETRACKER.ACCEPT, CHANGETRACKER.VALIDATION)

Author:
Manuel Fiorelli
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
    • OPTIONAL_TRUE

      public static final Optional<Boolean> OPTIONAL_TRUE
    • OPTIONAL_FALSE

      public static final Optional<Boolean> OPTIONAL_FALSE
    • PROPERTIES

      public static final String PROPERTIES
      See Also:
    • props

      protected static final Properties props
    • PROP_VERSION

      protected static final String PROP_VERSION
      See Also:
    • version

      protected static final String version
    • supportRepoId

      protected final String supportRepoId
    • serverURL

      protected final String serverURL
    • metadataNS

      protected final String metadataNS
    • historyGraph

      protected final org.eclipse.rdf4j.model.IRI historyGraph
    • validationGraph

      protected final org.eclipse.rdf4j.model.IRI validationGraph
    • blacklistGraph

      protected final org.eclipse.rdf4j.model.IRI blacklistGraph
    • graphManagement

      protected final org.eclipse.rdf4j.model.Model graphManagement
    • historyEnabled

      protected final boolean historyEnabled
    • validationEnabled

      protected final boolean validationEnabled
    • undoEnabled

      protected final boolean undoEnabled
    • blacklistEnabled

      protected final boolean blacklistEnabled
    • interactiveNotifications

      protected final Optional<Boolean> interactiveNotifications
    • undoStack

      protected Optional<UndoStack> undoStack
  • Constructor Details

    • ChangeTracker

      public ChangeTracker(String serverURL, String supportRepoId, String metadataNS, org.eclipse.rdf4j.model.IRI historyGraph, Set<org.eclipse.rdf4j.model.IRI> includeGraph, Set<org.eclipse.rdf4j.model.IRI> excludeGraph, boolean historyEnabled, boolean validationEnabled, boolean undoEnabled, Optional<Boolean> interactiveNotifications, org.eclipse.rdf4j.model.IRI validationGraph, boolean blacklistEnabled, org.eclipse.rdf4j.model.IRI blacklistGraph)
  • Method Details

    • getVersion

      public static String getVersion()
    • setRepositoryResolver

      public void setRepositoryResolver(org.eclipse.rdf4j.repository.RepositoryResolver resolver)
      Specified by:
      setRepositoryResolver in interface org.eclipse.rdf4j.repository.RepositoryResolverClient
    • setRepositoryResolver

      public void setRepositoryResolver(org.eclipse.rdf4j.repository.sail.config.RepositoryResolver resolver)
    • init

      public void init() throws org.eclipse.rdf4j.sail.SailException
      Specified by:
      init in interface org.eclipse.rdf4j.sail.Sail
      Overrides:
      init in class org.eclipse.rdf4j.sail.helpers.SailWrapper
      Throws:
      org.eclipse.rdf4j.sail.SailException
    • shutDown

      public void shutDown() throws org.eclipse.rdf4j.sail.SailException
      Specified by:
      shutDown in interface org.eclipse.rdf4j.sail.Sail
      Overrides:
      shutDown in class org.eclipse.rdf4j.sail.helpers.SailWrapper
      Throws:
      org.eclipse.rdf4j.sail.SailException
    • getConnection

      public ChangeTrackerConnection getConnection() throws org.eclipse.rdf4j.sail.SailException
      Specified by:
      getConnection in interface org.eclipse.rdf4j.sail.NotifyingSail
      Specified by:
      getConnection in interface org.eclipse.rdf4j.sail.Sail
      Overrides:
      getConnection in class org.eclipse.rdf4j.sail.helpers.NotifyingSailWrapper
      Throws:
      org.eclipse.rdf4j.sail.SailException
    • getDefaultIsolationLevel

      public org.eclipse.rdf4j.common.transaction.IsolationLevel getDefaultIsolationLevel()
      Specified by:
      getDefaultIsolationLevel in interface org.eclipse.rdf4j.sail.Sail
      Overrides:
      getDefaultIsolationLevel in class org.eclipse.rdf4j.sail.helpers.SailWrapper
    • getSupportedIsolationLevels

      public List<org.eclipse.rdf4j.common.transaction.IsolationLevel> getSupportedIsolationLevels()
      Specified by:
      getSupportedIsolationLevels in interface org.eclipse.rdf4j.sail.Sail
      Overrides:
      getSupportedIsolationLevels in class org.eclipse.rdf4j.sail.helpers.SailWrapper