## org.eclipse.emf.cdo.view
Interface CDOView

All Superinterfaces:
  CDOCommonView, org.eclipse.net4j.util.collection.Closeable, org.eclipse.net4j.util.event.INotifier, org.eclipse.net4j.util.options.IOptionsContainer

All Known Subinterfaces:
  CDOAudit, CDOTransaction, InternalCDOTransaction, InternalCDOView

    public interface CDOView

extends CDOCommonView, org.eclipse.net4j.util.event.INotifier, org.eclipse.net4j.util.options.IOptionsContainer

A read-only view to the current (i.e. latest) state of the object graph in the repository of the underlying `session`.

Objects that are accessed through this view are unchangeable for the client. Each attempt to call a mutator on one of these objects or one of their reference collections will result in a `ReadOnlyException` being thrown immediately.

A view is opened through API of the underlying session like this:

       CDOSession session = ...
       CDOView view = session.openView();
       ...

CDOView instances must not be accessed through concurrent client threads.

Since a CDOObject, in a `non-TRANSIENT` state, is only meaningful in combination with its dedicated view they must also not be accessed through concurrent client threads. Please note that at arbitrary times an arbitrary number of framework background threads are allowed to use and modify a CDOview and its CDOObjects. Whenever you are iterating over a number of CDOObjects and need to ensure that they are not modified by the framework at the same time it is strongly recommended to acquire the `view lock` and protect your code appropriately.

Since:
  2.0

Nested Class Summary
`static interface` `CDOView.Options`

Nested classes/interfaces inherited from interface org.eclipse.emf.cdo.common.CDOCommonView
`CDOCommonView.Type`

Nested classes/interfaces inherited from interface org.eclipse.net4j.util.event.INotifier
`org.eclipse.net4j.util.event.INotifier.Introspection`

Field Summary

Fields inherited from interface org.eclipse.emf.cdo.common.CDOCommonView
`UNSPECIFIED_DATE`

Method Summary
`CDOQuery` `createQuery(java.lang.String language, java.lang.String queryString)`
`java.util.concurrent.locks.ReentrantLock` `getLock()` Returns a reentrant lock that can be used to prevent the framework from writing to any object in this view (as it is caused, for example, by passive updates).
`CDOObject` `getObject(CDOID id)` Returns the object for the given CDOID.
`CDOObject` `getObject(CDOID id, boolean loadOnDemand)` Returns the object for the given CDOID.

`

`<T extends org.eclipse.emf.ecore.EObject> T`

`

`getObject(T objectFromDifferentView)`
Takes an object from a (possibly) different view and contextifies it for the usage with this view.

`CDOResource` `getResource(java.lang.String path)` Same as `getResource(String, true)`.
`CDOResource` `getResource(java.lang.String path, boolean loadOnDemand)`
`CDOResourceNode` `getResourceNode(java.lang.String path)` Returns the resource node with the given path, or `null` if no such resource node exists.
`org.eclipse.emf.ecore.resource.ResourceSet` `getResourceSet()` Returns the `resource set` this view is associated with.
`CDOResource` `getRootResource()` Returns the root resource of the repository.
`CDOSession` `getSession()` Returns the `session` this view was opened by.
`org.eclipse.emf.ecore.resource.URIHandler` `getURIHandler()` Deprecated. This API is provisional and subject to change or removal.
`CDOViewSet` `getViewSet()` Returns the `view set` this view is associated with.
`boolean` `hasConflict()` Returns always `false`.
`boolean` `hasResource(java.lang.String path)` Returns `true` if a resource with the given path exists in the repository, `false`.
`boolean` `isDirty()` Returns always `false`.
`boolean` `isObjectRegistered(CDOID id)` Returns `true` if an `object` with the given `id` is currently registered in this view, `false` otherwise.
`void` `lockObjects(java.util.Collection<? extends CDOObject> objects, org.eclipse.net4j.util.concurrent.RWLockManager.LockType lockType, long timeout)` Locks the given objects.
`CDOView.Options` `options()`
`java.util.List<CDOResourceNode>` `queryResources(CDOResourceFolder folder, java.lang.String name, boolean exactMatch)` Returns a list of the resources in the given folder with a name equal to or starting with the value of the name parameter.
`org.eclipse.net4j.util.collection.CloseableIterator<CDOResourceNode>` `queryResourcesAsync(CDOResourceFolder folder, java.lang.String name, boolean exactMatch)` Returns an iterator over the resources in the given folder with a name equal to or starting with the value of the name parameter.
`int` `reload(CDOObject... objects)` Reloads the given `objects` from the repository.
`void` `unlockObjects()` Unlocks all locked objects of this view.
`void` `unlockObjects(java.util.Collection<? extends CDOObject> objects, org.eclipse.net4j.util.concurrent.RWLockManager.LockType lockType)` Unlocks the given locked objects of this view.

