Class RDFServiceSparql
- java.lang.Object
-
- edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceImpl
-
- edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql.RDFServiceSparql
-
- All Implemented Interfaces:
RDFService
- Direct Known Subclasses:
RDFServiceSparqlHttp,RDFServiceVirtuoso
public class RDFServiceSparql extends RDFServiceImpl implements RDFService
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService
RDFService.ModelSerializationFormat, RDFService.ResultFormat, RDFService.SPARQLQueryType
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.http.client.HttpClienthttpClientprotected StringreadEndpointURIprotected StringupdateEndpointURI-
Fields inherited from class edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceImpl
defaultWriteGraphURI, graphURIs, isRebuildGraphURICacheRunning, rebuildGraphURICache, registeredJenaListeners, registeredListeners
-
-
Constructor Summary
Constructors Constructor Description RDFServiceSparql(String endpointURI)Returns an RDFService for a remote repositoryRDFServiceSparql(String readEndpointURI, String updateEndpointURI)Returns an RDFService for a remote repositoryRDFServiceSparql(String readEndpointURI, String updateEndpointURI, String defaultWriteGraphURI)Returns an RDFService for a remote repository
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanchangeSetUpdate(ChangeSet changeSet)Perform a series of additions to and or removals from specified graphs in the RDF store.voidclose()Frees any resources held by this RDFService object The implementation of this method should be idempotent so that multiple invocations do not cause an error.protected voidexecuteUpdate(String updateString)protected org.apache.http.protocol.HttpContextgetContext(org.apache.http.client.methods.HttpRequestBase request)protected org.apache.http.auth.UsernamePasswordCredentialsgetCredentials()StringgetDefaultWriteGraphURI()Get the URI of the default write graphvoidgetGraphMetadata()To be determined.protected StringgetReadEndpointURI()protected StringgetUpdateEndpointURI()booleanisEquivalentGraph(String graphURI, InputStream serializedGraph, RDFService.ModelSerializationFormat serializationFormat)The basic version.booleanisEquivalentGraph(String graphURI, org.apache.jena.rdf.model.Model graph)The basic version.protected booleanisPreconditionSatisfied(String query, RDFService.SPARQLQueryType queryType)ChangeSetmanufactureChangeSet()Create a ChangeSet objectbooleanpreferPreciseOptionals()protected voidrebuildGraphUris()voidregisterListener(ChangeListener changeListener)Register a listener to listen to changes in any graph in the RDF store.voidserializeAll(OutputStream outputStream)Serializes the union of all named and unnamed graphs in the store to the supplied OutputStream, in N-Quads format.voidserializeGraph(String graphURI, OutputStream outputStream)Serializes the contents of the named graph to the supplied OutputStream, in N-Triples format.booleansparqlAskQuery(String queryStr)Performs a SPARQL ASK query against the knowledge base.InputStreamsparqlConstructQuery(String queryStr, RDFService.ModelSerializationFormat resultFormat)Performs a SPARQL construct query against the knowledge base.voidsparqlConstructQuery(String queryStr, org.apache.jena.rdf.model.Model model)Performs a SPARQL construct query against the knowledge base.InputStreamsparqlDescribeQuery(String queryStr, RDFService.ModelSerializationFormat resultFormat)Performs a SPARQL describe query against the knowledge base.InputStreamsparqlSelectQuery(String queryStr, RDFService.ResultFormat resultFormat)Performs a SPARQL select query against the knowledge base.voidsparqlSelectQuery(String queryStr, ResultSetConsumer consumer)Performs a SPARQL select query against the knowledge base.protected booleansparqlSelectQueryHasResults(String queryStr)protected voidtestConnection()voidunregisterListener(ChangeListener changeListener)Unregister a listener from listening to changes in any graph in the RDF store.-
Methods inherited from class edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceImpl
countTriples, createQuery, getGraphURIs, getRegisteredJenaModelChangedListeners, getRegisteredListeners, getSerializationFormatString, getTriples, getVitroRequest, newIndividual, newIndividual, notifyListeners, notifyListenersOfChanges, notifyListenersOfEvent, pyString, registerJenaModelChangedListener, separateStatementsWithBlankNodes, setVitroRequest, sparqlNode, sparqlNodeUpdate, sparqlTriple, toString, unregisterJenaModelChangedListener, updateGraphURIs
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService
countTriples, getGraphURIs, getTriples, getVitroRequest, newIndividual, newIndividual, registerJenaModelChangedListener, setVitroRequest, unregisterJenaModelChangedListener
-
-
-
-
Constructor Detail
-
RDFServiceSparql
public RDFServiceSparql(String readEndpointURI, String updateEndpointURI, String defaultWriteGraphURI)
Returns an RDFService for a remote repository- Parameters:
readEndpointURI- - URI of the read SPARQL endpoint for the knowledge baseupdateEndpointURI- - URI of the update SPARQL endpoint for the knowledge basedefaultWriteGraphURI- - URI of the default write graph within the knowledge base. this is the graph that will be written to when a graph is not explicitly specified. The default read graph is the union of all graphs in the knowledge base
-
RDFServiceSparql
public RDFServiceSparql(String readEndpointURI, String updateEndpointURI)
Returns an RDFService for a remote repository- Parameters:
readEndpointURI- - URI of the read SPARQL endpoint for the knowledge baseupdateEndpointURI- - URI of the update SPARQL endpoint for the knowledge base The default read graph is the union of all graphs in the knowledge base
-
RDFServiceSparql
public RDFServiceSparql(String endpointURI)
Returns an RDFService for a remote repository- Parameters:
endpointURI- - URI of the read and update SPARQL endpoint for the knowledge base The default read graph is the union of all graphs in the knowledge base
-
-
Method Detail
-
testConnection
protected void testConnection()
-
close
public void close()
Description copied from interface:RDFServiceFrees any resources held by this RDFService object The implementation of this method should be idempotent so that multiple invocations do not cause an error.- Specified by:
closein interfaceRDFService
-
changeSetUpdate
public boolean changeSetUpdate(ChangeSet changeSet) throws RDFServiceException
Perform a series of additions to and or removals from specified graphs in the RDF store. preConditionSparql will be executed against the union of all the graphs in the knowledge base before any updates are made. If the precondition query returns a non-empty result no updates will be made.- Specified by:
changeSetUpdatein interfaceRDFService- Parameters:
changeSet- - a set of changes to be performed on the RDF store.- Returns:
- boolean - indicates whether the precondition was satisfied
- Throws:
RDFServiceException
-
sparqlConstructQuery
public InputStream sparqlConstructQuery(String queryStr, RDFService.ModelSerializationFormat resultFormat) throws RDFServiceException
Performs a SPARQL construct query against the knowledge base. The query may have an embedded graph identifier.- Specified by:
sparqlConstructQueryin interfaceRDFService- Parameters:
queryStr- - the SPARQL query to be executed against the RDF storeresultFormat- - type of serialization for RDF result of the SPARQL query- Returns:
- InputStream - the result of the query
- Throws:
RDFServiceException
-
sparqlConstructQuery
public void sparqlConstructQuery(String queryStr, org.apache.jena.rdf.model.Model model) throws RDFServiceException
Description copied from interface:RDFServicePerforms a SPARQL construct query against the knowledge base. The query may have an embedded graph identifier. If the query does not contain a graph identifier the query is executed against the union of all named and unnamed graphs in the store.- Specified by:
sparqlConstructQueryin interfaceRDFService- Parameters:
queryStr- - the SPARQL query to be executed against the RDF storemodel- - the Model to add the statements to- Throws:
RDFServiceException
-
sparqlDescribeQuery
public InputStream sparqlDescribeQuery(String queryStr, RDFService.ModelSerializationFormat resultFormat) throws RDFServiceException
Performs a SPARQL describe query against the knowledge base. The query may have an embedded graph identifier.- Specified by:
sparqlDescribeQueryin interfaceRDFService- Parameters:
queryStr- - the SPARQL query to be executed against the RDF storeresultFormat- - type of serialization for RDF result of the SPARQL query- Returns:
- InputStream - the result of the query
- Throws:
RDFServiceException
-
sparqlSelectQuery
public InputStream sparqlSelectQuery(String queryStr, RDFService.ResultFormat resultFormat) throws RDFServiceException
Performs a SPARQL select query against the knowledge base. The query may have an embedded graph identifier.- Specified by:
sparqlSelectQueryin interfaceRDFService- Parameters:
queryStr- - the SPARQL query to be executed against the RDF storeresultFormat- - format for the result of the Select query- Returns:
- InputStream - the result of the query
- Throws:
RDFServiceException
-
sparqlSelectQuery
public void sparqlSelectQuery(String queryStr, ResultSetConsumer consumer) throws RDFServiceException
Description copied from interface:RDFServicePerforms a SPARQL select query against the knowledge base. The query may have an embedded graph identifier. If the query does not contain a graph identifier the query is executed against the union of all named and unnamed graphs in the store.- Specified by:
sparqlSelectQueryin interfaceRDFService- Parameters:
queryStr- - the SPARQL query to be executed against the RDF storeconsumer- - the class to consume the results of the query- Throws:
RDFServiceException
-
sparqlAskQuery
public boolean sparqlAskQuery(String queryStr) throws RDFServiceException
Performs a SPARQL ASK query against the knowledge base. The query may have an embedded graph identifier.- Specified by:
sparqlAskQueryin interfaceRDFService- Parameters:
queryStr- - the SPARQL query to be executed against the RDF store- Returns:
- boolean - the result of the SPARQL query
- Throws:
RDFServiceException
-
rebuildGraphUris
protected void rebuildGraphUris()
- Specified by:
rebuildGraphUrisin classRDFServiceImpl
-
getGraphMetadata
public void getGraphMetadata() throws RDFServiceExceptionDescription copied from interface:RDFServiceTo be determined. This is a place holder and is not implemented in current implementations.- Specified by:
getGraphMetadatain interfaceRDFService- Throws:
RDFServiceException
-
getDefaultWriteGraphURI
public String getDefaultWriteGraphURI() throws RDFServiceException
Get the URI of the default write graph- Specified by:
getDefaultWriteGraphURIin interfaceRDFService- Overrides:
getDefaultWriteGraphURIin classRDFServiceImpl- Returns:
- String URI of default write graph
- Throws:
RDFServiceException
-
registerListener
public void registerListener(ChangeListener changeListener) throws RDFServiceException
Register a listener to listen to changes in any graph in the RDF store.- Specified by:
registerListenerin interfaceRDFService- Overrides:
registerListenerin classRDFServiceImpl- Parameters:
changeListener- - the change listener- Throws:
RDFServiceException
-
unregisterListener
public void unregisterListener(ChangeListener changeListener) throws RDFServiceException
Unregister a listener from listening to changes in any graph in the RDF store.- Specified by:
unregisterListenerin interfaceRDFService- Overrides:
unregisterListenerin classRDFServiceImpl- Parameters:
changeListener- - the change listener- Throws:
RDFServiceException
-
manufactureChangeSet
public ChangeSet manufactureChangeSet()
Create a ChangeSet object- Specified by:
manufactureChangeSetin interfaceRDFService- Overrides:
manufactureChangeSetin classRDFServiceImpl- Returns:
- a ChangeSet object
-
getReadEndpointURI
protected String getReadEndpointURI()
-
getUpdateEndpointURI
protected String getUpdateEndpointURI()
-
executeUpdate
protected void executeUpdate(String updateString) throws RDFServiceException
- Throws:
RDFServiceException
-
isPreconditionSatisfied
protected boolean isPreconditionSatisfied(String query, RDFService.SPARQLQueryType queryType) throws RDFServiceException
- Overrides:
isPreconditionSatisfiedin classRDFServiceImpl- Throws:
RDFServiceException
-
sparqlSelectQueryHasResults
protected boolean sparqlSelectQueryHasResults(String queryStr) throws RDFServiceException
- Overrides:
sparqlSelectQueryHasResultsin classRDFServiceImpl- Throws:
RDFServiceException
-
serializeAll
public void serializeAll(OutputStream outputStream) throws RDFServiceException
Description copied from interface:RDFServiceSerializes the union of all named and unnamed graphs in the store to the supplied OutputStream, in N-Quads format. This method is designed for exporting data from VIVO, so any filters should be bypassed. If possible, this should be done without buffering in memory, so arbitrarily large graphs can be exported.- Specified by:
serializeAllin interfaceRDFService- Parameters:
outputStream- - receives the serialized result.- Throws:
RDFServiceException
-
serializeGraph
public void serializeGraph(String graphURI, OutputStream outputStream) throws RDFServiceException
Description copied from interface:RDFServiceSerializes the contents of the named graph to the supplied OutputStream, in N-Triples format. This method is designed for exporting data from VIVO, so any filters should be bypassed. If possible, this should be done without buffering in memory, so arbitrarily large graphs can be exported.- Specified by:
serializeGraphin interfaceRDFService- Parameters:
graphURI- - the URI of the desired graph. May not be null.outputStream- - receives the serialized result.- Throws:
RDFServiceException
-
isEquivalentGraph
public boolean isEquivalentGraph(String graphURI, InputStream serializedGraph, RDFService.ModelSerializationFormat serializationFormat) throws RDFServiceException
The basic version. Parse the model from the file, read the model from the tripleStore, and ask whether they are isomorphic.- Specified by:
isEquivalentGraphin interfaceRDFService- Parameters:
graphURI- - the URI of the graph to test against. May not be null.serializedGraph- - the contents to be compared with the existing graph. May not be null.serializationFormat- - May not be null.- Throws:
RDFServiceException
-
isEquivalentGraph
public boolean isEquivalentGraph(String graphURI, org.apache.jena.rdf.model.Model graph) throws RDFServiceException
The basic version. Parse the model from the file, read the model from the tripleStore, and ask whether they are isomorphic.- Specified by:
isEquivalentGraphin interfaceRDFService- Parameters:
graphURI- - the URI of the graph to test against. May not be null.graph- - the contents to be compared with the existing graph. May not be null.- Throws:
RDFServiceException
-
preferPreciseOptionals
public boolean preferPreciseOptionals()
- Specified by:
preferPreciseOptionalsin interfaceRDFService
-
getContext
protected org.apache.http.protocol.HttpContext getContext(org.apache.http.client.methods.HttpRequestBase request)
-
getCredentials
protected org.apache.http.auth.UsernamePasswordCredentials getCredentials()
-
-