Interface TransactionEventListener<T>
- Type Parameters:
T
- The type of a state object that the transaction handler can use to pass information from thebeforeCommit(TransactionData, Transaction, GraphDatabaseService)
event dispatch method to theafterCommit(TransactionData, Object, GraphDatabaseService)
orafterRollback(TransactionData, Object, GraphDatabaseService)
method, depending on whether the transaction succeeded or failed.
DatabaseManagementService
instance it will receive events
about what has happened in each transaction which is about to be committed
and has any data that is accessible via TransactionData
.
Handlers won't get notified about transactions which haven't performed any
write operation or won't be committed (either if
Transaction.commit()
hasn't been called or the transaction has been
rolled back, Transaction.rollback()
).
Right before a transaction is about to be committed the
beforeCommit(TransactionData, Transaction, GraphDatabaseService)
method is called with the entire diff
of modifications made in the transaction. At this point the transaction is
still running so changes can still be made. However, there's no guarantee that
other handlers will see such changes since the order in which handlers are
executed is undefined. This method can also throw an exception and will, in
such a case, prevent the transaction from being committed.
If beforeCommit(TransactionData, Transaction, GraphDatabaseService)
is successfully executed the
transaction will be committed and the
afterCommit(TransactionData, Object, GraphDatabaseService)
method will be called with the
same transaction data as well as the object returned from
beforeCommit(TransactionData, Transaction, GraphDatabaseService)
. This assumes that all other handlers
(if more were registered) also executed
beforeCommit(TransactionData, Transaction, GraphDatabaseService)
successfully.
If beforeCommit(TransactionData, Transaction, GraphDatabaseService)
isn't executed successfully, but
instead throws an exception the transaction won't be committed. Transient errors of type TransientFailureException
will (eventually) be rethrown.
For all other errors a TransactionFailureException
will (eventually) be thrown from
Transaction.close()
. All handlers which at this point have had its
beforeCommit(TransactionData, Transaction, GraphDatabaseService)
method executed successfully will
receive a call to afterRollback(TransactionData, Object, GraphDatabaseService)
.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterCommit
(TransactionData data, T state, GraphDatabaseService databaseService) Invoked after the transaction has been committed successfully.void
afterRollback
(TransactionData data, T state, GraphDatabaseService databaseService) Invoked after the transaction has been rolled back if committing the transaction failed for some reason.beforeCommit
(TransactionData data, Transaction transaction, GraphDatabaseService databaseService) Invoked when a transaction that has changes accessible viaTransactionData
is about to be committed.
-
Method Details
-
beforeCommit
T beforeCommit(TransactionData data, Transaction transaction, GraphDatabaseService databaseService) throws Exception Invoked when a transaction that has changes accessible viaTransactionData
is about to be committed. If this method throws an exception the transaction will be rolled back and aTransactionFailureException
or aTransientFailureException
will be thrown fromTransaction.close()
. The transaction is still open when this method is invoked, making it possible to perform mutating operations in this method. This is however highly discouraged since changes made in this method are not guaranteed to be visible by this or otherTransactionEventListener
s.- Parameters:
data
- the changes that will be committed in this transaction.transaction
- ongoing transactiondatabaseService
- underlying database service- Returns:
- a state object (or
null
) that will be passed on toafterCommit(TransactionData, Object, GraphDatabaseService)
orafterRollback(TransactionData, Object, GraphDatabaseService)
of this object. - Throws:
Exception
- to indicate that the transaction should be rolled back.
-
afterCommit
Invoked after the transaction has been committed successfully. AnyTransactionData
being passed in to this method is guaranteed to first have been called withbeforeCommit(TransactionData, Transaction, GraphDatabaseService)
. At the point of calling this method the transaction have been closed and so accessing data outside that of what theTransactionData
can provide will require a new transaction to be opened.- Parameters:
data
- the changes that were committed in this transaction.state
- the object returned bybeforeCommit(TransactionData, Transaction, GraphDatabaseService)
.databaseService
- underlying database service
-
afterRollback
Invoked after the transaction has been rolled back if committing the transaction failed for some reason. AnyTransactionData
being passed in to this method is guaranteed to first have been called withbeforeCommit(TransactionData, Transaction, GraphDatabaseService)
. At the point of calling this method the transaction have been closed and so accessing data outside that of what theTransactionData
can provide will require a new transaction to be opened.- Parameters:
data
- the changes that were attempted to be committed in this transaction.state
- the object returned bybeforeCommit(TransactionData, Transaction, GraphDatabaseService)
. If this handler failed when executingbeforeCommit(TransactionData, Transaction, GraphDatabaseService)
thisstate
will benull
.databaseService
- underlying database service
-