|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Transaction
Specifies transactions to be used with the transaction management service.
These are the transactions to be used by the application, each mapping to one
or more (in case of nested or distributed transactions)
DataSourceTransaction
s.
Transactions maintain two lists of GraphEntities and GraphEntityClasses
marked "dirty", indicating that there have been changes to these
since the last consistency check. These lists are typically filled by the
EventManager
(who because of practical
reasons also serves in this role), and cleared by the consistency checkers.
While it is preferable to realize those lists as a Set (in the
Set
sense) to reduce memory consumption and time for
consistency checking, and the documentation refers to them as sets, neither
the interface nor the specification forces you to do so.
Nested Class Summary | |
---|---|
static class |
Transaction.State
Specifies the different state transactions can be in. |
Method Summary | |
---|---|
void |
begin()
Starts the scope of a transaction |
void |
commit()
Commits the transaction. |
DataSourceTransaction |
getDataSourceTransaction(DataSourceURL dataSourceURL)
Returns the associated DataSourceTransaction for this Transaction (or one of them if this is a distributed transaction). |
java.util.Collection<GraphEntity> |
getDirtyGraphEntities()
Returns the set of GraphEntities that are currently marked "dirty". |
java.util.Collection<GraphEntityClass> |
getDirtyGraphEntityClasses()
Returns the set of GraphEntityClasses that are currently marked "dirty". |
java.util.Collection<? extends Transaction> |
getNestedTransactions()
Returns a Collection containing the nested transaction (if any). |
Transaction |
getParentTransaction()
Returns the parent transaction if this is a nested transaction, null otherwise. |
Transaction.State |
getState()
Get the current state of this transaction |
TransactionManager |
getTransactionManager()
Get the TransactionManager which manages this transaction. |
boolean |
isDirty()
Returns true if there is at least one GraphEntity or
GraphEntityClass in the "dirty" sets. |
void |
markGraphEntitiesDirty(java.util.Collection<GraphEntity> g)
Adds the Collection of GraphEntities to the "dirty" set. |
void |
markGraphEntityClassDirty(GraphEntityClass g)
Adds the specified GraphEntityClass to the "dirty" set. |
void |
markGraphEntityClassesDirty(java.util.Collection<GraphEntityClass> g)
Adds the Collection of GraphEntityClasses to the "dirty" set. |
void |
markGraphEntityDirty(GraphEntity g)
Adds the specified GraphEntity to the "dirty" set. |
void |
rollback()
Aborts the transaction, causing a rollback of all nested transactions. |
void |
setRollbackOnly()
Sets the only possible outcome of this transaction to rollback. |
void |
unmarkAllGraphEnitiesDirty(DataSourceURL logicalURL)
Removes all GraphEntity marked as dirty from the dirty set that
belong to a GraphPool identified by the (logical)
DataSourceURL . |
void |
unmarkAllGraphEnityClassesDirty(DataSourceURL logicalURL)
Removes all GraphEntityClass marked as dirty from the dirty set that
belong to a GraphPool identified by the (logical)
DataSourceURL . |
void |
unmarkGraphEntitiesDirty(java.util.Collection<GraphEntity> g)
Bulk version of unmarkGraphEntityDirty(GraphEntity) . |
void |
unmarkGraphEntityClassDirty(GraphEntityClass g)
Removes the specified GraphEntityClass from the "dirty" set of the top-level transcation and all its (grand^*)children (which obviously always includes the transaction this method was called on). |
void |
unmarkGraphEntityClassesDirty(java.util.Collection<GraphEntityClass> g)
Bulk version of unmarkGraphEntityClassDirty(GraphEntityClass) . |
void |
unmarkGraphEntityDirty(GraphEntity g)
Removes the specified GraphEntity from the "dirty" set of the top-level transcation and all its (grand^*)children (which obviously always includes the transaction this method was called on). |
Method Detail |
---|
void begin() throws TransactionException
TransactionException
- if the transaction could not be startedvoid rollback() throws TransactionException
It can be called on any transaction that is either the current
transaction or a (grand^n)parent of the current one. It can be called in
all states but Transaction.State.COMMITTED
.
If the transaction is already in state Transaction.State.ROLLED_BACK
, no
action is taken, otherwise this methods proceeds as follows:
BEFORE_ROLLBACK
TransactionEvent in the reverse order of their creation (youngest
transactions fire first) recursively.BEFORE_ROLLBACK
TransactionEvent for this
transaction.Transaction.State.ROLLED_BACK
recursively (order is not
specified).AFTER_ROLLBACK
TransactionEvent in the reverse order of their creation (youngest
transactions fire first) recursively.AFTER_ROLLBACK
TransactionEvent for this
transaction.
There are some important differences when compared to commit()
:
You can call this method on transactions other than the current one, and
only the transaction it is called on actually performs an action on the
data source! This avoids the restauration of temporary states that will
be discarded anyway, which is not necessary for the checkpoint/savepoint
nested transaction implementation commonly found in databases. Of course,
nothing prevents the data source transaction from replicating the user
transaction hierachy as it is built up, and performing a step-by-step
rollback of nested DataSourceTransactions internally.
TransactionException
- if the transaction could not be rolled backvoid commit() throws TransactionException
You can only commit a transaction if it is the current one, which implies you have to commit any nested transaction first.
For a top-level transaction, this method performs performs the following steps in order:
Transaction.State.BEGUN
state, throw Exception if not.TransactionValidator
).BEFORE_COMMIT
TransactionEvent in the reverse order of their creation (youngest
transactions fire first) recursively.BEFORE_COMMIT
TransactionEvent for this
transaction.Transaction.State.COMMITTED
recursively (order is not specified).AFTER_COMMIT
TransactionEvent in the reverse order of their creation (youngest
transactions fire first) recursively.AFTER_COMMIT
TransactionEvent for this
transaction.For a nested transaction, a call to this method performs the following steps:
Transaction.State.BEGUN
state, throw Exception if not.BEFORE_PRECOMMIT
TransactionEvent.Transaction.State.PRECOMMIT
.AFTER_PRECOMMIT
TransactionEvent.
It would be sufficient to restrict the second check to any elements that
were changed in response to the BEFORE_PRECOMMIT
event,
but that would either require several additional methods in this class or
temporary removal of checked elements and restauration after event
processing, which would have the disadvantage that the list of changed
elements would not be available to event listeners. So we consider this
premature optimization, thus evil, and forego it for now.
This specification may seem overly detailed and restrictive, but is required to guarantee both consistency in the graph data and in the order of events generated.
TransactionException
- if the transaction could not be committedTransactionValidator
void setRollbackOnly() throws TransactionException
getParentTransaction()
to set
them to rollback only instead (if desired). A TransactionException will
be thrown if this transaction is already in state COMMITTED or
ROLLED_BACK.
TransactionException
- if the transaction could not be set to rollback only.Transaction.State getState() throws TransactionException
TransactionException
- in case of internal errors.void markGraphEntityDirty(GraphEntity g) throws TransactionException
g
- The GraphEntity that was changed.
TransactionException
- in case of errors.void markGraphEntitiesDirty(java.util.Collection<GraphEntity> g) throws TransactionException
g
- The GraphEntities that were changed.
TransactionException
- in case of errors.void unmarkGraphEntityDirty(GraphEntity g) throws TransactionException
It must be called whenever a GraphEntityClass previously marked dirty is deleted or for other reasons does not need to be checked anymore. If the object in question is a valid argument but was not marked before, this call will have no effect (especially it will not throw an exception).
g
- The GraphEntity that was changed.
TransactionException
- in case of errors.void unmarkGraphEntitiesDirty(java.util.Collection<GraphEntity> g) throws TransactionException
unmarkGraphEntityDirty(GraphEntity)
.
g
- The GraphEntityClasses that were changed.
TransactionException
- in case of errors.void markGraphEntityClassDirty(GraphEntityClass g) throws TransactionException
g
- The GraphEntityClass that was changed.
TransactionException
- in case of errors.void markGraphEntityClassesDirty(java.util.Collection<GraphEntityClass> g) throws TransactionException
g
- The GraphEntityClasses that were changed.
TransactionException
- in case of errors.void unmarkGraphEntityClassDirty(GraphEntityClass g) throws TransactionException
It must be called whenever a GraphEntityClass previously marked dirty is deleted or for other reasons does not need to be checked anymore. If the object in question is a valid argument but was not marked before, this call will have no effect (especially it will not throw an exception).
g
- The GraphEntityClass that was changed.
TransactionException
- in case of errors.void unmarkGraphEntityClassesDirty(java.util.Collection<GraphEntityClass> g) throws TransactionException
unmarkGraphEntityClassDirty(GraphEntityClass)
.
g
- The GraphEntityClasses that were changed.
TransactionException
- in case of errors.void unmarkAllGraphEnitiesDirty(DataSourceURL logicalURL) throws TransactionException
GraphEntity
marked as dirty from the dirty set that
belong to a GraphPool
identified by the (logical)
DataSourceURL
. This concernes the top-level transaction's dirty
set as well as the transitive closure of its children. Its main use is
for the 'shortcut' GraphPool.clear(boolean)
semantics removing
all elements at once.
logicalURL
- URL of the GraphPool
the elements are removed from.
TransactionException
- in case of errors.void unmarkAllGraphEnityClassesDirty(DataSourceURL logicalURL) throws TransactionException
GraphEntityClass
marked as dirty from the dirty set that
belong to a GraphPool
identified by the (logical)
DataSourceURL
. This concernes the top-level transaction's dirty
set as well as the transitive closure of its children. Its main use is
for the 'shortcut' GraphPool.clear(boolean)
semantics removing
all elements at once.
logicalURL
- URL of the GraphPool
the elements are removed from.
TransactionException
- in case of errors.boolean isDirty() throws TransactionException
true
if there is at least one GraphEntity or
GraphEntityClass in the "dirty" sets.
true
if there is at least one GraphEntity or
GraphEntityClass in the "dirty" sets.
TransactionException
- in case of errors.java.util.Collection<GraphEntity> getDirtyGraphEntities() throws TransactionException
null
. The returned set is not a copy, but a direct
reference, so it may be manipulated. This should only be done by the
consistency checkers, only to remove elements that have been checked, and
only when proper synchronization is ensured through a lock. For adding
elements, use the markGraphEntityDirty(GraphEntity)
method.
TransactionException
- in case of errors.java.util.Collection<GraphEntityClass> getDirtyGraphEntityClasses() throws TransactionException
null
. The returned set is not a copy, but a direct
reference, so it may be manipulated. This should only be done by the
consistency checkers, only to remove elements that have been checked, and
only when proper synchronization is ensured through a lock. For adding
elements, use the markGraphEntityClassDirty(GraphEntityClass)
method.
TransactionException
- in case of errors.TransactionManager getTransactionManager() throws TransactionException
TransactionManager
which manages this transaction.
TransactionManager
which manages this transaction.
TransactionException
- in case of errors.Transaction getParentTransaction() throws TransactionException
null
otherwise.
null
otherwise.
TransactionException
- in case of internal errors.java.util.Collection<? extends Transaction> getNestedTransactions() throws TransactionException
The returned Collection must not be a reference to any internal data structure or shared between method calls, but a newly allocated copy, so the caller can safely read and modify it.
null
).
TransactionException
- in case of internal errors.DataSourceTransaction getDataSourceTransaction(DataSourceURL dataSourceURL) throws TransactionException
dataSourceURL
- The DataSource for which you want to get the transaction.
null
if none.
TransactionException
- in case of errors.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |