Package cz.vutbr.fit.layout.rdf
Class RDFStorage
- java.lang.Object
-
- cz.vutbr.fit.layout.rdf.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 protectedRDFStorage(org.eclipse.rdf4j.repository.Repository repo)Use the create functions for creating the instances.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(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.voidaddNamespace(String prefix, String namespace)voidaddValue(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.voidclear()Clears the entire RDF repository.voidclear(org.eclipse.rdf4j.model.IRI context)Clears the entire RDF repository.voidclearNamespaces()voidclose()static RDFStoragecreate(org.eclipse.rdf4j.repository.Repository repo)static RDFStoragecreateHTTP(String serverUrl, String repositoryId)static RDFStoragecreateMemory(String dataDir)static RDFStoragecreateNative(String dataDir)voiddeleteNamespace(String prefix)voidexecSparqlUpdate(String query)org.eclipse.rdf4j.model.ModelexecuteSafeQuery(String query)Executes an internal (safe) SPARQL graph query.List<org.eclipse.rdf4j.query.BindingSet>executeSafeTupleQuery(String query)Executes an internal (safe) tuple query.org.eclipse.rdf4j.repository.RepositoryConnectiongetConnection()org.eclipse.rdf4j.model.ModelgetContextModel(Collection<org.eclipse.rdf4j.model.Resource> contexts)Obtains a model containing all statements in a given context.org.eclipse.rdf4j.model.ModelgetContextModel(org.eclipse.rdf4j.model.Resource context)Obtains a model containing all statements in a given context.longgetLastSequenceValue(org.eclipse.rdf4j.model.IRI sequenceIri)Obtains the last assigned value of a sequence with the given name.StringgetNamespace(String prefix)List<org.eclipse.rdf4j.model.Namespace>getNamespaces()longgetNextSequenceValue(org.eclipse.rdf4j.model.IRI sequenceIri)org.eclipse.rdf4j.model.ValuegetPropertyValue(org.eclipse.rdf4j.model.Resource subject, org.eclipse.rdf4j.model.IRI predicate)Obtains the value of the given predicate for the given subject.org.eclipse.rdf4j.repository.RepositorygetRepository()org.eclipse.rdf4j.model.ModelgetSubjectModel(org.eclipse.rdf4j.model.Resource subject)Obtains a model for the specific subject.org.eclipse.rdf4j.model.IRIgetSubjectType(org.eclipse.rdf4j.model.Resource subject)Determines the type of the subject as determined by the corresponding rdf:type predicate (if present)org.eclipse.rdf4j.model.ValueFactorygetValueFactory()voidimportTurtle(String query)voidimportTurtle(String query, org.eclipse.rdf4j.model.IRI context)voidimportXML(String query)voidimportXML(String query, org.eclipse.rdf4j.model.IRI context)voidinsertGraph(org.eclipse.rdf4j.model.Model graph)Inserts a new graph to the database.voidinsertGraph(org.eclipse.rdf4j.model.Model graph, org.eclipse.rdf4j.model.IRI contextIri)Inserts a new graph to the database.voidqueryExportCSV(String queryString, OutputStream ostream)
-
-
-
Method Detail
-
create
public static RDFStorage create(org.eclipse.rdf4j.repository.Repository repo)
-
createMemory
public static RDFStorage createMemory(String dataDir)
-
createNative
public static RDFStorage createNative(String dataDir)
-
createHTTP
public static RDFStorage createHTTP(String serverUrl, String repositoryId)
-
getRepository
public org.eclipse.rdf4j.repository.Repository getRepository()
-
getValueFactory
public org.eclipse.rdf4j.model.ValueFactory getValueFactory()
-
getConnection
public org.eclipse.rdf4j.repository.RepositoryConnection getConnection()
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getPropertyValue
public org.eclipse.rdf4j.model.Value getPropertyValue(org.eclipse.rdf4j.model.Resource subject, org.eclipse.rdf4j.model.IRI predicate) throws StorageExceptionObtains the value of the given predicate for the given subject.- Parameters:
subject- the subject resourcepredicate- the predicate IRI- Returns:
- the resulting Value or
nullwhen there is no corresponding triplet available. - Throws:
StorageException
-
getSubjectModel
public org.eclipse.rdf4j.model.Model getSubjectModel(org.eclipse.rdf4j.model.Resource subject) throws StorageExceptionObtains 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 StorageExceptionDetermines 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
nullwhen the type is not defined - Throws:
StorageException
-
getContextModel
public org.eclipse.rdf4j.model.Model getContextModel(org.eclipse.rdf4j.model.Resource context) throws StorageExceptionObtains 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 StorageExceptionInserts 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 StorageExceptionInserts a new graph to the database.- Parameters:
graph-contextIri- the context to be used for the inserted statements- Throws:
StorageException
-
clear
public void clear() throws StorageExceptionClears the entire RDF repository.- Throws:
StorageException
-
clear
public void clear(org.eclipse.rdf4j.model.IRI context) throws StorageExceptionClears the entire RDF repository.- Throws:
StorageException
-
execSparqlUpdate
public void execSparqlUpdate(String query) throws StorageException
- Throws:
StorageException
-
importTurtle
public void importTurtle(String query) throws StorageException, IOException
- Throws:
StorageExceptionIOException
-
importTurtle
public void importTurtle(String query, org.eclipse.rdf4j.model.IRI context) throws StorageException, IOException
- Throws:
StorageExceptionIOException
-
importXML
public void importXML(String query) throws StorageException, IOException
- Throws:
StorageExceptionIOException
-
importXML
public void importXML(String query, org.eclipse.rdf4j.model.IRI context) throws StorageException, IOException
- Throws:
StorageExceptionIOException
-
queryExportCSV
public void queryExportCSV(String queryString, OutputStream ostream) throws StorageException
- Throws:
StorageException
-
getLastSequenceValue
public long getLastSequenceValue(org.eclipse.rdf4j.model.IRI sequenceIri) throws StorageExceptionObtains 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
-
getNextSequenceValue
public long getNextSequenceValue(org.eclipse.rdf4j.model.IRI sequenceIri) throws StorageException- Throws:
StorageException
-
getNamespaces
public List<org.eclipse.rdf4j.model.Namespace> getNamespaces()
-
deleteNamespace
public void deleteNamespace(String prefix)
-
clearNamespaces
public void clearNamespaces()
-
-