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: 1 comment 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.
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: