Skip to content

Instantly share code, notes, and snippets.

@bachmanm
Last active March 19, 2020 13:17
Show Gist options
  • Save bachmanm/6264708 to your computer and use it in GitHub Desktop.
Save bachmanm/6264708 to your computer and use it in GitHub Desktop.
An example of a Neo4j transaction event handler (for a blog post)
@Test
public void showSimpleEventHandling() {
GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
database.registerTransactionEventHandler(new TransactionEventHandler<Void>() {
@Override
public Void beforeCommit(TransactionData data) throws Exception {
System.out.println("Committing transaction");
return null;
}
@Override
public void afterCommit(TransactionData data, Void state) {
System.out.println("Committed transaction");
}
@Override
public void afterRollback(TransactionData data, Void state) {
System.out.println("Transaction rolled back");
}
});
Transaction tx = database.beginTx();
try {
database.createNode();
tx.success();
} finally {
tx.finish();
}
/**
prints:
> Committing transaction
> Committed transaction
**/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment