7.9 SPARQL Update Support
RDF Graph support for Apache Jena supports SPARQL Update
(http://www.w3.org/TR/sparql11-update/
), also referred to as SPARUL.
The primary programming APIs involve the Jena class
org.apache.jena.update.UpdateAction
and RDF Graph support for Apache Jena
classes GraphOracleSem
and DatasetGraphOracleSem
. Example 7-4 shows a SPARQL Update operation removes all triples in named graph
<http://example/graph>
from the relevant RDF graph stored in the
database.
Example 7-4 Simple SPARQL Update
GraphOracleSem graphOracleSem = .... ; DatasetGraphOracleSem dsgos = DatasetGraphOracleSem.createFrom(graphOracleSem); // SPARQL Update operation String szUpdateAction = "DROP GRAPH <http://example/graph>"; // Execute the Update against a DatasetGraph instance (can be a Jena Model as well) UpdateAction.parseExecute(szUpdateAction, dsgos);
Note that Oracle Database does not keep any information about an empty named graph. This implies if you invoke CREATE GRAPH <graph_name> without adding any triples into this graph, then no additional rows in the application table or the underlying RDF_LINK$ table will be created. To an Oracle database, you can safely skip the CREATE GRAPH step, as is the case in Example 7-4.
Example 7-5 SPARQL Update with Insert and Delete Operations
Example 7-5 shows a SPARQL Update operation (from ARQ 2.8.8) involving multiple insert and delete operations.
PREFIX : <http://example/> CREATE GRAPH <http://example/graph> ; INSERT DATA { :r :p 123 } ; INSERT DATA { :r :p 1066 } ; DELETE DATA { :r :p 1066 } ; INSERT DATA { GRAPH <http://example/graph> { :r :p 123 . :r :p 1066 } } ; DELETE DATA { GRAPH <http://example/graph> { :r :p 123 } }
After running the update operation in Example 7-5 against an empty DatasetGraphOracleSem
, running the SPARQL query SELECT ?s ?p ?o WHERE {?s ?p ?o}
generates the following response:
----------------------------------------------------------------------------------------------- | s | p | o | =============================================================================================== | <http://example/r> | <http://example/p> | "123"^^<http://www.w3.org/2001/XMLSchema#decimal> | -----------------------------------------------------------------------------------------------
Using the same data, running the SPARQL query SELECT ?g ?s ?p ?o where {GRAPH ?g {?s ?p ?o}}
generates the following response:
------------------------------------------------------------------------------------------------------------------------- | g | s | p | o | ========================================================================================================================= | <http://example/graph> | <http://example/r> | <http://example/p> | "1066"^^<http://www.w3.org/2001/XMLSchema#decimal> | -------------------------------------------------------------------------------------------------------------------------
Parent topic: RDF Graph Support for Apache Jena