Methods inherited from interface org.eclipse.emf.cdo.common.CDOCommonView
`getTimeStamp, getViewID, getViewType`

Methods inherited from interface org.eclipse.net4j.util.collection.Closeable
`close, isClosed`

Methods inherited from interface org.eclipse.net4j.util.event.INotifier
`addListener, removeListener`

Method Detail

### getSession

    CDOSession getSession()

  Returns the `session` this view was opened by.

  Specified by:
    `getSession` in interface `CDOCommonView`
  Returns:
    The session this view was opened by, or `null` if this view is closed.
  See Also:
    `Closeable.close()`, `Closeable.isClosed()`, `CDOSession.openView()`, `CDOSession.openView(ResourceSet)`, `CDOSession.openAudit(long)`, `CDOSession.openAudit(ResourceSet, long)`, `CDOSession.openTransaction()`, `CDOSession.openTransaction(ResourceSet)`

### getViewSet

    CDOViewSet getViewSet()

  Returns the `view set` this view is associated with.

  Returns:
    The view set this view is associated with, never `null`.
  See Also:
    `CDOViewSet.getViews()`

### getResourceSet

    org.eclipse.emf.ecore.resource.ResourceSet getResourceSet()

  Returns the `resource set` this view is associated with.

  Same as calling `getViewSet().getResourceSet()`.

  See Also:
    `CDOViewSet.getResourceSet()`

### getURIHandler

    @Deprecated
    org.eclipse.emf.ecore.resource.URIHandler getURIHandler()

  Deprecated. This API is provisional and subject to change or removal.

### getLock

    java.util.concurrent.locks.ReentrantLock getLock()

  Returns a reentrant lock that can be used to prevent the framework from writing to any object in this view (as it is caused, for example, by passive updates).

  Acquiring this lock provides a means to safely iterate over multiple model elements without being affected by unanticipated remote updates, like in the following example:

          CDOResource resource = view.getResource("/orders/order-4711");
          PurchaseOrder order = (PurchaseOrder)resource.getContents().get(0);
          ReentrantLock lock = view.getLock();
          if (!lock.tryLock(5L, TimeUnit.SECONDS))
          {
            throw new TimeoutException();
          }

          try
          {
            float sum = 0;
            for (OrderDetail detail : order.getOrderDetails())
            {
              sum += detail.getPrice();
            }

            System.out.println("Sum: " + sum);
          }
          finally
          {
            lock.unlock();
          }
        }

  Note that this method really just returns the lock instance but does not acquire the lock! The above example acquires the lock with a timeout that expires after five seconds.

### isDirty

    boolean isDirty()

  Returns always `false`.

  This method has a special implementation in `CDOTransaction` as well.

  See Also:
    `CDOTransaction.isDirty()`

### hasConflict

    boolean hasConflict()

  Returns always `false`.

  This method has a special implementation in `CDOTransaction` as well.

  See Also:
    `CDOTransaction.hasConflict()`

### hasResource

    boolean hasResource(java.lang.String path)

  Returns `true` if a resource with the given path exists in the repository, `false`.

  See Also:
    `getResource(String, boolean)`

### getResource

    CDOResource getResource(java.lang.String path,
                            boolean loadOnDemand)

  See Also:
    `ResourceSet.getResource(URI, boolean)`

