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 breaks 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. One way is only for synchronizing of model changes. Listener will not be called during undo/redo. Will be called only on first command execution in the command history.
2. Second way is for "pseudo" synchronizing. Will not be called only during undo/redo, but will be called even if command is not started. 3. Third way is regular transaction commit - called always on commit.
-
-
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)
Add listener which gets notifications for changes done when event delivery is turned off.void
addTransactionCommitListener(TransactionCommitListener listener)
Adds new listener to listen transaction commits (post commits) events.void
addTransactionCommitListenerForExecute(TransactionCommitListener listener)
Adds transaction commit listener which will not be invoked on command undo or redo.void
addTransactionCommitListenerIncludingUndoAndRedo(TransactionCommitListener listener)
Adds transaction commit listener which will be invoked during any transaction commitsvoid
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()
java.util.Collection<TransactionCommitListener>
getListenersForFiring()
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 new listener to listen transaction commits (post commits) events.- Parameters:
listener
- listener to add
-
addTransactionCommitListenerIncludingUndoAndRedo
void addTransactionCommitListenerIncludingUndoAndRedo(TransactionCommitListener listener)
Adds transaction commit listener which will be invoked during any transaction commits- Parameters:
listener
- listener
-
addTransactionCommitListenerForExecute
void addTransactionCommitListenerForExecute(TransactionCommitListener listener)
Adds transaction commit listener which will not be invoked on command undo or redo. And will not be invoked if transaction is committed not from editing session.- Parameters:
listener
- listener
-
addNotDeliveredEventsListener
void addNotDeliveredEventsListener(TransactionCommitListener listener)
Add listener which gets notifications for changes done when 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.
-
getListenersForFiring
java.util.Collection<TransactionCommitListener> getListenersForFiring()
- Returns:
- regisrered transaction commit listeners available for event firing in current manager state
-
-