## org.eclipse.emf.transaction.util
Class TransactionUtil

    java.lang.Object
      org.eclipse.emf.transaction.util.TransactionUtil

    public class TransactionUtil

extends Object

Static utilities for dealing with EMF elements and resources in a transactional editing domain.

Method Summary

`static

`<T> RunnableWithResult<T>`

`

`createPrivilegedRunnable(TransactionalEditingDomain domain, RunnableWithResult<? extends T> runnable)`
Utility method for providing privileged access to runnables that return values.

`static void` `disconnectFromEditingDomain(EObject eobject)` Disconnects the specified element from its editing domain, so that it is released from the constraints of the transactional environment.
`static void` `disconnectFromEditingDomain(Resource resource)` Disconnects the specified resource from its editing domain, so that it is released from the constraints of the transactional environment.
`static void` `dispose(ChangeDescription change)` Disposes a change description.

`static

`<T> T`

`

`getAdapter(TransactionalEditingDomain domain, Class<? extends T> adapterType)`
Obtains an instance of the specified adapter type for an editing domain.

`static TransactionalEditingDomain` `getEditingDomain(EObject eObject)` Obtains the transactional editing domain that manages the specified element.
`static TransactionalEditingDomain` `getEditingDomain(Object object)` Obtains the transactional editing domain that manages the specified object.
`static TransactionalEditingDomain` `getEditingDomain(Resource resource)` Obtains the transactional editing domain that manages the specified resource.
`static TransactionalEditingDomain` `getEditingDomain(ResourceSet rset)` Obtains the transactional editing domain that manages the specified resource set.

`static

`<T> T`

`

`runExclusive(TransactionalEditingDomain domain, RunnableWithResult<? extends T> runnable)`
Utility method for executing exclusive runnables that return values.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### getEditingDomain

    public static TransactionalEditingDomain getEditingDomain(EObject eObject)

  Obtains the transactional editing domain that manages the specified element.

  Parameters:
    `eObject` - an EMF model element
  Returns:
    its editing domain, or `null` if it is not attached to any resource in an editing domain

### getEditingDomain

    public static TransactionalEditingDomain getEditingDomain(Resource resource)

  Obtains the transactional editing domain that manages the specified resource.

  Parameters:
    `resource` - a resource
  Returns:
    its editing domain, or `null` if it is not in a resource set managed by an editing domain

### getEditingDomain

    public static TransactionalEditingDomain getEditingDomain(ResourceSet rset)

  Obtains the transactional editing domain that manages the specified resource set.

  Parameters:
    `rset` - a resource set
  Returns:
    its editing domain, or `null` if it is managed by an editing domain

### getEditingDomain

    public static TransactionalEditingDomain getEditingDomain(Object object)

  Obtains the transactional editing domain that manages the specified object. This is useful, for example, to get the editing domain from which a `Notification` originated by testing its `notifier`.

  Parameters:
    `object` - some object
  Returns:
    its editing domain, or `null` if it is not of a type that is managed by an editing domain or if it is of an appropriate type but happens not to be managed by an editing domain

### disconnectFromEditingDomain

    public static void disconnectFromEditingDomain(Resource resource)

  Disconnects the specified resource from its editing domain, so that it is released from the constraints of the transactional environment. Note that this is only permitted if the resource is not currently attached to the resource set of the editing domain in question.

  This should only be done with extreme caution. If any other resources that are still being managed by the transactional editing domain have dependencies on this `resource`, then existing undo/redo information for these may be corrupted and future undo recording may not be complete. It is highly recommended to flush the command stack of the editing domain in question after disconnecting a resource from it.

  Parameters:
    `resource` - a resource to disconnect from its current editing domain, if any
  Throws:
    `IllegalStateException` - if the specified `resource` is still in the `ResourceSet` managed by its current editing domain
  Since:
    1.1

### disconnectFromEditingDomain

    public static void disconnectFromEditingDomain(EObject eobject)

  Disconnects the specified element from its editing domain, so that it is released from the constraints of the transactional environment. Note that this is only permitted if the element is not currently attached to the resource set of the editing domain in question.

  This should only be done with extreme caution. If any other elements that are still being managed by the transactional editing domain have dependencies on this `eobject`, then existing undo/redo information for these may be corrupted and future undo recording may not be complete. It is highly recommended to flush the command stack of the editing domain in question after disconnecting an element from it.

  It is probably more useful to disconnect an entire `Resource` from the editing domain instead of just an object, unless that object is being moved from one editing domain to another.

  Parameters:
    `eobject` - a model element to disconnect from its current editing domain, if any
  Throws:
    `IllegalStateException` - if the specified `eobject` is still in the `ResourceSet` managed by its current editing domain
  Since:
    1.1
  See Also:
    `disconnectFromEditingDomain(Resource)i`

### dispose

    public static void dispose(ChangeDescription change)

  Disposes a change description. Currently, this just clears the adapters list of all objects in the change description.

  Parameters:
    `change` - a change description to dispose
  Since:
    1.1

### getAdapter

    public static <T> T getAdapter(TransactionalEditingDomain domain,
                                   Class<? extends T> adapterType)

  Obtains an instance of the specified adapter type for an editing domain.

  Type Parameters:
    `T` - the adapter interface that is required
  Parameters:
    `domain` - an editing domain to adapt
    `adapterType` - the required interface
  Returns:
    an instance of the required interface that adapts the `domain`, or `null` if it does not supply this interface
  Since:
    1.2

### runExclusive

    public static <T> T runExclusive(TransactionalEditingDomain domain,
                                     RunnableWithResult<? extends T> runnable)
                          throws InterruptedException

  Utility method for executing exclusive runnables that return values. The advantage of this method over `TransactionalEditingDomain.runExclusive(Runnable)` is that it provides compile-time type safety.

  Type Parameters:
    `T` - the result type of the runnable
  Parameters:
    `domain` - the editing domain in which to run
    `runnable` - the runnable to execute
  Returns:
    the result of the runnable
  Throws:
    `InterruptedException` - if the current thread is interrupted while waiting for access to the resource set
  Since:
    1.2

### createPrivilegedRunnable

    public static <T> RunnableWithResult<T> createPrivilegedRunnable(TransactionalEditingDomain domain,
                                                                     RunnableWithResult<? extends T> runnable)
                                                          throws InterruptedException

  Utility method for providing privileged access to runnables that return values. The advantage of this method over `TransactionalEditingDomain.createPrivilegedRunnable(Runnable)` is that it provides compile-time type safety.

  Type Parameters:
    `T` - the result type of the runnable
  Parameters:
    `domain` - the editing domain in which to grant privileged access
    `runnable` - the runnable to execute
  Returns:
    the result of the runnable
  Throws:
    `InterruptedException` - if the current thread is interrupted while waiting for access to the resource set
  Since:
    1.2

Copyright 2002, 2007 IBM Corporation and others. All Rights Reserved.