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 context from the 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 in a default isolation level.org.eclipse.rdf4j.model.ModelexecuteSafeQuery(String query, org.eclipse.rdf4j.common.transaction.IsolationLevel isolationLevel)Executes an internal (safe) SPARQL graph query in a given transaction isolation level.List<org.eclipse.rdf4j.query.BindingSet>executeSafeTupleQuery(String query)Executes an internal (safe) tuple query.SparqlQueryResultexecuteSparqlQuery(String queryString, boolean distinct, long limit, long offset)Checks and executes extrenal (possibly unsafe) SPARQL query and returns a result depending on the query type.List<org.eclipse.rdf4j.query.BindingSet>executeSparqlTupleQuery(String queryString, boolean distinct, long limit, long offset)Checks and executes extrenal (possibly unsafe) SPARQL SELECT query and returns a result.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.List<org.eclipse.rdf4j.model.Resource>getContexts()longgetLastSequenceValue(org.eclipse.rdf4j.model.IRI sequenceIri)Obtains the last assigned value of a sequence with the given name.static ObjectgetLiteralAsObject(org.eclipse.rdf4j.model.Literal lval)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()Collection<org.eclipse.rdf4j.model.Resource>getResourcesOfType(org.eclipse.rdf4j.model.IRI type)Finds IRIs of resources of the given type.Collection<org.eclipse.rdf4j.model.Resource>getResourcesOfType(org.eclipse.rdf4j.model.IRI type, org.eclipse.rdf4j.model.Resource context)Finds IRIs of resources of the given type.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()voidimportStream(InputStream stream, org.eclipse.rdf4j.rio.RDFFormat dataFormat)voidimportStream(InputStream stream, org.eclipse.rdf4j.rio.RDFFormat dataFormat, String baseURI)voidimportStream(InputStream stream, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.IRI context)voidimportStream(InputStream stream, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.IRI context, String baseURI)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.ServiceConfigloadServiceConfig(org.eclipse.rdf4j.model.IRI iri)voidqueryExportCSV(String queryString, OutputStream ostream)voidremove(org.eclipse.rdf4j.model.IRI subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.IRI obj, org.eclipse.rdf4j.model.IRI context)Removes a quadruple from the storage.voidremoveStatements(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, org.eclipse.rdf4j.model.Resource... contexts)voidremoveValue(org.eclipse.rdf4j.model.IRI subj, org.eclipse.rdf4j.model.IRI pred, Object value, org.eclipse.rdf4j.model.IRI context)Removes a quadruple from the storage.
-
-
-
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
-
getResourcesOfType
public Collection<org.eclipse.rdf4j.model.Resource> getResourcesOfType(org.eclipse.rdf4j.model.IRI type)
Finds IRIs of resources of the given type.- Parameters:
type- The resource type IRI.- Returns:
- a collection of Resources
-
getResourcesOfType
public Collection<org.eclipse.rdf4j.model.Resource> getResourcesOfType(org.eclipse.rdf4j.model.IRI type, org.eclipse.rdf4j.model.Resource context)
Finds IRIs of resources of the given type.- Parameters:
type- The resource type IRI.context- Repository context- Returns:
- a collection of Resources
-
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 in a default isolation level.- Parameters:
query- the SPARQL query- Returns:
- a the resulting model
- Throws:
StorageException
-
executeSafeQuery
public org.eclipse.rdf4j.model.Model executeSafeQuery(String query, org.eclipse.rdf4j.common.transaction.IsolationLevel isolationLevel) throws StorageException
Executes an internal (safe) SPARQL graph query in a given transaction isolation level.- Parameters:
query- the SPARQL queryisolationLevel- the transaction isolation level ornullwhen no transaction is required.- 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
-
executeSparqlTupleQuery
public List<org.eclipse.rdf4j.query.BindingSet> executeSparqlTupleQuery(String queryString, boolean distinct, long limit, long offset) throws StorageException
Checks and executes extrenal (possibly unsafe) SPARQL SELECT query and returns a result. This is a special version ofexecuteSparqlQuery(String, boolean, long, long)optimized for SELECT queries.- Parameters:
queryString- the SPARQL SELECT querydistinct-truewhen only distinct results should be returnedlimit- maximal number of returned resultsoffset- index of the first result to be returned- Returns:
- a query result that holds the result type and data
- Throws:
StorageException- when the query could not be parsed or executed or is not a SELECT query.
-
executeSparqlQuery
public SparqlQueryResult executeSparqlQuery(String queryString, boolean distinct, long limit, long offset) throws StorageException
Checks and executes extrenal (possibly unsafe) SPARQL query and returns a result depending on the query type.- Parameters:
queryString- the SPARQL querydistinct-truewhen only distinct results should be returnedlimit- maximal number of returned resultsoffset- index of the first result to be returned- Returns:
- a query result that holds the result type and data
- Throws:
StorageException- when the query could not be parsed or executed
-
execSparqlUpdate
public void execSparqlUpdate(String query) throws StorageException
- Throws:
StorageException
-
queryExportCSV
public void queryExportCSV(String queryString, OutputStream ostream) throws StorageException
- 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
-
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
-
importStream
public void importStream(InputStream stream, org.eclipse.rdf4j.rio.RDFFormat dataFormat) throws StorageException
- Throws:
StorageException
-
importStream
public void importStream(InputStream stream, org.eclipse.rdf4j.rio.RDFFormat dataFormat, String baseURI) throws StorageException
- Throws:
StorageException
-
importStream
public void importStream(InputStream stream, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.IRI context) throws StorageException
- Throws:
StorageException
-
importStream
public void importStream(InputStream stream, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.IRI context, String baseURI) throws StorageException
- 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 context from the RDF repository.- Parameters:
context- Context IRI- Throws:
StorageException
-
removeStatements
public void removeStatements(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, org.eclipse.rdf4j.model.Resource... contexts)
-
remove
public void remove(org.eclipse.rdf4j.model.IRI subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.IRI obj, org.eclipse.rdf4j.model.IRI context)Removes a quadruple from the storage.- Parameters:
subj-pred-obj-context-
-
removeValue
public void removeValue(org.eclipse.rdf4j.model.IRI subj, org.eclipse.rdf4j.model.IRI pred, Object value, org.eclipse.rdf4j.model.IRI context)Removes a quadruple from the storage.- Parameters:
subj-pred-value-context-
-
loadServiceConfig
public ServiceConfig loadServiceConfig(org.eclipse.rdf4j.model.IRI iri) throws StorageException
- Throws:
StorageException
-
getLiteralAsObject
public static Object getLiteralAsObject(org.eclipse.rdf4j.model.Literal lval)
-
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()
-
getContexts
public List<org.eclipse.rdf4j.model.Resource> getContexts()
-
-