|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object i3.dragos.core.services.transactions.localmgr.LocalTransaction
public class LocalTransaction
Implements the LocalTransaction to be used with
LocalTransactionManager
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface i3.dragos.core.services.transactions.Transaction |
---|
Transaction.State |
Field Summary | |
---|---|
protected java.util.Map<DataSourceURL,DataSourceTransaction> |
dataSourceTransactions
Map of DataSourceURLs to DataSourceTransactions for all data sources we work with. |
protected LocalTransactionManager |
manager
The LocalTransactionManager responsible for this transaction. |
protected java.util.LinkedList<LocalTransaction> |
nestedTransactions
Child transactions (may be empty, nut is never null ). |
protected LocalTransaction |
parentTransaction
The parent transaction, may be null if none. |
protected Transaction.State |
state
Current state of this transaction. |
Constructor Summary | |
---|---|
protected |
LocalTransaction(DataSource[] ds,
LocalTransaction parentTransaction,
LocalTransactionManager mgr)
Creates a new LocalTransaction. |
Method Summary | |
---|---|
void |
begin()
Starts the scope of a transaction |
void |
commit()
Commits the transaction. |
protected void |
commitHook()
A hook for subclasses which is called after the commit of any transaction, but before the state is set to (PRE)COMMITTED or any event is fired. |
DataSourceTransaction |
getDataSourceTransaction(DataSourceURL dataSourceURL)
Returns the associated DataSourceTransaction for this Transaction (or one of them if this is a distributed transaction). |
java.util.Set<GraphEntity> |
getDirtyGraphEntities()
Returns the set of GraphEntities that are currently marked "dirty". |
java.util.Set<GraphEntityClass> |
getDirtyGraphEntityClasses()
Returns the set of GraphEntityClasses that are currently marked "dirty". |
java.util.Collection<LocalTransaction> |
getNestedTransactions()
Returns a Collection containing the nested transaction (if any). |
LocalTransaction |
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. |
protected void |
prepareCommitHook()
A hook for subclasses which is called after the "prepare commit" stage of any transaction, between the first and second phase of the 2-phase-commit protocol. |
protected void |
propagateState(Transaction.State newState)
This helper method of commit() and rollback() is
responsible for setting the transaction state recursively. |
protected void |
propagateTransactionEvent(int type)
This helper method of commit() and rollback() is
responsible for firing TransactionEvents for nested transactions
recursively in reverse order of creation and finally also for this
method. |
void |
rollback()
Aborts the transaction, causing a rollback of all nested transactions. |
protected void |
rollbackHook()
A hook for subclasses which is called after the rollback of any transaction, but before the state is set to ROLLED_BACK or any event is fired. |
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 Transaction.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 Transaction.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). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final LocalTransaction parentTransaction
null
if none.
protected final LocalTransactionManager manager
protected final java.util.Map<DataSourceURL,DataSourceTransaction> dataSourceTransactions
protected final java.util.LinkedList<LocalTransaction> nestedTransactions
null
).
protected Transaction.State state
Constructor Detail |
---|
protected LocalTransaction(DataSource[] ds, LocalTransaction parentTransaction, LocalTransactionManager mgr) throws TransactionException
ds
- DataSource to work with.parentTransaction
- parent transaction if any.mgr
- The LocalTransactionManager to work with.
TransactionException
- if the DataSourceTransaction could not be created.Method Detail |
---|
public void begin() throws TransactionException
begin
in interface Transaction
TransactionException
- if the transaction could not be startedpublic void 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 Transaction.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.
rollback
in interface Transaction
TransactionException
- if the transaction could not be rolled backpublic void 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.
commit
in interface Transaction
TransactionException
- if the transaction could not be committedTransactionValidator
protected void propagateTransactionEvent(int type) throws TransactionException
commit()
and rollback()
is
responsible for firing TransactionEvents for nested transactions
recursively in reverse order of creation and finally also for this
method.
type
- the type of TransactionEvent to fire.
TransactionException
- if an exception was thrown during event handling.protected void propagateState(Transaction.State newState)
commit()
and rollback()
is
responsible for setting the transaction state recursively.
newState
- the new transaction state.public void setRollbackOnly() throws TransactionException
Transaction.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.
setRollbackOnly
in interface Transaction
TransactionException
- if the transaction could not be set to rollback only.public Transaction.State getState()
getState
in interface Transaction
public boolean isDirty() throws TransactionException
true
if there is at least one GraphEntity or
GraphEntityClass in the "dirty" sets.
isDirty
in interface Transaction
true
if there is at least one GraphEntity or
GraphEntityClass in the "dirty" sets.
TransactionException
- in case of errors.public void markGraphEntityDirty(GraphEntity g) throws TransactionException
markGraphEntityDirty
in interface Transaction
g
- The GraphEntity that was changed.
TransactionException
- in case of errors.public void markGraphEntitiesDirty(java.util.Collection<GraphEntity> g) throws TransactionException
markGraphEntitiesDirty
in interface Transaction
g
- The GraphEntities that were changed.
TransactionException
- in case of errors.public 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).
unmarkGraphEntityDirty
in interface Transaction
g
- The GraphEntity that was changed.
TransactionException
- in case of errors.public void unmarkGraphEntitiesDirty(java.util.Collection<GraphEntity> g) throws TransactionException
Transaction.unmarkGraphEntityDirty(GraphEntity)
.
unmarkGraphEntitiesDirty
in interface Transaction
g
- The GraphEntityClasses that were changed.
TransactionException
- in case of errors.public void markGraphEntityClassDirty(GraphEntityClass g) throws TransactionException
markGraphEntityClassDirty
in interface Transaction
g
- The GraphEntityClass that was changed.
TransactionException
- in case of errors.public void markGraphEntityClassesDirty(java.util.Collection<GraphEntityClass> g) throws TransactionException
markGraphEntityClassesDirty
in interface Transaction
g
- The GraphEntityClasses that were changed.
TransactionException
- in case of errors.public 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).
unmarkGraphEntityClassDirty
in interface Transaction
g
- The GraphEntityClass that was changed.
TransactionException
- in case of errors.public void unmarkGraphEntityClassesDirty(java.util.Collection<GraphEntityClass> g) throws TransactionException
Transaction.unmarkGraphEntityClassDirty(GraphEntityClass)
.
unmarkGraphEntityClassesDirty
in interface Transaction
g
- The GraphEntityClasses that were changed.
TransactionException
- in case of errors.public java.util.Set<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 Transaction.markGraphEntityDirty(GraphEntity)
method.
getDirtyGraphEntities
in interface Transaction
TransactionException
- in case of errors.public java.util.Set<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 Transaction.markGraphEntityClassDirty(GraphEntityClass)
method.
getDirtyGraphEntityClasses
in interface Transaction
TransactionException
- in case of errors.public 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.
unmarkAllGraphEnitiesDirty
in interface Transaction
logicalURL
- URL of the GraphPool
the elements are removed from.
TransactionException
- in case of errors.public 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.
unmarkAllGraphEnityClassesDirty
in interface Transaction
logicalURL
- URL of the GraphPool
the elements are removed from.
TransactionException
- in case of errors.public TransactionManager getTransactionManager()
TransactionManager
which manages this transaction.
getTransactionManager
in interface Transaction
TransactionManager
which manages this transaction.public LocalTransaction getParentTransaction()
null
otherwise.
getParentTransaction
in interface Transaction
null
otherwise.public java.util.Collection<LocalTransaction> 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.
getNestedTransactions
in interface Transaction
null
).
TransactionException
- in case of internal errors.public DataSourceTransaction getDataSourceTransaction(DataSourceURL dataSourceURL)
getDataSourceTransaction
in interface Transaction
dataSourceURL
- The DataSource for which you want to get the transaction.
null
if none.protected void commitHook() throws TransactionException
TransactionException
- in case of errors.protected void prepareCommitHook() throws TransactionException
TransactionException
- in case of errors.protected void rollbackHook() throws TransactionException
TransactionException
- in case of errors.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |