Get affected triples from SPARQL update query

Viewed 97

I have a SPARQL update query like following

DELETE { ?s <http://ex#> <http://ex#OLD> }
INSERT { ?s <http://ex#> <http://ex#NEW> }
WHERE { ?s <http://ex#> <http://ex#OLD> }

I want to run this query on my model. This will result in deleting some triples and addition of some other triples in the model. I am looking for a way to get these affected triples in Apache jena.

Till now I have made a ModelChangedListner (https://jena.apache.org/documentation/notes/event-handler-howto.html) to get these triples. Even though it is working fine but the problem is that I want the affected triples before they are committed to the dataset. But the model changed listener does not provide any such guarantee.

Edit: If there is no solution in current version of Jena, I am open to modify and recompile the Jena code if someone can point me to the location where this modification should be made.

1 Answers

See RDF Delta - specifically the DatasetGraphChanges - records changes to a dataset. It records the "add" and "delete" operations performed, recording the triples (quads) changed. Using a wrapper is more reliable and more general than ModelChangedListener because it captures the change operations on the basic storage (datasets).

Related