Get Inserted/Deleted statements on an Update Query #3163
-
Is there a way that I could retrieve the statements that were modified in an update query? Basically I want to be able to do a "dry-run" of an update query (i.e., start a transaction, run an update, find the changed statements, rollback the transaction). Is something like this even possible? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
You can do something along those lines with a Repository rep = new SailRepository(new MemoryStore());
try (SailRepositoryConnection conn = (SailRepositoryConnection) rep.getConnection()) {
NotifyingSailConnection sailConn = (NotifyingSailConnection) conn.getSailConnection();
sailConn.addConnectionListener(new SailConnectionListener() {
@Override
public void statementRemoved(Statement removed) {
System.out.println("removed: " + removed);
}
@Override
public void statementAdded(Statement added) {
System.out.println("added: " + added);
}
});
conn.begin();
conn.add(FOAF.PERSON, RDF.TYPE, RDFS.CLASS);
String update = "DELETE { ?p a rdfs:Class } INSERT { ?p rdfs:label \"Person\" } WHERE { ?p a rdfs:Class }";
conn.prepareUpdate(update).execute();
System.out.println("executed");
conn.commit();
System.out.println("transaction committed");
} As you can see we need to cast the
|
Beta Was this translation helpful? Give feedback.
-
Would it be possible to do this for an HTTPRepository as well? I'm trying to get notifications on updates that take place on an external RDF4J server. I'm trying to implement this using NotifyingRepositoryWrapper with the addRepositoryListener method, but I haven't managed to get there yet. It seems that statementAdded and statementRemoved is not available for RepositoryListener, so if anyone could tell me if what I'm trying achieve is even possible, I would be very grateful. |
Beta Was this translation helpful? Give feedback.
You can do something along those lines with a
SailConnectionListener
. The way to access this is a little bit clunky though. Here's an example: