Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-06-06 09:15:05 +0000
committerEike Stepper2012-06-06 09:15:05 +0000
commitbeaf88a6d18849a3d00476ca046a111f636ace5a (patch)
treeb4dbc0ddc54963632692f0d0db83877dabd73a57 /plugins/org.eclipse.emf.cdo.server.ocl
parente5bc42789a5fa73d5f2c9a2dac4f0d0c177f9b63 (diff)
downloadcdo-beaf88a6d18849a3d00476ca046a111f636ace5a.tar.gz
cdo-beaf88a6d18849a3d00476ca046a111f636ace5a.tar.xz
cdo-beaf88a6d18849a3d00476ca046a111f636ace5a.zip
Update Javadocs
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.ocl')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java830
-rw-r--r--plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentMap.java280
-rw-r--r--plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLExtentCreator.java54
-rw-r--r--plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java4
4 files changed, 593 insertions, 575 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java
index cff404ee16..984f344d64 100644
--- a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java
+++ b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java
@@ -1,412 +1,418 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.ocl;
-
-import org.eclipse.emf.cdo.common.branch.CDOBranch;
-import org.eclipse.emf.cdo.common.commit.CDOChangeKind;
-import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
-import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
-import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.util.ObjectNotFoundException;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.spi.cdo.InternalCDOObject;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * @author Eike Stepper
- */
-public class CDOExtentCreator implements OCLExtentCreator
-{
- private CDOView view;
-
- private CDOChangeSetData changeSetData;
-
- private CDORevisionCacheAdder revisionCacheAdder;
-
- public CDOExtentCreator(CDOView view)
- {
- this.view = view;
- }
-
- public CDOView getView()
- {
- return view;
- }
-
- public CDOChangeSetData getChangeSetData()
- {
- return changeSetData;
- }
-
- public void setChangeSetData(CDOChangeSetData changeSetData)
- {
- this.changeSetData = changeSetData;
- }
-
- public CDORevisionCacheAdder getRevisionCacheAdder()
- {
- return revisionCacheAdder;
- }
-
- public void setRevisionCacheAdder(CDORevisionCacheAdder revisionCacheAdder)
- {
- this.revisionCacheAdder = revisionCacheAdder;
- }
-
- public Set<EObject> createExtent(EClass eClass, AtomicBoolean canceled)
- {
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
- CDOBranch branch = view.getBranch();
- long timeStamp = view.getTimeStamp();
- return createExtent(eClass, accessor, branch, timeStamp, canceled);
- }
-
- protected Set<EObject> createExtent(EClass eClass, IStoreAccessor accessor, CDOBranch branch, long timeStamp,
- final AtomicBoolean canceled)
- {
- final Set<EObject> extent = new HashSet<EObject>();
- if (changeSetData != null)
- {
- List<CDOIDAndVersion> newObjects = changeSetData.getNewObjects();
- if (newObjects != null)
- {
- for (CDOIDAndVersion key : newObjects)
- {
- EObject object = getEObject(key.getID());
- if (object != null)
- {
- extent.add(object);
- }
- }
- }
- }
-
- accessor.handleRevisions(eClass, branch, timeStamp, false, new CDORevisionHandler.Filtered.Undetached(
- new CDORevisionHandler()
- {
- public boolean handleRevision(CDORevision revision)
- {
- if (revisionCacheAdder != null)
- {
- revisionCacheAdder.addRevision(revision);
- }
-
- CDOID id = revision.getID();
- if (!isDetached(id))
- {
- EObject object = getEObject(id);
- if (object != null)
- {
- extent.add(object);
- }
- }
-
- return !canceled.get();
- }
- }));
-
- return extent;
- }
-
- protected boolean isDetached(CDOID id)
- {
- if (changeSetData == null)
- {
- return false;
- }
-
- CDOChangeKind changeKind = changeSetData.getChangeKind(id);
- return changeKind == CDOChangeKind.DETACHED;
- }
-
- protected EObject getEObject(CDOID id) throws ObjectNotFoundException
- {
- InternalCDOObject object = (InternalCDOObject)view.getObject(id);
- if (object == null)
- {
- throw new ObjectNotFoundException(id);
- }
-
- return object.cdoInternalInstance();
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Lazy extends CDOExtentCreator
- {
- public Lazy(CDOView view)
- {
- super(view);
- }
-
- @Override
- protected Set<EObject> createExtent(final EClass eClass, final IStoreAccessor accessor, final CDOBranch branch,
- final long timeStamp, final AtomicBoolean canceled)
- {
- return new Set<EObject>()
- {
- private Iterator<EObject> emptyIterator;
-
- private Boolean empty;
-
- private CountDownLatch emptyKnown = new CountDownLatch(1);
-
- public synchronized boolean isEmpty()
- {
- if (empty != null)
- {
- return empty;
- }
-
- emptyIterator = iterator();
-
- try
- {
- emptyKnown.await();
- return empty;
- }
- catch (InterruptedException ex)
- {
- throw new Error("Interrupted");
- }
- }
-
- public synchronized Iterator<EObject> iterator()
- {
- if (emptyIterator != null)
- {
- Iterator<EObject> it = emptyIterator;
- emptyIterator = null;
- return it;
- }
-
- final Object mutex = new Object();
- final LinkedList<CDOID> ids = new LinkedList<CDOID>();
- final boolean[] done = { false };
-
- Thread thread = new Thread("OCLExtentIterator")
- {
- @Override
- public void run()
- {
- handleDirtyState();
- handlePersistentState();
-
- synchronized (mutex)
- {
- done[0] = true;
- mutex.notify();
- }
-
- if (empty == null)
- {
- empty = true;
- emptyKnown.countDown();
- }
- }
-
- private void handleDirtyState()
- {
- CDOChangeSetData changeSetData = getChangeSetData();
- if (changeSetData != null)
- {
- List<CDOIDAndVersion> newObjects = changeSetData.getNewObjects();
- if (newObjects != null)
- {
- for (CDOIDAndVersion key : newObjects)
- {
- enqueue(key.getID());
- }
- }
- }
- }
-
- private void handlePersistentState()
- {
- accessor.handleRevisions(eClass, branch, timeStamp, false, new CDORevisionHandler.Filtered.Undetached(
- new CDORevisionHandler()
- {
- public boolean handleRevision(CDORevision revision)
- {
- empty = false;
- emptyKnown.countDown();
-
- CDORevisionCacheAdder revisionCacheAdder = getRevisionCacheAdder();
- if (revisionCacheAdder != null)
- {
- revisionCacheAdder.addRevision(revision);
- }
-
- CDOID id = revision.getID();
- if (!isDetached(id))
- {
- enqueue(id);
- }
-
- return !canceled.get();
- }
- }));
- }
-
- private void enqueue(CDOID id)
- {
- synchronized (mutex)
- {
- ids.addLast(id);
- mutex.notify();
- }
- }
- };
-
- thread.setDaemon(true);
- thread.start();
-
- return new Iterator<EObject>()
- {
- private CDOID next;
-
- public boolean hasNext()
- {
- while (next == null)
- {
- if (canceled.get())
- {
- return false;
- }
-
- synchronized (mutex)
- {
- if (ids.isEmpty())
- {
- if (done[0])
- {
- return false;
- }
-
- try
- {
- mutex.wait();
- }
- catch (InterruptedException ex)
- {
- throw new Error(ex);
- }
- }
- else
- {
- next = ids.removeFirst();
- }
- }
- }
-
- return true;
- }
-
- public EObject next()
- {
- if (!hasNext())
- {
- throw new NoSuchElementException();
- }
-
- try
- {
- return getEObject(next);
- }
- finally
- {
- next = null;
- }
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- };
- }
-
- public int size()
- {
- throw new Error("Not supported"); // RuntimeException gets swallowed up the stack!
- }
-
- public boolean contains(Object o)
- {
- throw new Error("Not supported");
- }
-
- public Object[] toArray()
- {
- throw new Error("Not supported");
- }
-
- public <T> T[] toArray(T[] a)
- {
- throw new Error("Not supported");
- }
-
- public boolean add(EObject o)
- {
- throw new Error("Not supported");
- }
-
- public boolean remove(Object o)
- {
- throw new Error("Not supported");
- }
-
- public boolean containsAll(Collection<?> c)
- {
- throw new Error("Not supported");
- }
-
- public boolean addAll(Collection<? extends EObject> c)
- {
- throw new Error("Not supported");
- }
-
- public boolean retainAll(Collection<?> c)
- {
- throw new Error("Not supported");
- }
-
- public boolean removeAll(Collection<?> c)
- {
- throw new Error("Not supported");
- }
-
- public void clear()
- {
- throw new Error("Not supported");
- }
- };
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.ocl;
+
+import org.eclipse.emf.cdo.common.branch.CDOBranch;
+import org.eclipse.emf.cdo.common.commit.CDOChangeKind;
+import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
+import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
+import org.eclipse.emf.cdo.server.IStoreAccessor;
+import org.eclipse.emf.cdo.server.StoreThreadLocal;
+import org.eclipse.emf.cdo.util.ObjectNotFoundException;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.spi.cdo.InternalCDOObject;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * An OCL {@link OCLExtentCreator extent creator} implementation for CDO.
+ * <p>
+ * The {@link #createExtent(EClass, AtomicBoolean) extent} of a {@link EClass class} X is the set of all {@link EObject objects} with <code>object.getEClass() == X</code>.
+ *
+ * @author Eike Stepper
+ */
+public class CDOExtentCreator implements OCLExtentCreator
+{
+ private CDOView view;
+
+ private CDOChangeSetData changeSetData;
+
+ private CDORevisionCacheAdder revisionCacheAdder;
+
+ public CDOExtentCreator(CDOView view)
+ {
+ this.view = view;
+ }
+
+ public CDOView getView()
+ {
+ return view;
+ }
+
+ public CDOChangeSetData getChangeSetData()
+ {
+ return changeSetData;
+ }
+
+ public void setChangeSetData(CDOChangeSetData changeSetData)
+ {
+ this.changeSetData = changeSetData;
+ }
+
+ public CDORevisionCacheAdder getRevisionCacheAdder()
+ {
+ return revisionCacheAdder;
+ }
+
+ public void setRevisionCacheAdder(CDORevisionCacheAdder revisionCacheAdder)
+ {
+ this.revisionCacheAdder = revisionCacheAdder;
+ }
+
+ public Set<EObject> createExtent(EClass eClass, AtomicBoolean canceled)
+ {
+ IStoreAccessor accessor = StoreThreadLocal.getAccessor();
+ CDOBranch branch = view.getBranch();
+ long timeStamp = view.getTimeStamp();
+ return createExtent(eClass, accessor, branch, timeStamp, canceled);
+ }
+
+ protected Set<EObject> createExtent(EClass eClass, IStoreAccessor accessor, CDOBranch branch, long timeStamp,
+ final AtomicBoolean canceled)
+ {
+ final Set<EObject> extent = new HashSet<EObject>();
+ if (changeSetData != null)
+ {
+ List<CDOIDAndVersion> newObjects = changeSetData.getNewObjects();
+ if (newObjects != null)
+ {
+ for (CDOIDAndVersion key : newObjects)
+ {
+ EObject object = getEObject(key.getID());
+ if (object != null)
+ {
+ extent.add(object);
+ }
+ }
+ }
+ }
+
+ accessor.handleRevisions(eClass, branch, timeStamp, false, new CDORevisionHandler.Filtered.Undetached(
+ new CDORevisionHandler()
+ {
+ public boolean handleRevision(CDORevision revision)
+ {
+ if (revisionCacheAdder != null)
+ {
+ revisionCacheAdder.addRevision(revision);
+ }
+
+ CDOID id = revision.getID();
+ if (!isDetached(id))
+ {
+ EObject object = getEObject(id);
+ if (object != null)
+ {
+ extent.add(object);
+ }
+ }
+
+ return !canceled.get();
+ }
+ }));
+
+ return extent;
+ }
+
+ protected boolean isDetached(CDOID id)
+ {
+ if (changeSetData == null)
+ {
+ return false;
+ }
+
+ CDOChangeKind changeKind = changeSetData.getChangeKind(id);
+ return changeKind == CDOChangeKind.DETACHED;
+ }
+
+ protected EObject getEObject(CDOID id) throws ObjectNotFoundException
+ {
+ InternalCDOObject object = (InternalCDOObject)view.getObject(id);
+ if (object == null)
+ {
+ throw new ObjectNotFoundException(id);
+ }
+
+ return object.cdoInternalInstance();
+ }
+
+ /**
+ * An {@link CDOExtentCreator extent creator} that creates extent sets which support a lazy populating iterator.
+ *
+ * @author Eike Stepper
+ */
+ public static class Lazy extends CDOExtentCreator
+ {
+ public Lazy(CDOView view)
+ {
+ super(view);
+ }
+
+ @Override
+ protected Set<EObject> createExtent(final EClass eClass, final IStoreAccessor accessor, final CDOBranch branch,
+ final long timeStamp, final AtomicBoolean canceled)
+ {
+ return new Set<EObject>()
+ {
+ private Iterator<EObject> emptyIterator;
+
+ private Boolean empty;
+
+ private CountDownLatch emptyKnown = new CountDownLatch(1);
+
+ public synchronized boolean isEmpty()
+ {
+ if (empty != null)
+ {
+ return empty;
+ }
+
+ emptyIterator = iterator();
+
+ try
+ {
+ emptyKnown.await();
+ return empty;
+ }
+ catch (InterruptedException ex)
+ {
+ throw new Error("Interrupted");
+ }
+ }
+
+ public synchronized Iterator<EObject> iterator()
+ {
+ if (emptyIterator != null)
+ {
+ Iterator<EObject> it = emptyIterator;
+ emptyIterator = null;
+ return it;
+ }
+
+ final Object mutex = new Object();
+ final LinkedList<CDOID> ids = new LinkedList<CDOID>();
+ final boolean[] done = { false };
+
+ Thread thread = new Thread("OCLExtentIterator")
+ {
+ @Override
+ public void run()
+ {
+ handleDirtyState();
+ handlePersistentState();
+
+ synchronized (mutex)
+ {
+ done[0] = true;
+ mutex.notify();
+ }
+
+ if (empty == null)
+ {
+ empty = true;
+ emptyKnown.countDown();
+ }
+ }
+
+ private void handleDirtyState()
+ {
+ CDOChangeSetData changeSetData = getChangeSetData();
+ if (changeSetData != null)
+ {
+ List<CDOIDAndVersion> newObjects = changeSetData.getNewObjects();
+ if (newObjects != null)
+ {
+ for (CDOIDAndVersion key : newObjects)
+ {
+ enqueue(key.getID());
+ }
+ }
+ }
+ }
+
+ private void handlePersistentState()
+ {
+ accessor.handleRevisions(eClass, branch, timeStamp, false, new CDORevisionHandler.Filtered.Undetached(
+ new CDORevisionHandler()
+ {
+ public boolean handleRevision(CDORevision revision)
+ {
+ empty = false;
+ emptyKnown.countDown();
+
+ CDORevisionCacheAdder revisionCacheAdder = getRevisionCacheAdder();
+ if (revisionCacheAdder != null)
+ {
+ revisionCacheAdder.addRevision(revision);
+ }
+
+ CDOID id = revision.getID();
+ if (!isDetached(id))
+ {
+ enqueue(id);
+ }
+
+ return !canceled.get();
+ }
+ }));
+ }
+
+ private void enqueue(CDOID id)
+ {
+ synchronized (mutex)
+ {
+ ids.addLast(id);
+ mutex.notify();
+ }
+ }
+ };
+
+ thread.setDaemon(true);
+ thread.start();
+
+ return new Iterator<EObject>()
+ {
+ private CDOID next;
+
+ public boolean hasNext()
+ {
+ while (next == null)
+ {
+ if (canceled.get())
+ {
+ return false;
+ }
+
+ synchronized (mutex)
+ {
+ if (ids.isEmpty())
+ {
+ if (done[0])
+ {
+ return false;
+ }
+
+ try
+ {
+ mutex.wait();
+ }
+ catch (InterruptedException ex)
+ {
+ throw new Error(ex);
+ }
+ }
+ else
+ {
+ next = ids.removeFirst();
+ }
+ }
+ }
+
+ return true;
+ }
+
+ public EObject next()
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+
+ try
+ {
+ return getEObject(next);
+ }
+ finally
+ {
+ next = null;
+ }
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ public int size()
+ {
+ throw new Error("Not supported"); // RuntimeException gets swallowed up the stack!
+ }
+
+ public boolean contains(Object o)
+ {
+ throw new Error("Not supported");
+ }
+
+ public Object[] toArray()
+ {
+ throw new Error("Not supported");
+ }
+
+ public <T> T[] toArray(T[] a)
+ {
+ throw new Error("Not supported");
+ }
+
+ public boolean add(EObject o)
+ {
+ throw new Error("Not supported");
+ }
+
+ public boolean remove(Object o)
+ {
+ throw new Error("Not supported");
+ }
+
+ public boolean containsAll(Collection<?> c)
+ {
+ throw new Error("Not supported");
+ }
+
+ public boolean addAll(Collection<? extends EObject> c)
+ {
+ throw new Error("Not supported");
+ }
+
+ public boolean retainAll(Collection<?> c)
+ {
+ throw new Error("Not supported");
+ }
+
+ public boolean removeAll(Collection<?> c)
+ {
+ throw new Error("Not supported");
+ }
+
+ public void clear()
+ {
+ throw new Error("Not supported");
+ }
+ };
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentMap.java b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentMap.java
index c7c65e6706..2a44a3bee6 100644
--- a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentMap.java
+++ b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentMap.java
@@ -1,138 +1,142 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.ocl;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * @author Eike Stepper
- */
-public class CDOExtentMap implements Map<EClass, Set<? extends EObject>>
-{
- private final Map<EClass, Set<? extends EObject>> delegate = new java.util.HashMap<EClass, Set<? extends EObject>>();
-
- private final OCLExtentCreator extentCreator;
-
- private AtomicBoolean canceled = new AtomicBoolean(false);
-
- public CDOExtentMap(OCLExtentCreator extentCreator)
- {
- this.extentCreator = extentCreator;
- }
-
- public void cancel()
- {
- canceled.set(true);
- }
-
- public Set<? extends EObject> get(Object key)
- {
- if (key instanceof EClass)
- {
- EClass cls = (EClass)key;
-
- // TODO: Optimize by parsing ahead of time to find all EClasses that we will query
- Set<? extends EObject> result = delegate.get(cls);
- if (result == null)
- {
- result = extentCreator.createExtent(cls, canceled);
- delegate.put(cls, result);
- }
-
- return result;
- }
-
- return null;
- }
-
- //
- // Strictly delegating methods
- //
-
- public void clear()
- {
- delegate.clear();
- }
-
- public boolean containsKey(Object key)
- {
- return delegate.containsKey(key);
- }
-
- public boolean containsValue(Object value)
- {
- return delegate.containsValue(value);
- }
-
- public Set<Map.Entry<EClass, Set<? extends EObject>>> entrySet()
- {
- return delegate.entrySet();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- return delegate.equals(obj);
- }
-
- @Override
- public int hashCode()
- {
- return delegate.hashCode();
- }
-
- public boolean isEmpty()
- {
- return delegate.isEmpty();
- }
-
- public Set<EClass> keySet()
- {
- return delegate.keySet();
- }
-
- public Set<? extends EObject> put(EClass key, Set<? extends EObject> value)
- {
- return delegate.put(key, value);
- }
-
- public void putAll(Map<? extends EClass, ? extends Set<? extends EObject>> t)
- {
- delegate.putAll(t);
- }
-
- public Set<? extends EObject> remove(Object key)
- {
- return delegate.remove(key);
- }
-
- public int size()
- {
- return delegate.size();
- }
-
- @Override
- public String toString()
- {
- return delegate.toString();
- }
-
- public Collection<Set<? extends EObject>> values()
- {
- return delegate.values();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.ocl;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Maps {@link EClass classes} to their extents.
+ * <p>
+ * The {@link #get(Object) extent} of a {@link EClass class} X is the set of all {@link EObject objects} with <code>object.getEClass() == X</code>.
+ *
+ * @author Eike Stepper
+ */
+public class CDOExtentMap implements Map<EClass, Set<? extends EObject>>
+{
+ private final Map<EClass, Set<? extends EObject>> delegate = new java.util.HashMap<EClass, Set<? extends EObject>>();
+
+ private final OCLExtentCreator extentCreator;
+
+ private AtomicBoolean canceled = new AtomicBoolean(false);
+
+ public CDOExtentMap(OCLExtentCreator extentCreator)
+ {
+ this.extentCreator = extentCreator;
+ }
+
+ public void cancel()
+ {
+ canceled.set(true);
+ }
+
+ public Set<? extends EObject> get(Object key)
+ {
+ if (key instanceof EClass)
+ {
+ EClass cls = (EClass)key;
+
+ // TODO: Optimize by parsing ahead of time to find all EClasses that we will query
+ Set<? extends EObject> result = delegate.get(cls);
+ if (result == null)
+ {
+ result = extentCreator.createExtent(cls, canceled);
+ delegate.put(cls, result);
+ }
+
+ return result;
+ }
+
+ return null;
+ }
+
+ //
+ // Strictly delegating methods
+ //
+
+ public void clear()
+ {
+ delegate.clear();
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return delegate.containsKey(key);
+ }
+
+ public boolean containsValue(Object value)
+ {
+ return delegate.containsValue(value);
+ }
+
+ public Set<Map.Entry<EClass, Set<? extends EObject>>> entrySet()
+ {
+ return delegate.entrySet();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return delegate.equals(obj);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return delegate.hashCode();
+ }
+
+ public boolean isEmpty()
+ {
+ return delegate.isEmpty();
+ }
+
+ public Set<EClass> keySet()
+ {
+ return delegate.keySet();
+ }
+
+ public Set<? extends EObject> put(EClass key, Set<? extends EObject> value)
+ {
+ return delegate.put(key, value);
+ }
+
+ public void putAll(Map<? extends EClass, ? extends Set<? extends EObject>> t)
+ {
+ delegate.putAll(t);
+ }
+
+ public Set<? extends EObject> remove(Object key)
+ {
+ return delegate.remove(key);
+ }
+
+ public int size()
+ {
+ return delegate.size();
+ }
+
+ @Override
+ public String toString()
+ {
+ return delegate.toString();
+ }
+
+ public Collection<Set<? extends EObject>> values()
+ {
+ return delegate.values();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLExtentCreator.java b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLExtentCreator.java
index 739a88440e..0856af34b9 100644
--- a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLExtentCreator.java
+++ b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLExtentCreator.java
@@ -1,25 +1,29 @@
-/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.ocl;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * @author Eike Stepper
- */
-public interface OCLExtentCreator
-{
- public Set<EObject> createExtent(EClass cls, AtomicBoolean canceled);
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.ocl;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Creates extents of {@link EClass classes}.
+ * <p>
+ * The {@link #createExtent(EClass, AtomicBoolean) extent} of a {@link EClass class} X is the set of all {@link EObject objects} with <code>object.getEClass() == X</code>.
+ *
+ * @author Eike Stepper
+ */
+public interface OCLExtentCreator
+{
+ public Set<EObject> createExtent(EClass cls, AtomicBoolean canceled);
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java
index 03eb11f66c..6363c144aa 100644
--- a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/OCLQueryHandler.java
@@ -66,6 +66,8 @@ import java.util.Map.Entry;
import java.util.Set;
/**
+ * A {@link IQueryHandler query handler} that evaluates OCL query expressions.
+ *
* @author Eike Stepper
*/
public class OCLQueryHandler implements IQueryHandler
@@ -373,6 +375,8 @@ public class OCLQueryHandler implements IQueryHandler
}
/**
+ * Creates {@link OCLQueryHandler} instances.
+ *
* @author Eike Stepper
*/
public static class Factory extends QueryHandlerFactory

Back to the top