### getResource

    CDOResource getResource(java.lang.String path)

  Same as `getResource(String, true)`.

  See Also:
    `ResourceSet.getResource(URI, boolean)`

### getResourceNode

    CDOResourceNode getResourceNode(java.lang.String path)

  Returns the resource node with the given path, or `null` if no such resource node exists.

### getRootResource

    CDOResource getRootResource()

  Returns the root resource of the repository.

  The root resource is a special resource with only `CDOResourceNodes` in its contents list. You can use it as the main entry into the new resource and folder structure.

### queryResources

    java.util.List<CDOResourceNode> queryResources(CDOResourceFolder folder,
                                                   java.lang.String name,
                                                   boolean exactMatch)

  Returns a list of the resources in the given folder with a name equal to or starting with the value of the name parameter.

  Parameters:
    `folder` - The folder to search in, or `null` for top level resource nodes.
    `name` - the name or prefix of the resource nodes to return.
    `exactMatch` - `true` if the complete name of the resource must match, `false` if only a common prefix of the name must match.

### queryResourcesAsync

    org.eclipse.net4j.util.collection.CloseableIterator<CDOResourceNode> queryResourcesAsync(CDOResourceFolder folder,
                                                                                             java.lang.String name,
                                                                                             boolean exactMatch)

  Returns an iterator over the resources in the given folder with a name equal to or starting with the value of the name parameter. The underlying query will be executed asynchronously.

  Parameters:
    `folder` - The folder to search in, or `null` for top level resource nodes.
    `name` - the name or prefix of the resource nodes to return.
    `exactMatch` - `true` if the complete name of the resource must match, `false` if only a common prefix of the name must match.

### getObject

    CDOObject getObject(CDOID id,
                        boolean loadOnDemand)

  Returns the object for the given CDOID.

  Parameters:
    `loadOnDemand` - whether to create and load the object, if it doesn't already exist.
  Returns:
    the object resolved by the CDOID if the id is not `null`, or `null` if there isn't one and loadOnDemand is `false`.

### getObject

    CDOObject getObject(CDOID id)

  Returns the object for the given CDOID.

  Same as `getObject(id, true)`.

  See Also:
    `getObject(CDOID, boolean)`

### getObject

    <T extends org.eclipse.emf.ecore.EObject> T getObject(T objectFromDifferentView)

  Takes an object from a (possibly) different view and contextifies it for the usage with this view.
  - If the given object is contained in this view it is returned unmodified.
  - If the given object can not be cast to `CDOObject` it is returned unmodified.
  - If the view of the given object is contained in a different session an `IllegalArgumentException` is thrown.
  - If `null` is passed `null` is returned.

### isObjectRegistered

    boolean isObjectRegistered(CDOID id)

  Returns `true` if an `object` with the given `id` is currently registered in this view, `false` otherwise.

### reload

    int reload(CDOObject... objects)

  Reloads the given `objects` from the repository.

### lockObjects

    void lockObjects(java.util.Collection<? extends CDOObject> objects,
                     org.eclipse.net4j.util.concurrent.RWLockManager.LockType lockType,
                     long timeout)
                     throws java.lang.InterruptedException

  Locks the given objects. Once the objects are locked, they will not be changed remotely or go in conflict state.

  Throws:
    `java.lang.InterruptedException`

### unlockObjects

    void unlockObjects(java.util.Collection<? extends CDOObject> objects,
                       org.eclipse.net4j.util.concurrent.RWLockManager.LockType lockType)

  Unlocks the given locked objects of this view.

### unlockObjects

    void unlockObjects()

  Unlocks all locked objects of this view.

  Since:
    2.0

### createQuery

    CDOQuery createQuery(java.lang.String language,
                         java.lang.String queryString)

  Since:
    2.0

### options

    CDOView.Options options()

  Specified by:
    `options` in interface `org.eclipse.net4j.util.options.IOptionsContainer`
  Since:
    2.0

Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others. All Rights Reserved.