Class RDFStorage

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class RDFStorage
    extends Object
    implements Closeable
    This class provides an abstraction of an RDF repository and implements the common low-level operations.
    Author:
    burgetr
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected RDFStorage​(org.eclipse.rdf4j.repository.Repository repo)
      Use the create functions for creating the instances.
    • Constructor Detail

      • RDFStorage

        protected RDFStorage​(org.eclipse.rdf4j.repository.Repository repo)
        Use the create functions for creating the instances.
    • Method Detail

      • create

        public static RDFStorage create​(org.eclipse.rdf4j.repository.Repository repo)
      • getRepository

        public org.eclipse.rdf4j.repository.Repository getRepository()
      • getConnection

        public org.eclipse.rdf4j.repository.RepositoryConnection getConnection()
      • getPropertyValue

        public org.eclipse.rdf4j.model.Value getPropertyValue​(org.eclipse.rdf4j.model.Resource subject,
                                                              org.eclipse.rdf4j.model.IRI predicate)
                                                       throws StorageException
        Obtains the value of the given predicate for the given subject.
        Parameters:
        subject - the subject resource
        predicate - the predicate IRI
        Returns:
        the resulting Value or null when there is no corresponding triplet available.
        Throws:
        StorageException
      • getSubjectModel

        public org.eclipse.rdf4j.model.Model getSubjectModel​(org.eclipse.rdf4j.model.Resource subject)
                                                      throws StorageException
        Obtains a model for the specific subject.
        Parameters:
        subject -
        Returns:
        Throws:
        StorageException
      • getSubjectType

        public org.eclipse.rdf4j.model.IRI getSubjectType​(org.eclipse.rdf4j.model.Resource subject)
                                                   throws StorageException
        Determines the type of the subject as determined by the corresponding rdf:type predicate (if present)
        Parameters:
        subject - the subject IRI
        Returns:
        the type IRI or null when the type is not defined
        Throws:
        StorageException
      • getContextModel

        public org.eclipse.rdf4j.model.Model getContextModel​(org.eclipse.rdf4j.model.Resource context)
                                                      throws StorageException
        Obtains a model containing all statements in a given context.
        Parameters:
        context - the context IRI
        Returns:
        Throws:
        StorageException
      • getContextModel

        public org.eclipse.rdf4j.model.Model getContextModel​(Collection<org.eclipse.rdf4j.model.Resource> contexts)
                                                      throws StorageException
        Obtains a model containing all statements in a given context.
        Parameters:
        contexts - the context IRIs
        Returns:
        Throws:
        StorageException
      • executeSafeQuery

        public org.eclipse.rdf4j.model.Model executeSafeQuery​(String query)
                                                       throws StorageException
        Executes an internal (safe) SPARQL graph query.
        Parameters:
        query - the SPARQL query
        Returns:
        a the resulting model
        Throws:
        StorageException
      • executeSafeTupleQuery

        public List<org.eclipse.rdf4j.query.BindingSet> executeSafeTupleQuery​(String query)
                                                                       throws StorageException
        Executes an internal (safe) tuple query.
        Parameters:
        query -
        Returns:
        a list of binding sets object representing the result
        Throws:
        StorageException
      • add

        public void add​(org.eclipse.rdf4j.model.IRI subj,
                        org.eclipse.rdf4j.model.IRI pred,
                        org.eclipse.rdf4j.model.IRI obj,
                        org.eclipse.rdf4j.model.IRI context)
        Adds a new quadruple to the storage.
        Parameters:
        subj -
        pred -
        obj -
        context -
      • addValue

        public void addValue​(org.eclipse.rdf4j.model.IRI subj,
                             org.eclipse.rdf4j.model.IRI pred,
                             Object value,
                             org.eclipse.rdf4j.model.IRI context)
        Adds a new data quadruple to the storage.
        Parameters:
        subj -
        pred -
        value -
        context -
      • insertGraph

        public void insertGraph​(org.eclipse.rdf4j.model.Model graph)
                         throws StorageException
        Inserts a new graph to the database.
        Parameters:
        graph -
        Throws:
        StorageException
      • insertGraph

        public void insertGraph​(org.eclipse.rdf4j.model.Model graph,
                                org.eclipse.rdf4j.model.IRI contextIri)
                         throws StorageException
        Inserts a new graph to the database.
        Parameters:
        graph -
        contextIri - the context to be used for the inserted statements
        Throws:
        StorageException
      • getLastSequenceValue

        public long getLastSequenceValue​(org.eclipse.rdf4j.model.IRI sequenceIri)
                                  throws StorageException
        Obtains the last assigned value of a sequence with the given name.
        Parameters:
        sequenceIri - the sequence IRI
        Returns:
        the last assigned value or 0 when the sequence does not exist.
        Throws:
        StorageException