Class SPARQLConnection
- java.lang.Object
-
- org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection
-
- org.eclipse.rdf4j.repository.sparql.SPARQLConnection
-
- All Implemented Interfaces:
AutoCloseable,HttpClientDependent,RepositoryConnection
public class SPARQLConnection extends AbstractRepositoryConnection implements HttpClientDependent
Provides aRepositoryConnectioninterface to any SPARQL endpoint.- Author:
- James Leigh
-
-
Field Summary
-
Fields inherited from class org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection
logger
-
-
Constructor Summary
Constructors Constructor Description SPARQLConnection(SPARQLRepository repository, SPARQLProtocolSession client)SPARQLConnection(SPARQLRepository repository, SPARQLProtocolSession client, boolean quadMode)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(File file, String baseURI, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.Resource... contexts)voidadd(InputStream in, String baseURI, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.Resource... contexts)voidadd(Reader reader, String baseURI, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.Resource... contexts)voidadd(Iterable<? extends org.eclipse.rdf4j.model.Statement> statements, org.eclipse.rdf4j.model.Resource... contexts)voidadd(URL url, String baseURI, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.Resource... contexts)voidadd(org.eclipse.rdf4j.model.Statement st, org.eclipse.rdf4j.model.Resource... contexts)protected voidaddWithoutCommit(org.eclipse.rdf4j.model.Resource subject, org.eclipse.rdf4j.model.IRI predicate, org.eclipse.rdf4j.model.Value object, org.eclipse.rdf4j.model.Resource... contexts)protected voidaddWithoutCommit(org.eclipse.rdf4j.model.Statement st, org.eclipse.rdf4j.model.Resource... contexts)voidbegin()voidclear(org.eclipse.rdf4j.model.Resource... contexts)voidclearNamespaces()voidclose()voidcommit()voidenableSilentMode(boolean flag)Deprecated.since 3.6.0 - usesetSilentClear(boolean)instead.voidexportStatements(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, boolean includeInferred, org.eclipse.rdf4j.rio.RDFHandler handler, org.eclipse.rdf4j.model.Resource... contexts)RepositoryResult<org.eclipse.rdf4j.model.Resource>getContextIDs()org.apache.http.client.HttpClientgetHttpClient()StringgetNamespace(String prefix)RepositoryResult<org.eclipse.rdf4j.model.Namespace>getNamespaces()SPARQLRepositorygetRepository()RepositoryResult<org.eclipse.rdf4j.model.Statement>getStatements(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, boolean includeInferred, org.eclipse.rdf4j.model.Resource... contexts)booleanhasStatement(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, boolean includeInferred, org.eclipse.rdf4j.model.Resource... contexts)booleanisActive()booleanisEmpty()protected booleanisQuadMode()Shall graph information also be retrieved, e.g.protected booleanisSilentClear()voidprepare()org.eclipse.rdf4j.query.BooleanQueryprepareBooleanQuery(org.eclipse.rdf4j.query.QueryLanguage ql, String query, String base)org.eclipse.rdf4j.query.GraphQueryprepareGraphQuery(org.eclipse.rdf4j.query.QueryLanguage ql, String query, String base)org.eclipse.rdf4j.query.QueryprepareQuery(org.eclipse.rdf4j.query.QueryLanguage ql, String query, String base)org.eclipse.rdf4j.query.TupleQueryprepareTupleQuery(org.eclipse.rdf4j.query.QueryLanguage ql, String query, String base)org.eclipse.rdf4j.query.UpdateprepareUpdate(org.eclipse.rdf4j.query.QueryLanguage ql, String update, String baseURI)voidremove(Iterable<? extends org.eclipse.rdf4j.model.Statement> statements, org.eclipse.rdf4j.model.Resource... contexts)voidremove(org.eclipse.rdf4j.model.Statement st, org.eclipse.rdf4j.model.Resource... contexts)voidremoveNamespace(String prefix)protected voidremoveWithoutCommit(org.eclipse.rdf4j.model.Resource subject, org.eclipse.rdf4j.model.IRI predicate, org.eclipse.rdf4j.model.Value object, org.eclipse.rdf4j.model.Resource... contexts)protected voidremoveWithoutCommit(org.eclipse.rdf4j.model.Statement st, org.eclipse.rdf4j.model.Resource... contexts)voidrollback()voidsetHttpClient(org.apache.http.client.HttpClient httpClient)voidsetNamespace(String prefix, String name)voidsetParserConfig(org.eclipse.rdf4j.rio.ParserConfig parserConfig)voidsetSilentClear(boolean silent)Configure the connection to executeclear(Resource...)operations silently: the remote endpoint will not respond with an error if the supplied named graph does not exist on the endpoint.longsize(org.eclipse.rdf4j.model.Resource... contexts)protected org.eclipse.rdf4j.common.iteration.Iteration<org.eclipse.rdf4j.model.Statement,org.eclipse.rdf4j.query.QueryEvaluationException>toStatementIteration(org.eclipse.rdf4j.query.TupleQueryResult iter, org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj)Converts aTupleQueryResultresulting from theEVERYTHING_WITH_GRAPHto a statement by using the respective values from theBindingSetor (if provided) the ones from the arguments.StringtoString()-
Methods inherited from class org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection
add, add, begin, conditionalCommit, conditionalRollback, export, getIsolationLevel, getParserConfig, getValueFactory, hasStatement, isAutoCommit, isOpen, prepareBooleanQuery, prepareGraphQuery, prepareQuery, prepareTupleQuery, prepareUpdate, remove, remove, setAutoCommit, setIsolationLevel, startLocalTransaction
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.rdf4j.repository.RepositoryConnection
add, add, add, add, add, add, add, begin, getStatements, prepareBooleanQuery, prepareGraphQuery, prepareQuery, prepareTupleQuery, prepareUpdate, remove
-
-
-
-
Constructor Detail
-
SPARQLConnection
public SPARQLConnection(SPARQLRepository repository, SPARQLProtocolSession client)
-
SPARQLConnection
public SPARQLConnection(SPARQLRepository repository, SPARQLProtocolSession client, boolean quadMode)
-
-
Method Detail
-
setSilentClear
public void setSilentClear(boolean silent)
Configure the connection to executeclear(Resource...)operations silently: the remote endpoint will not respond with an error if the supplied named graph does not exist on the endpoint.By default, the SPARQL connection executes the
clear(Resource...)API operation by converting it to a SPARQL `CLEAR GRAPH` update operation. This operation has an optionalSILENTmodifier, which can be enabled by setting this flag totrue. The behavior of this modifier is speficied as follows in the SPARQL 1.1 Recommendation:If the store records the existence of empty graphs, then the SPARQL 1.1 Update service, by default, SHOULD return failure if the specified graph does not exist. If SILENT is present, the result of the operation will always be success.
Note that in most SPARQL endpoint implementations not recording empty graphs is the default behavior, and setting this flag toStores that do not record empty graphs will always return success.
truewill have no effect. Setting this flag will have no effect on any other errors or other API or SPARQL operations: only the behavior of theclear(Resource...)API operation is modified to respond with a success message when removing a non-existent named graph.- Parameters:
silent- the value to set this to.
-
enableSilentMode
@Deprecated public void enableSilentMode(boolean flag)
Deprecated.since 3.6.0 - usesetSilentClear(boolean)instead.Configure the connection to executeclear(Resource...)operations silently: the remote endpoint will not respond with an error if the supplied named graph does not exist on the endpoint.By default, the SPARQL connection executes the
clear(Resource...)API operation by converting it to a SPARQL `CLEAR GRAPH` update operation. This operation has an optionalSILENTmodifier, which can be enabled by setting this flag totrue. The behavior of this modifier is speficied as follows in the SPARQL 1.1 Recommendation:If the store records the existence of empty graphs, then the SPARQL 1.1 Update service, by default, SHOULD return failure if the specified graph does not exist. If SILENT is present, the result of the operation will always be success.
Note that in most SPARQL endpoint implementations not recording empty graphs is the default behavior, and setting this flag toStores that do not record empty graphs will always return success.
truewill have no effect. Setting this flag will have no effect on any other errors or other API or SPARQL operations: only the behavior of theclear(Resource...)API operation is modified to respond with a success message when removing a non-existent named graph.- Parameters:
silent- the value to set this to.
-
setParserConfig
public void setParserConfig(org.eclipse.rdf4j.rio.ParserConfig parserConfig)
- Specified by:
setParserConfigin interfaceRepositoryConnection- Overrides:
setParserConfigin classAbstractRepositoryConnection
-
getHttpClient
public final org.apache.http.client.HttpClient getHttpClient()
- Specified by:
getHttpClientin interfaceHttpClientDependent
-
setHttpClient
public void setHttpClient(org.apache.http.client.HttpClient httpClient)
- Specified by:
setHttpClientin interfaceHttpClientDependent
-
close
public void close() throws RepositoryException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceRepositoryConnection- Overrides:
closein classAbstractRepositoryConnection- Throws:
RepositoryException
-
exportStatements
public void exportStatements(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, boolean includeInferred, org.eclipse.rdf4j.rio.RDFHandler handler, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException, org.eclipse.rdf4j.rio.RDFHandlerException- Specified by:
exportStatementsin interfaceRepositoryConnection- Throws:
RepositoryExceptionorg.eclipse.rdf4j.rio.RDFHandlerException
-
getContextIDs
public RepositoryResult<org.eclipse.rdf4j.model.Resource> getContextIDs() throws RepositoryException
- Specified by:
getContextIDsin interfaceRepositoryConnection- Throws:
RepositoryException
-
getNamespace
public String getNamespace(String prefix) throws RepositoryException
- Specified by:
getNamespacein interfaceRepositoryConnection- Throws:
RepositoryException
-
getNamespaces
public RepositoryResult<org.eclipse.rdf4j.model.Namespace> getNamespaces() throws RepositoryException
- Specified by:
getNamespacesin interfaceRepositoryConnection- Throws:
RepositoryException
-
isEmpty
public boolean isEmpty() throws RepositoryException- Specified by:
isEmptyin interfaceRepositoryConnection- Overrides:
isEmptyin classAbstractRepositoryConnection- Throws:
RepositoryException
-
size
public long size(org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException- Specified by:
sizein interfaceRepositoryConnection- Throws:
RepositoryException
-
getStatements
public RepositoryResult<org.eclipse.rdf4j.model.Statement> getStatements(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, boolean includeInferred, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException
- Specified by:
getStatementsin interfaceRepositoryConnection- Throws:
RepositoryException
-
hasStatement
public boolean hasStatement(org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj, boolean includeInferred, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException- Specified by:
hasStatementin interfaceRepositoryConnection- Overrides:
hasStatementin classAbstractRepositoryConnection- Throws:
RepositoryException
-
getRepository
public SPARQLRepository getRepository()
- Specified by:
getRepositoryin interfaceRepositoryConnection- Overrides:
getRepositoryin classAbstractRepositoryConnection
-
prepareQuery
public org.eclipse.rdf4j.query.Query prepareQuery(org.eclipse.rdf4j.query.QueryLanguage ql, String query, String base) throws RepositoryException, org.eclipse.rdf4j.query.MalformedQueryException- Specified by:
prepareQueryin interfaceRepositoryConnection- Throws:
RepositoryExceptionorg.eclipse.rdf4j.query.MalformedQueryException
-
prepareBooleanQuery
public org.eclipse.rdf4j.query.BooleanQuery prepareBooleanQuery(org.eclipse.rdf4j.query.QueryLanguage ql, String query, String base) throws RepositoryException, org.eclipse.rdf4j.query.MalformedQueryException- Specified by:
prepareBooleanQueryin interfaceRepositoryConnection- Throws:
RepositoryExceptionorg.eclipse.rdf4j.query.MalformedQueryException
-
prepareGraphQuery
public org.eclipse.rdf4j.query.GraphQuery prepareGraphQuery(org.eclipse.rdf4j.query.QueryLanguage ql, String query, String base) throws RepositoryException, org.eclipse.rdf4j.query.MalformedQueryException- Specified by:
prepareGraphQueryin interfaceRepositoryConnection- Throws:
RepositoryExceptionorg.eclipse.rdf4j.query.MalformedQueryException
-
prepareTupleQuery
public org.eclipse.rdf4j.query.TupleQuery prepareTupleQuery(org.eclipse.rdf4j.query.QueryLanguage ql, String query, String base) throws RepositoryException, org.eclipse.rdf4j.query.MalformedQueryException- Specified by:
prepareTupleQueryin interfaceRepositoryConnection- Throws:
RepositoryExceptionorg.eclipse.rdf4j.query.MalformedQueryException
-
prepare
public void prepare() throws RepositoryException- Specified by:
preparein interfaceRepositoryConnection- Throws:
RepositoryException
-
commit
public void commit() throws RepositoryException- Specified by:
commitin interfaceRepositoryConnection- Throws:
RepositoryException
-
rollback
public void rollback() throws RepositoryException- Specified by:
rollbackin interfaceRepositoryConnection- Throws:
RepositoryException
-
begin
public void begin() throws RepositoryException- Specified by:
beginin interfaceRepositoryConnection- Throws:
RepositoryException
-
add
public void add(File file, String baseURI, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.Resource... contexts) throws IOException, org.eclipse.rdf4j.rio.RDFParseException, RepositoryException
- Specified by:
addin interfaceRepositoryConnection- Overrides:
addin classAbstractRepositoryConnection- Throws:
IOExceptionorg.eclipse.rdf4j.rio.RDFParseExceptionRepositoryException
-
add
public void add(URL url, String baseURI, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.Resource... contexts) throws IOException, org.eclipse.rdf4j.rio.RDFParseException, RepositoryException
- Specified by:
addin interfaceRepositoryConnection- Overrides:
addin classAbstractRepositoryConnection- Throws:
IOExceptionorg.eclipse.rdf4j.rio.RDFParseExceptionRepositoryException
-
add
public void add(InputStream in, String baseURI, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.Resource... contexts) throws IOException, org.eclipse.rdf4j.rio.RDFParseException, RepositoryException
- Specified by:
addin interfaceRepositoryConnection- Overrides:
addin classAbstractRepositoryConnection- Throws:
IOExceptionorg.eclipse.rdf4j.rio.RDFParseExceptionRepositoryException
-
add
public void add(Reader reader, String baseURI, org.eclipse.rdf4j.rio.RDFFormat dataFormat, org.eclipse.rdf4j.model.Resource... contexts) throws IOException, org.eclipse.rdf4j.rio.RDFParseException, RepositoryException
- Specified by:
addin interfaceRepositoryConnection- Overrides:
addin classAbstractRepositoryConnection- Throws:
IOExceptionorg.eclipse.rdf4j.rio.RDFParseExceptionRepositoryException
-
add
public void add(org.eclipse.rdf4j.model.Statement st, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException- Specified by:
addin interfaceRepositoryConnection- Overrides:
addin classAbstractRepositoryConnection- Throws:
RepositoryException
-
add
public void add(Iterable<? extends org.eclipse.rdf4j.model.Statement> statements, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException
- Specified by:
addin interfaceRepositoryConnection- Overrides:
addin classAbstractRepositoryConnection- Throws:
RepositoryException
-
clear
public void clear(org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException- Specified by:
clearin interfaceRepositoryConnection- Overrides:
clearin classAbstractRepositoryConnection- Throws:
RepositoryException
-
clearNamespaces
public void clearNamespaces() throws RepositoryException- Specified by:
clearNamespacesin interfaceRepositoryConnection- Throws:
RepositoryException
-
remove
public void remove(org.eclipse.rdf4j.model.Statement st, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException- Specified by:
removein interfaceRepositoryConnection- Overrides:
removein classAbstractRepositoryConnection- Throws:
RepositoryException
-
remove
public void remove(Iterable<? extends org.eclipse.rdf4j.model.Statement> statements, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException
- Specified by:
removein interfaceRepositoryConnection- Overrides:
removein classAbstractRepositoryConnection- Throws:
RepositoryException
-
removeNamespace
public void removeNamespace(String prefix) throws RepositoryException
- Specified by:
removeNamespacein interfaceRepositoryConnection- Throws:
RepositoryException
-
setNamespace
public void setNamespace(String prefix, String name) throws RepositoryException
- Specified by:
setNamespacein interfaceRepositoryConnection- Throws:
RepositoryException
-
prepareUpdate
public org.eclipse.rdf4j.query.Update prepareUpdate(org.eclipse.rdf4j.query.QueryLanguage ql, String update, String baseURI) throws RepositoryException, org.eclipse.rdf4j.query.MalformedQueryException- Specified by:
prepareUpdatein interfaceRepositoryConnection- Throws:
RepositoryExceptionorg.eclipse.rdf4j.query.MalformedQueryException
-
isActive
public boolean isActive() throws UnknownTransactionStateException, RepositoryException- Specified by:
isActivein interfaceRepositoryConnection- Throws:
UnknownTransactionStateExceptionRepositoryException
-
addWithoutCommit
protected void addWithoutCommit(org.eclipse.rdf4j.model.Statement st, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException- Overrides:
addWithoutCommitin classAbstractRepositoryConnection- Throws:
RepositoryException
-
addWithoutCommit
protected void addWithoutCommit(org.eclipse.rdf4j.model.Resource subject, org.eclipse.rdf4j.model.IRI predicate, org.eclipse.rdf4j.model.Value object, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException- Specified by:
addWithoutCommitin classAbstractRepositoryConnection- Throws:
RepositoryException
-
removeWithoutCommit
protected void removeWithoutCommit(org.eclipse.rdf4j.model.Statement st, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException- Overrides:
removeWithoutCommitin classAbstractRepositoryConnection- Throws:
RepositoryException
-
removeWithoutCommit
protected void removeWithoutCommit(org.eclipse.rdf4j.model.Resource subject, org.eclipse.rdf4j.model.IRI predicate, org.eclipse.rdf4j.model.Value object, org.eclipse.rdf4j.model.Resource... contexts) throws RepositoryException- Specified by:
removeWithoutCommitin classAbstractRepositoryConnection- Throws:
RepositoryException
-
isQuadMode
protected boolean isQuadMode()
Shall graph information also be retrieved, e.g. forgetStatements(Resource, IRI, Value, boolean, Resource...)- Returns:
- true if in quad mode
-
isSilentClear
protected boolean isSilentClear()
-
toStatementIteration
protected org.eclipse.rdf4j.common.iteration.Iteration<org.eclipse.rdf4j.model.Statement,org.eclipse.rdf4j.query.QueryEvaluationException> toStatementIteration(org.eclipse.rdf4j.query.TupleQueryResult iter, org.eclipse.rdf4j.model.Resource subj, org.eclipse.rdf4j.model.IRI pred, org.eclipse.rdf4j.model.Value obj)Converts aTupleQueryResultresulting from theEVERYTHING_WITH_GRAPHto a statement by using the respective values from theBindingSetor (if provided) the ones from the arguments.- Parameters:
iter- theTupleQueryResultsubj- the subjectResourceused as input ornullif wildcard was usedpred- the predicateIRIused as input ornullif wildcard was usedobj- the objectValueused as input ornullif wildcard was used- Returns:
- the converted iteration
-
-