Interface TransactionManager
Model verification and fixing must be implemented outside, and hooks must be passed to transaction.
Transaction can be read only - during such transaction no model modifications are allowed and any of model modification throws ReadOnlyModelException
Transaction managers offers three ways to attach the listeners.
1. Synchronize model changes - see addTransactionCommitListenerForExecute(TransactionCommitListener)
2. "Pseudo" synchronize model changes - see addTransactionCommitListener(TransactionCommitListener)
3. Regular transaction commit - see addTransactionCommitListenerIncludingUndoAndRedo(TransactionCommitListener)
.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Transaction options. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds transaction commit listener which will be invoked if event delivery is turned off.void
Adds transaction commit listener which will be invoked on first command execution or on direct transaction execution (not called on command/session undo/redo).void
Adds transaction commit listener which will be invoked only on the first command/session execution (not called on command/session undo/redo nor direct transaction execution).void
Adds transaction commit listener which will be invoked on command/session execution/undo/redo or direct transaction execution.void
commit()
Commits transaction.void
Commits transaction during execute operation.void
Commits transaction during undo or redo operation.void
Runs given code in new transaction by callingcommitExecute()
If transaction is not yet started, then starts a new, runs the code, and commits the transaction.Get validation hook which validates model integrity.boolean
void
Removes listener from transaction commit listeners.void
Runs given code in a transaction.void
Runs given code in new transaction by callingcommit()
void
Runs given code in new transaction by callingcommit()
void
Sets handler which fixes model with verification errors.void
setModelValidator
(ModelValidator validator) Sets validation hook which validates model integrity.void
start()
Starts transaction.void
Starts with given options.
-
Method Details
-
runTransaction
void runTransaction(Runnable r, TransactionManager.TransactionOptions options) throws RollbackException, TransactionAlreadyStartedException Runs given code in new transaction by callingcommit()
- Parameters:
r
- code to run.options
- transaction options to run- Throws:
RollbackException
- when model verification fails, andInvalidModelHandler
TransactionAlreadyStartedException
- when transaction already running
-
runTransaction
Runs given code in new transaction by callingcommit()
- Parameters:
r
- code to run- Throws:
RollbackException
- when model verification fails, andInvalidModelHandler
TransactionAlreadyStartedException
- If currently transaction is running
-
executeInTransaction
void executeInTransaction(Runnable r, TransactionManager.TransactionOptions options) throws RollbackException Runs given code in new transaction by callingcommitExecute()
If transaction is not yet started, then starts a new, runs the code, and commits the transaction. If transaction is already started then simply runs the code.- Parameters:
r
- code to run.options
- transaction options to run- Throws:
RollbackException
- when model verification fails, andInvalidModelHandler
-
runInTransaction
void runInTransaction(Runnable r, TransactionManager.TransactionOptions options) throws RollbackException Runs given code in a transaction. If transaction is not yet started, then starts a new, runs the code, and commits the transaction. If transaction is already started then simply runs the code.- Parameters:
r
- code to run.options
- transaction options to run- Throws:
RollbackException
- when model verification fails, andInvalidModelHandler
-
start
Starts transaction. Any model modification after transaction is started is recorded.- Throws:
TransactionAlreadyStartedException
- when there is running transaction
-
isStarted
boolean isStarted()- Returns:
- true if transaction is started
-
commit
Commits transaction. During commit, model is verified and in case verification failed model is fixed. If the only one fix is to rollback model to previous state which was before transactionRollbackException
is thrown- Throws:
RollbackException
- when transaction validation fails, and there is no way to fix model except undoing last actionTransactionAlreadyCommitedException
- when transaction is not started
-
commitUndoOrRedo
Commits transaction during undo or redo operation.- Throws:
RollbackException
TransactionAlreadyCommitedException
- See Also:
-
commitExecute
Commits transaction during execute operation.- Throws:
RollbackException
TransactionAlreadyCommitedException
- See Also:
-
start
Starts with given options. If transaction is read only any model modification after transaction is started throwsReadOnlyModelException
If transaction
Read only transactions are deprecated - normally queries on model can be done without transaction, and all modifications must be done through transaction.
- Parameters:
options
- transaction options- Throws:
TransactionAlreadyStartedException
- if transaction is already started
-
setInvalidModelHandler
Sets handler which fixes model with verification errors.- Parameters:
handler
- handler which fixes model
-
setModelValidator
Sets validation hook which validates model integrity.- Parameters:
validator
- which validates model integrity
-
getModelValidator
ModelValidator getModelValidator()Get validation hook which validates model integrity.- Returns:
- validator which validates model integrity
-
addTransactionCommitListener
Adds transaction commit listener which will be invoked on first command execution or on direct transaction execution (not called on command/session undo/redo).- Parameters:
listener
- listener to add
-
addTransactionCommitListenerIncludingUndoAndRedo
Adds transaction commit listener which will be invoked on command/session execution/undo/redo or direct transaction execution.- Parameters:
listener
- listener
-
addTransactionCommitListenerForExecute
Adds transaction commit listener which will be invoked only on the first command/session execution (not called on command/session undo/redo nor direct transaction execution).- Parameters:
listener
- listener
-
addNotDeliveredEventsListener
Adds transaction commit listener which will be invoked if event delivery is turned off. Usual transaction listeners will be not notified about such events.- Parameters:
listener
- which is notified for events happened only when event delivery was turned off. Notification is done on event delivery restore.
-
removeTransactionCommitListener
Removes listener from transaction commit listeners.- Parameters:
listener
- listener to remove
-
getListeners
Collection<TransactionCommitListener> getListeners()- Returns:
- all registered transaction commit listeners.
-