Class SharedStorageConnector

java.lang.Object
cz.cvut.kbss.ontodriver.jena.connector.SharedStorageConnector
All Implemented Interfaces:
Closeable, StatementExecutor, StorageConnector, Wrapper
Direct Known Subclasses:
SnapshotStorageConnector

public class SharedStorageConnector extends Object
Main storage connector using the JenaOntoDriverProperties.READ_COMMITTED connector strategy.

Adding statements to it actually adds them to the repository.

Note on transactions:

Starting a transaction on this connector also starts a write transaction on the underlying dataset. Commit then commits the transaction. Therefore, these transactions should be short. Reading can happen in parallel (as per Jena documentation).

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(List<org.apache.jena.rdf.model.Statement> statements, String context)
    Adds the specified statements to the specified context in the storage.
    void
    Begins a transaction.
    void
    Closes this resource releasing any sub-resources it holds.
    void
    Commits the current transaction.
    boolean
    contains(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property property, org.apache.jena.rdf.model.RDFNode value, Collection<String> contexts)
    Checks whether the specified context (named graph) contains any statements matching the specified criteria.
    executeAskQuery(org.apache.jena.query.Query query, Statement.StatementOntology target)
    Executes the specified SPARQL ASK query.
    executeSelectQuery(org.apache.jena.query.Query query, Statement.StatementOntology target)
    Executes the specified SPARQL SELECT query, returning the Jena ARQ result set.
    void
    Executes the specified SPARQL 1.1 Update query.
    Collection<org.apache.jena.rdf.model.Statement>
    find(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property property, org.apache.jena.rdf.model.RDFNode value, Collection<String> contexts)
    Retrieves statements corresponding to the specified criteria from the specified named graph.
    Lists all contexts (named graph) in the repository (including the transactional ones).
    boolean
    Retrieves status of this resource.
    void
    Reloads data from the underlying storage (if possible).
    void
    remove(List<org.apache.jena.rdf.model.Statement> statements, String context)
    Removes the specified statements from the specified context in the storage.
    void
    remove(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property property, org.apache.jena.rdf.model.RDFNode object, String context)
    Removes statements matching the specified pattern from the specified storage context.
    void
    Removes all property values specified by the provided argument for the specified subject(s).
    void
    Rolls back the current transaction.
    void
    setDataset(org.apache.jena.query.Dataset dataset)
    Sets new dataset on the underlying storage.
    <T> T
    unwrap(Class<T> cls)
    Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.

    Methods inherited from class java.lang.Object

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

    • begin

      public void begin()
      Description copied from interface: StorageConnector
      Begins a transaction.
    • commit

      public void commit() throws JenaDriverException
      Description copied from interface: StorageConnector
      Commits the current transaction.
      Throws:
      JenaDriverException - If commit fails
    • rollback

      public void rollback()
      Description copied from interface: StorageConnector
      Rolls back the current transaction.
    • find

      public Collection<org.apache.jena.rdf.model.Statement> find(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property property, org.apache.jena.rdf.model.RDFNode value, Collection<String> contexts)
      Description copied from interface: StorageConnector
      Retrieves statements corresponding to the specified criteria from the specified named graph.

      The first three parameters are optional, their absence signifies that any value in that position is acceptable.

      contexts are also optional, their absence means that the default graph should be used.

      Parameters:
      subject - Statement subject, optional
      property - Property, optional
      value - Value, optional
      contexts - Named graph IRIs, optional. If empty, the default graph will be used
      Returns:
      Collection of matching statements
    • contains

      public boolean contains(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property property, org.apache.jena.rdf.model.RDFNode value, Collection<String> contexts)
      Description copied from interface: StorageConnector
      Checks whether the specified context (named graph) contains any statements matching the specified criteria.

      The first three parameters are optional, their absence signifies that any value in that position is acceptable.

      context is also optional, its absence means that the default graph should be used.

      Parameters:
      subject - Subject, optional
      property - Property, optional
      value - Value, optional
      contexts - Named graph IRIs, optional. If empty, the default graph will be used
      Returns:
      true if at least one statement matches the criteria, false otherwise
    • getContexts

      public List<String> getContexts()
      Description copied from interface: StorageConnector
      Lists all contexts (named graph) in the repository (including the transactional ones).
      Returns:
      List of named graph URIs
    • add

      public void add(List<org.apache.jena.rdf.model.Statement> statements, String context)
      Description copied from interface: StorageConnector
      Adds the specified statements to the specified context in the storage.

      Requires an active transaction.

      context is optional, its absence means that the statements will be added into the the default graph.

      Parameters:
      statements - Statements to add
      context - Target context, optional
    • remove

      public void remove(List<org.apache.jena.rdf.model.Statement> statements, String context)
      Description copied from interface: StorageConnector
      Removes the specified statements from the specified context in the storage.

      Requires an active transaction.

      context is optional, its absence means that the statements will be removed from the the default graph.

      Parameters:
      statements - Statements to remove
      context - Target context, optional
    • remove

      public void remove(org.apache.jena.rdf.model.Resource subject, org.apache.jena.rdf.model.Property property, org.apache.jena.rdf.model.RDFNode object, String context)
      Description copied from interface: StorageConnector
      Removes statements matching the specified pattern from the specified storage context.

      context is optional, its absence means that the statements will be removed from the the default graph.

      Parameters:
      subject - Statement subject, optional
      property - Statement property, optional
      object - Statement object, optional
      context - Repository context IRI, optional
    • removePropertyValues

      public void removePropertyValues(Collection<SubjectPredicateContext> spc)
      Description copied from interface: StorageConnector
      Removes all property values specified by the provided argument for the specified subject(s).
      Parameters:
      spc - Subject-predicate-contexts tuples
    • executeSelectQuery

      public AbstractResultSet executeSelectQuery(org.apache.jena.query.Query query, Statement.StatementOntology target) throws JenaDriverException
      Description copied from interface: StatementExecutor
      Executes the specified SPARQL SELECT query, returning the Jena ARQ result set.

      The target specifies whether the query should be executed on the shared repository or whether the transactional snapshot will be used to evaluate the query. However, some implementations may ignore this parameter.

      Parameters:
      query - Query to execute
      target - Dataset on which the query should be executed
      Returns:
      ARQ result set
      Throws:
      JenaDriverException - If query execution fails
    • executeAskQuery

      public AbstractResultSet executeAskQuery(org.apache.jena.query.Query query, Statement.StatementOntology target) throws JenaDriverException
      Description copied from interface: StatementExecutor
      Executes the specified SPARQL ASK query.

      The target specifies whether the query should be executed on the shared repository or whether the transactional snapshot will be used to evaluate the query. However, some implementations may ignore this parameter.

      Parameters:
      query - Query to execute
      target - Dataset on which the query should be executed
      Returns:
      ASK result
      Throws:
      JenaDriverException - If query execution fails
    • executeUpdate

      public void executeUpdate(String query, Statement.StatementOntology target) throws JenaDriverException
      Description copied from interface: StatementExecutor
      Executes the specified SPARQL 1.1 Update query.

      The target specifies whether the query should be executed on the shared repository or whether the transactional snapshot will be used to evaluate the query. However, some implementations may ignore this parameter.

      Parameters:
      query - Query to execute
      target - Dataset on which the update should be executed
      Throws:
      JenaDriverException - If query execution fails
    • close

      public void close()
      Description copied from interface: Closeable
      Closes this resource releasing any sub-resources it holds.

      After closing the resource is not usable any more and calling methods on it (except close and isOpen) will result in IllegalStateException.

      Calling close on already closed resource does nothing.

      Specified by:
      close in interface Closeable
      Specified by:
      close in interface StorageConnector
    • reloadStorage

      public void reloadStorage()
      Reloads data from the underlying storage (if possible).

      Note that this applies only to RDF file-based storage access, other storage do not support reloading.

    • setDataset

      public void setDataset(org.apache.jena.query.Dataset dataset)
      Sets new dataset on the underlying storage.

      Note that this is supported only for in-memory storage.

      Parameters:
      dataset - The dataset to use
    • isOpen

      public boolean isOpen()
      Description copied from interface: Closeable
      Retrieves status of this resource.
      Specified by:
      isOpen in interface Closeable
      Returns:
      true if the resource is open, false otherwise
    • unwrap

      public <T> T unwrap(Class<T> cls)
      Description copied from interface: Wrapper
      Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. If the receiver implements the interface then the result is the receiver or a proxy for the receiver. If the receiver is a wrapper and the wrapped object implements the interface then the result is the wrapped object or a proxy for the wrapped object. Otherwise return the the result of calling unwrap recursively on the wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface, then an OntoDriverException is thrown.
      Specified by:
      unwrap in interface Wrapper
      Type Parameters:
      T - The type of the class modeled by this Class object
      Parameters:
      cls - The type of the required result
      Returns:
      An object implementing the interface