3

Thanks to ModelChangedListener, I can monitor changes in a Model as explained in Jena documentation (Event handling in Jena).

Model m = ModelFactory.createDefaultModel(); 
ModelChangedListener L = new MyListener();
m.register(L);

However, in my project, I want to monitor a Dataset for changes to run a code after something occurred in the default graph or one of the named graphes of the Dataset.

What I want to do is simply triggering events after executing such a query against a Dataset:

PREFIX d: <http://learningsparql.com/ns/data#>
PREFIX dm: <http://learningsparql.com/ns/demo#>
INSERT DATA
{
    d:x dm:tag "one" .
    d:x dm:tag "two" .
    GRAPH d:g1
    {
        d:x dm:tag "three" .
        d:x dm:tag "four" .
    }
}

to detect that "one" "two" were added to the default graph, and "three" "four" where added to g1.

With this code, I can't even detect changes happening in the default graph of the Dataset, let alone detecting changes in named graphs.

Dataset ds = RDFDataMgr.loadDataset(ONTOLOGY_PATH);
Model defaultModel = ds.getDefaultModel();
ModelChangedListener modelChangedListener = new MyListener();
defaultModel.register(modelChangedListener);
infomehdi
  • 53
  • 3

1 Answers1

3

Take a look at DatasetGraphMonitor which takes a DatasetChanges for processing changes.

Listening to models is unreliable if it works at all because the changes may be going straight to the dataset. A DatasetFactory.createGeneral data should work for models added by the application but in your example d:g1 may not. You would have to add a way to create the model. The engine for this is DatasetGraphMapLink.

But DatasetGraphMonitor / DatasetChanges is easier.

An alternative is RDF Delta, and DatasetGraphChanges where the changes are delivered with transaction boundaries.

AndyS
  • 14,989
  • 15
  • 20