|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.emf.transaction.impl.TransactionImpl
public class TransactionImpl
The default transaction implementation.
Field Summary | |
---|---|
static String |
ALLOW_CHANGE_PROPAGATION_BLOCKING
This option, when provided to a transaction that inherits from this implementation class and has children transactions that are using this implementation class, provides an optional block of the normal propagation of change descriptions to the parent transaction by any transaction in the child subtree of this transaction. |
static String |
BLOCK_CHANGE_PROPAGATION
This option blocks the propagation of change descriptions to the parent transaction. |
protected CompositeChangeDescription |
change
|
static Map<Object,Object> |
DEFAULT_UNDO_REDO_OPTIONS
The transaction options that should be used when undoing/redoing changes on the command stack. |
protected List<Notification> |
notifications
|
static String |
OPTION_IS_TRIGGER_TRANSACTION
An informative option that tags the transaction as a transaction that is executing trigger commands. |
Fields inherited from interface org.eclipse.emf.transaction.Transaction |
---|
OPTION_IS_UNDO_REDO_TRANSACTION, OPTION_NO_NOTIFICATIONS, OPTION_NO_TRIGGERS, OPTION_NO_UNDO, OPTION_NO_VALIDATION, OPTION_UNPROTECTED, OPTION_VALIDATE_EDIT, OPTION_VALIDATE_EDIT_CONTEXT |
Constructor Summary | |
---|---|
TransactionImpl(TransactionalEditingDomain domain,
boolean readOnly)
Initializes me with my editing domain and read-only state. |
|
TransactionImpl(TransactionalEditingDomain domain,
boolean readOnly,
Map<?,?> options)
Initializes me with my editing domain, read-only state, and additional options. |
Method Summary | |
---|---|
void |
abort(IStatus status)
Aborts the transaction with a reason given by the specified status. |
void |
add(Notification notification)
Adds the specified notification to the list of notifications received during this transaction. |
void |
addTriggers(TriggerCommand triggers)
Adds a group of triggers that were executed during my commit. |
protected void |
close()
Closes me. |
protected static boolean |
collectsNotifications(Transaction tx)
Queries whether the specified transaction collects notifications for broadcast to listeners or for validation. |
void |
commit()
Attempts to commit the transaction. |
void |
endPrivileged(PrivilegedRunnable<?> runnable)
Returns me to my previous owner, upon completion of the specified privileged runnable. |
TransactionChangeDescription |
getChangeDescription()
Obtains the change description summarizing the changes made to the model during the execution of the transaction. |
protected static Map<?,?> |
getDefaultOptions(TransactionalEditingDomain domain)
Obtains the default transaction options, if any, of the specified editing domain. |
TransactionalEditingDomain |
getEditingDomain()
Queries the editing domain in which I am transacting. |
protected InternalTransactionalEditingDomain |
getInternalDomain()
Obtains my owning editing domain as the internal interface. |
List<Notification> |
getNotifications()
Obtains the list of notifications that were received during execution of this transaction. |
Map<Object,Object> |
getOptions()
Obtains the special options with which I was created. |
Thread |
getOwner()
Queries the thread that owns me. |
Transaction |
getParent()
My parent transaction, if any. |
InternalTransaction |
getRoot()
Obtains the root transaction (the one that has no parent). |
IStatus |
getStatus()
Obtains the status of the transaction. |
Command |
getTriggers()
Obtains the triggers that were executed during my commit. |
protected static boolean |
hasOption(Transaction tx,
String option)
Queries whether the specified transaction has a boolean option. |
protected boolean |
isAborted()
Queries whether I have been aborted. |
boolean |
isActive()
Queries whether I am active. |
protected static boolean |
isNotificationEnabled(Transaction tx)
Queries whether the specified transaction should send post-commit events, according to its options . |
boolean |
isReadOnly()
Queries whether I am a read-only transaction. |
boolean |
isRollingBack()
Queries whether this transaction or any of its ancestors is in the process of rolling back. |
protected static boolean |
isTriggerEnabled(Transaction tx)
Queries whether the specified transaction should invoke pre-commit, listeners, according to its options and
read-only state . |
protected static boolean |
isUndoEnabled(Transaction tx)
Queries whether the specified transaction should record undo information, according to its options and
read-only state . |
protected static boolean |
isUnprotected(Transaction tx)
Queries whether the specified transaction is an unprotected write, according to its options and
read-only state . |
protected static boolean |
isValidationEnabled(Transaction tx)
Queries whether the specified transaction should validate changes, according to its options and
read-only state . |
void |
pause()
Pauses me while a child transaction is active, so that I do not collect either notifications or recorded changes during that time. |
void |
resume(TransactionChangeDescription nestedChanges)
Resumes me after completion of a child transaction. |
void |
rollback()
Rolls back the transaction, undoing all of the pending model changes. |
void |
setParent(InternalTransaction parent)
Assigns my parent transaction (the one in which I am nested). |
void |
setStatus(IStatus status)
Sets the status of the transaction. |
void |
start()
Starts me. |
void |
startPrivileged(PrivilegedRunnable<?> runnable)
Transfers ownership of this transaction to the specified privileged runnable. |
String |
toString()
|
protected IStatus |
validate()
Validates me. |
void |
yield()
Temporarily yields access to another read-only transaction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String ALLOW_CHANGE_PROPAGATION_BLOCKING
BLOCK_CHANGE_PROPAGATION
option to its own options with
the value of Boolean.TRUE
. This option IS inherited by child transactions.
public static final String BLOCK_CHANGE_PROPAGATION
ALLOW_CHANGE_PROPAGATION_BLOCKING
option added either directly or through
option inheritance. Note that to enable this option it must be added to the options map with
the value of Boolean.TRUE
. This option is NOT inherited by child transactions.
public static final String OPTION_IS_TRIGGER_TRANSACTION
public static final Map<Object,Object> DEFAULT_UNDO_REDO_OPTIONS
As of the 1.2 release, this map is immutable.
protected List<Notification> notifications
protected final CompositeChangeDescription change
Constructor Detail |
---|
public TransactionImpl(TransactionalEditingDomain domain, boolean readOnly)
domain
- the editing domain in which I operatereadOnly
- true
if I am read-only; false
if I am read/writepublic TransactionImpl(TransactionalEditingDomain domain, boolean readOnly, Map<?,?> options)
domain
- the editing domain in which I operatereadOnly
- true
if I am read-only; false
if I am read/writeoptions
- my options, or null
for defaultsMethod Detail |
---|
public void start() throws InterruptedException
InternalTransaction
activate
me.
Note that this call should block the current thread until the editing domain grants exclusive access.
start
in interface InternalTransaction
InterruptedException
- if the current thread is interrupted while
waiting for activationpublic final TransactionalEditingDomain getEditingDomain()
Transaction
getEditingDomain
in interface Transaction
public final Transaction getParent()
Transaction
pre-commit
events, they do not send post-commit events, nor are they validated.
Validation is performed only by the top-level transaction to validate
all changes made in its scope, and only the top-level transaction then
can send the post-commit event. Nested transactions can roll back their
changes without affecting their parent transactions.
Transactions can nest as follows:
getParent
in interface Transaction
public final void setParent(InternalTransaction parent)
InternalTransaction
setParent
in interface InternalTransaction
parent
- my parent transactionpublic final InternalTransaction getRoot()
InternalTransaction
getRoot
in interface InternalTransaction
public final Thread getOwner()
Transaction
getOwner
in interface Transaction
public final boolean isReadOnly()
Transaction
isReadOnly
in interface Transaction
true
if I am read-only; false
, otherwisepublic final Map<Object,Object> getOptions()
Transaction
TransactionalEditingDomain
interface.
getOptions
in interface Transaction
public boolean isActive()
Transaction
isActive
in interface Transaction
public IStatus getStatus()
Transaction
Note that while I am still active, my status is usually OK. It may not be OK if I have been aborted, in which case I will roll back on attempt to commit.
getStatus
in interface Transaction
public void setStatus(IStatus status)
InternalTransaction
setStatus
in interface InternalTransaction
status
- my statuspublic void abort(IStatus status)
InternalTransaction
abort
in interface InternalTransaction
status
- a status object providing the reason. It should be the status
attached to the eventual RollbackException
, and should be
set as my status
protected boolean isAborted()
true
if I have been aborted; false
, otherwiseInternalTransaction.abort(IStatus)
public void commit() throws RollbackException
Transaction
Commit proceeds in three phases: pre-commit events and triggers, validation, and the post-commit events.
Pre-commit notifications are sent to the editing domain's registered
ResourceSetListener
s to inform them that the transaction is
committing. If any listener throws a RollbackException
, then
the transaction is rolled back and the exception is propagated to the
caller. Any trigger commands returned by pre-commit listeners are
executed after all listeners are invoked, in a nested transaction.
This nested transaction, then, follows the commit protocol to send out
pre-commit notifications again. This process continues until no more
trigger commands are executed or some listener causes rollback.
After all pre-commit processing completes, the transaction is validated.
Validation checks all of the notifications received from the model
during the transaction (including any nested transactions, esp. those
that executed triggers). If the validation yields an error status (or
more severe), then the transaction is rolled back, throwing a
RollbackException
with the validation status.
The final phase, if validation passes, is to send out the post-commit event to the resource set listeners. This event includes all of the notifications received during the transaction, including triggers. Note that, because these listeners can read the model, they may cause further notifications (by resolving proxies, loading resources, etc.). Listeners are invoked in a nested read-only transaction, so it will also commit and send out a post-commit event if necessary with additional notifications.
Note that even a read-only
transaction can
roll back. This should only occur, however, if it is corrupted by a
concurrent modification by another thread, which means that invalid data
could have been read.
commit
in interface Transaction
RollbackException
- if a listener or validation caused the
transaction to roll back instead of committing successfullypublic void rollback()
Transaction
rollback
in interface Transaction
public void yield()
Transaction
TransactionalEditingDomain
supports any number of pseudo-concurrent
read-only transactions. Transactions that are expected to be
long-running should yield frequently, as a task running in a progress
monitor is expected to check for cancellation frequently. However, there
is a higher cost (in time) associated with yielding, so it should not
be overdone.
Only read-only transactions may yield, and only the transaction that is currently active in the editing domain may yield. The yielding transaction may be nested, but not within a read/write transaction at any depth.
Upon yielding, some other read-only transaction that is attempting to start or to return from a yield will take control of the editing domain. Control is never yielded to a read/write transaction (not even to a read-only transaction nested in a read/write) because this would introduce dirty reads (transactions reading uncommitted changes). If there are no other read-only transactions to receive the transfer of control, then the call returns immediately. Otherwise, control is transferred in FIFO fashion to waiting transactions.
yield
in interface Transaction
public TransactionChangeDescription getChangeDescription()
Transaction
getChangeDescription
in interface Transaction
null
if the transaction
rolled back or is still active
protected InternalTransactionalEditingDomain getInternalDomain()
public void pause()
InternalTransaction
pause
in interface InternalTransaction
public void resume(TransactionChangeDescription nestedChanges)
InternalTransaction
resume
in interface InternalTransaction
nestedChanges
- the nested transaction's recorded changes, or
null
if it rolled back (in which case, I do not add
anything to my changes)public boolean isRollingBack()
InternalTransaction
isRollingBack
in interface InternalTransaction
true
if I or my
parent
(if any) am rolling back;
false
otherwiseprotected void close()
resume
it.
If a subclass overrides this method, it must ensure that this implementation is also invoked.
public void add(Notification notification)
InternalTransaction
add
in interface InternalTransaction
notification
- the notification to addInternalTransaction.getNotifications()
public List<Notification> getNotifications()
InternalTransaction
getNotifications
in interface InternalTransaction
InternalTransaction.add(Notification)
protected IStatus validate()
public Command getTriggers()
InternalTransaction
getTriggers
in interface InternalTransaction
null
if I have
no triggers (perhaps because the Transaction.OPTION_NO_TRIGGERS
was applied). This may be a single Command
or a
compound of multiplepublic void addTriggers(TriggerCommand triggers)
InternalTransaction
addTriggers
in interface InternalTransaction
triggers
- the triggers to addpublic void startPrivileged(PrivilegedRunnable<?> runnable)
InternalTransaction
startPrivileged
in interface InternalTransaction
runnable
- the runnable whose thread is to borrow mepublic void endPrivileged(PrivilegedRunnable<?> runnable)
InternalTransaction
endPrivileged
in interface InternalTransaction
runnable
- the runnable whose thread had borrowed mepublic String toString()
toString
in class Object
protected static boolean isUndoEnabled(Transaction tx)
options
and
read-only state
.
tx
- a transaction
true
if the transaction should record undo
information; false
, otherwiseprotected static boolean isValidationEnabled(Transaction tx)
options
and
read-only state
.
tx
- a transaction
true
if the transaction should validate
changes; false
, otherwiseprotected static boolean isTriggerEnabled(Transaction tx)
options
and
read-only state
.
tx
- a transaction
true
if the transaction should perform the pre-commit
procedures; false
, otherwiseprotected static boolean isNotificationEnabled(Transaction tx)
options
.
tx
- a transaction
true
if the transaction should send post-commit
events; false
, otherwiseprotected static boolean isUnprotected(Transaction tx)
options
and
read-only state
.
tx
- a transaction
true
if the transaction is an unprotected write
transaction; false
, otherwiseprotected static boolean collectsNotifications(Transaction tx)
tx
- a transaction
true
any of notification, triggers, and validation
are enabled; false
, otherwiseisNotificationEnabled(Transaction)
,
isTriggerEnabled(Transaction)
,
isValidationEnabled(Transaction)
protected static boolean hasOption(Transaction tx, String option)
tx
- a transactionoption
- the boolean-valued option to query
true
if the transaction has the option;
false
if it does notprotected static Map<?,?> getDefaultOptions(TransactionalEditingDomain domain)
domain
- an editing domain
|
Copyright 2002, 2007 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |