Database Reference
In-Depth Information
// do some work
// no need to return state
return null;
}
@Override
public void afterCommit(TransactionData data, Object state) {
// do some work
}
@Override
public void afterRollback(TransactionData data, Object state) {
// do some work
}
});
The TransactionData objects will inform you about the changed graph resources
withinthetransaction.Typicalusecasesforeventhandlersincludeauditingandintegration
with external systems. For example, you could publish an event to update a dashboard
every time a new user is added to the system.
Be extra careful with the code that you run from a transaction event handler, though, as it
will be running from the same thread as your transaction—slow-running code will have an
impact on the performance of your system. Also, an exception thrown from an event hand-
ler will cause the transaction to fail.
Transactions and Neo4j server
This chapter has focused on demonstrating the use of programmatic transaction handling
for an embedded Neo4j setup. Neo4j can also be run in server mode, where clients access
the Neo4j server via a well-established HTTP REST-based API, and chapter 10 provides
details about what's required to do this. It's important to understand the considerations and
the way in which transactions are handled when running in server mode in order to be able
to build robust, performant applications. This sidebar aims to highlight some of the key
points relating to transactions that you should look out for when running in server mode,
without going into explicit details. Please see section 10.4.3 for more information.
By default, every request made to the Neo4j server is done via a REST API call, and each
call will occur within its own transaction. But making a lot of fine-grained REST calls will
Search WWH ::




Custom Search