Interface TransactionManager
-
public interface TransactionManager
Transaction provides framework to keep consistent model after model modification. All model modifications during transaction is recorded and later these modifications are verified to check if they do not break model integrity.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 - seeaddTransactionCommitListenerForExecute(TransactionCommitListener)
2. "Pseudo" synchronize model changes - seeaddTransactionCommitListener(TransactionCommitListener)
3. Regular transaction commit - seeaddTransactionCommitListenerIncludingUndoAndRedo(TransactionCommitListener)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
TransactionManager.TransactionOptions
Transaction options.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addNotDeliveredEventsListener(TransactionCommitListener listener)
Adds transaction commit listener which will be invoked if event delivery is turned off.void
addTransactionCommitListener(TransactionCommitListener listener)
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
addTransactionCommitListenerForExecute(TransactionCommitListener listener)
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
addTransactionCommitListenerIncludingUndoAndRedo(TransactionCommitListener listener)
Adds transaction commit listener which will be invoked on command/session execution/undo/redo or direct transaction execution.void
commit()
Commits transaction.void
commitExecute()
Commits transaction during execute operation.void
commitUndoOrRedo()
Commits transaction during undo or redo operation.void
executeInTransaction(java.lang.Runnable r, TransactionManager.TransactionOptions options)
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.java.util.Collection<TransactionCommitListener>
getListeners()
ModelValidator
getModelValidator()
Get validation hook which validates model integrity.boolean
isStarted()
void
removeTransactionCommitListener(TransactionCommitListener listener)
Removes listener from transaction commit listeners.void
runInTransaction(java.lang.Runnable r, TransactionManager.TransactionOptions options)
Runs given code in a transaction.void
runTransaction(java.lang.Runnable r)
Runs given code in new transaction by callingcommit()
void
runTransaction(java.lang.Runnable r, TransactionManager.TransactionOptions options)
Runs given code in new transaction by callingcommit()
void
setInvalidModelHandler(InvalidModelHandler handler)
Sets handler which fixes model with verification errors.void
setModelValidator(ModelValidator validator)
Sets validation hook which validates model integrity.void
start()
Starts transaction.void
start(TransactionManager.TransactionOptions options)
Starts with given options.
-
-
-
Method Detail
-
runTransaction
void runTransaction(java.lang.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
void runTransaction(java.lang.Runnable r) throws RollbackException, TransactionAlreadyStartedException
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(java.lang.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(java.lang.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
void start() throws TransactionAlreadyStartedException
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
void commit() throws RollbackException, TransactionAlreadyCommitedException
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
void commitUndoOrRedo() throws RollbackException, TransactionAlreadyCommitedException
Commits transaction during undo or redo operation.- Throws:
RollbackException
TransactionAlreadyCommitedException
- See Also:
commit()
-
commitExecute
void commitExecute() throws RollbackException, TransactionAlreadyCommitedException
Commits transaction during execute operation.- Throws:
RollbackException
TransactionAlreadyCommitedException
- See Also:
commit()
-
start
void start(TransactionManager.TransactionOptions options) throws TransactionAlreadyStartedException
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
void setInvalidModelHandler(InvalidModelHandler handler)
Sets handler which fixes model with verification errors.- Parameters:
handler
- handler which fixes model
-
setModelValidator
void setModelValidator(ModelValidator validator)
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
void addTransactionCommitListener(TransactionCommitListener listener)
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
void addTransactionCommitListenerIncludingUndoAndRedo(TransactionCommitListener listener)
Adds transaction commit listener which will be invoked on command/session execution/undo/redo or direct transaction execution.- Parameters:
listener
- listener
-
addTransactionCommitListenerForExecute
void addTransactionCommitListenerForExecute(TransactionCommitListener listener)
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
void addNotDeliveredEventsListener(TransactionCommitListener listener)
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
void removeTransactionCommitListener(TransactionCommitListener listener)
Removes listener from transaction commit listeners.- Parameters:
listener
- listener to remove
-
getListeners
java.util.Collection<TransactionCommitListener> getListeners()
- Returns:
- all registered transaction commit listeners.
-
-