Last active
March 19, 2020 13:17
-
-
Save bachmanm/6264708 to your computer and use it in GitHub Desktop.
An example of a Neo4j transaction event handler (for a blog post)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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