Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon McDuff2008-06-09 16:03:57 +0000
committerSimon McDuff2008-06-09 16:03:57 +0000
commit1d6e5bf222dcec712ea6d0e594adb6875626ebc4 (patch)
tree97a62bf3269950359d67556ff9abe40935d23e13
parent0126f40457f63e4cd642858079c5eaf647de756f (diff)
downloadcdo-1d6e5bf222dcec712ea6d0e594adb6875626ebc4.tar.gz
cdo-1d6e5bf222dcec712ea6d0e594adb6875626ebc4.tar.xz
cdo-1d6e5bf222dcec712ea6d0e594adb6875626ebc4.zip
[233273] [QUERY] Develop Query mechanism
https://bugs.eclipse.org/bugs/show_bug.cgi?id=233273 NOT COMPLETED
-rw-r--r--plugins/org.eclipse.emf.cdo.common/META-INF/MANIFEST.MF38
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/CDOQueryParameter.java25
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultReaderQueue.java22
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultWriterQueue.java23
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOInstanceUtil.java127
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PollIterator.java56
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java90
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/StateConcurrentQueue.java67
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOAbstractQueryResultImpl.java74
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryParameterImpl.java89
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryState.java22
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreReader.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java17
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java41
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreQueryExecution.java105
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryManager.java197
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryResult.java79
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/QueryCancelIndication.java72
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/QueryIndication.java111
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/QueryTest.java198
-rw-r--r--plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/query/CDOQuery.java47
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/query/CDOQueryResult.java21
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java10
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryCancelRequest.java64
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryRequest.java133
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java155
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java124
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/ECDOIDList.java192
38 files changed, 2242 insertions, 27 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.common/META-INF/MANIFEST.MF
index 528d9d80cc..fef59739d3 100644
--- a/plugins/org.eclipse.emf.cdo.common/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.common/META-INF/MANIFEST.MF
@@ -11,21 +11,23 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
Require-Bundle: org.eclipse.net4j;bundle-version="[1.0.0,2.0.0)";visibility:=reexport
Import-Package: org.osgi.framework;version="1.3.0";resolution:=optional
-Export-Package: org.eclipse.emf.cdo.common;version="1.0.0",
- org.eclipse.emf.cdo.common.analyzer;version="1.0.0",
- org.eclipse.emf.cdo.common.id;version="1.0.0",
- org.eclipse.emf.cdo.common.model;version="1.0.0",
- org.eclipse.emf.cdo.common.model.core;version="1.0.0",
- org.eclipse.emf.cdo.common.model.resource;version="1.0.0",
- org.eclipse.emf.cdo.common.revision;version="1.0.0",
- org.eclipse.emf.cdo.common.revision.delta;version="1.0.0",
- org.eclipse.emf.cdo.common.util;version="1.0.0",
- org.eclipse.emf.cdo.internal.common;version="1.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
- org.eclipse.emf.cdo.internal.common.bundle;version="1.0.0";x-internal:=true,
- org.eclipse.emf.cdo.internal.common.id;version="1.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
- org.eclipse.emf.cdo.internal.common.model;version="1.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
- org.eclipse.emf.cdo.internal.common.model.core;version="1.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
- org.eclipse.emf.cdo.internal.common.model.resource;version="1.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
- org.eclipse.emf.cdo.internal.common.revision;version="1.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
- org.eclipse.emf.cdo.internal.common.revision.delta;version="1.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
- org.eclipse.emf.cdo.spi.common;version="1.0.0"
+Export-Package: org.eclipse.emf.cdo.common;version="2.0.0",
+ org.eclipse.emf.cdo.common.analyzer;version="2.0.0",
+ org.eclipse.emf.cdo.common.id;version="2.0.0",
+ org.eclipse.emf.cdo.common.model;version="2.0.0",
+ org.eclipse.emf.cdo.common.model.core;version="2.0.0",
+ org.eclipse.emf.cdo.common.model.resource;version="2.0.0",
+ org.eclipse.emf.cdo.common.query;version="2.0.0",
+ org.eclipse.emf.cdo.common.revision;version="2.0.0",
+ org.eclipse.emf.cdo.common.revision.delta;version="2.0.0",
+ org.eclipse.emf.cdo.common.util;version="2.0.0",
+ org.eclipse.emf.cdo.internal.common;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
+ org.eclipse.emf.cdo.internal.common.bundle;version="2.0.0";x-internal:=true,
+ org.eclipse.emf.cdo.internal.common.id;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
+ org.eclipse.emf.cdo.internal.common.model;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
+ org.eclipse.emf.cdo.internal.common.model.core;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
+ org.eclipse.emf.cdo.internal.common.model.resource;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
+ org.eclipse.emf.cdo.internal.common.query;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
+ org.eclipse.emf.cdo.internal.common.revision;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
+ org.eclipse.emf.cdo.internal.common.revision.delta;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests,org.eclipse.emf.cdo,org.eclipse.emf.cdo.server",
+ org.eclipse.emf.cdo.spi.common;version="2.0.0"
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java
index f849caf4d5..b59761beed 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java
@@ -44,6 +44,10 @@ public interface CDOProtocolConstants
public static final short SIGNAL_COMMIT_TRANSACTION = 13;
public static final short SIGNAL_INVALIDATION = 14;
+
+ public static final short SIGNAL_QUERY = 15;
+
+ public static final short SIGNAL_QUERY_CANCEL = 16;
public static final int ERROR_REPOSITORY_NOT_FOUND = -1;
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/CDOQueryParameter.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/CDOQueryParameter.java
new file mode 100644
index 0000000000..7d809bf2ca
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/CDOQueryParameter.java
@@ -0,0 +1,25 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Simon McDuff, Canada.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.common.query;
+
+import java.util.Map;
+
+/**
+ * @author Simon McDuff
+ */
+public interface CDOQueryParameter
+{
+ String getQueryLanguage();
+
+ String getQueryString();
+
+ Map<String, Object> getParameters();
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultReaderQueue.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultReaderQueue.java
new file mode 100644
index 0000000000..5cd3cc46a7
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultReaderQueue.java
@@ -0,0 +1,22 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.common.query;
+
+import org.eclipse.net4j.util.collection.CloseableIterator;
+
+import java.util.concurrent.Future;
+
+/**
+ * @author Simon McDuff
+ */
+public interface ResultReaderQueue<T> extends CloseableIterator<T>, Future<T>
+{
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultWriterQueue.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultWriterQueue.java
new file mode 100644
index 0000000000..95cb98cfd1
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultWriterQueue.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.common.query;
+
+import java.util.Queue;
+
+/**
+ * @author Simon McDuff
+ */
+public interface ResultWriterQueue<E> extends Queue<E>
+{
+ void setException(RuntimeException exception);
+
+ void release();
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOInstanceUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOInstanceUtil.java
new file mode 100644
index 0000000000..ff691e038e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOInstanceUtil.java
@@ -0,0 +1,127 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.common.util;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDObjectFactory;
+import org.eclipse.emf.cdo.common.model.CDOClass;
+import org.eclipse.emf.cdo.common.model.CDOModelUtil;
+import org.eclipse.emf.cdo.common.model.CDOPackageManager;
+import org.eclipse.emf.cdo.common.model.CDOType;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+
+import org.eclipse.net4j.util.io.ExtendedDataInput;
+import org.eclipse.net4j.util.io.ExtendedDataOutput;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Simon McDuff
+ */
+public class CDOInstanceUtil
+{
+ public static Map<Class<?>, CDOType> idTypes = new HashMap<Class<?>, CDOType>();
+ static
+ {
+ idTypes.put(String.class, CDOType.STRING);
+ idTypes.put(Boolean.class, CDOType.BOOLEAN);
+ idTypes.put(Date.class, CDOType.DATE);
+ idTypes.put(Long.class, CDOType.LONG);
+ idTypes.put(Integer.class, CDOType.INT);
+ idTypes.put(Double.class, CDOType.DOUBLE);
+ idTypes.put(Byte.class, CDOType.BYTE);
+ }
+
+ private CDOInstanceUtil()
+ {
+
+ }
+
+ /**
+ * @param out
+ * @param id
+ * @throws IOException
+ */
+ static public void writeObject(ExtendedDataOutput out, Object id) throws IOException
+ {
+ if (id instanceof CDOClass)
+ {
+ out.writeByte(0);
+ CDOModelUtil.writeClassRef(out, ((CDOClass)id).createClassRef(), null);
+ return;
+ }
+
+ out.writeByte(1);
+
+ writeInstance(out, id);
+
+ }
+ /**
+ * @param out
+ * @param id
+ * @throws IOException
+ */
+ static public void writeInstance(ExtendedDataOutput out, Object id) throws IOException
+ {
+ if (id == null)
+ {
+ id = CDOID.NULL;
+ }
+ else if (id instanceof CDORevision)
+ {
+ id = ((CDORevision)id).getID();
+ }
+
+ CDOType type = null;
+
+ if (id instanceof CDOID)
+ {
+ type = CDOType.OBJECT;
+ }
+ else
+ {
+ type = idTypes.get(id.getClass());
+ }
+
+ if (type == null) throw new IllegalStateException("No type for object " + id.getClass());
+
+ CDOModelUtil.writeType(out, type);
+ type.writeValue(out, id);
+ }
+ /**
+ * @param out
+ * @param id
+ * @throws IOException
+ */
+ static public Object readInstance(ExtendedDataInput in, CDOIDObjectFactory objectFactory) throws IOException
+ {
+ CDOType type = CDOModelUtil.readType(in);
+ return type.readValue(in, objectFactory);
+ }
+
+ static public Object readObject(ExtendedDataInput in, CDOIDObjectFactory objectFactory, CDOPackageManager packageManager) throws IOException
+ {
+ byte value = in.readByte();
+
+ if (value == 0)
+ {
+ return CDOModelUtil.readClassRef(in).resolve(packageManager);
+ }
+ else if (value == 1)
+ {
+ readInstance(in, objectFactory);
+ }
+ throw new IllegalStateException();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PollIterator.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PollIterator.java
new file mode 100644
index 0000000000..d3012ca2df
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PollIterator.java
@@ -0,0 +1,56 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.common.util;
+
+import java.util.Iterator;
+
+/**
+ * @author Simon McDuff
+ */
+public class PollIterator<E> implements Iterator<E>
+{
+ private StateConcurrentQueue<E> queue;
+
+ public PollIterator(StateConcurrentQueue<E> queue)
+ {
+ this.queue = queue;
+ }
+
+ public boolean hasNext()
+ {
+ while (true)
+ {
+ if (!queue.isEmpty()) return true;
+
+ if (queue.isDone() && queue.isEmpty()) return false;
+
+ try
+ {
+ Thread.sleep(10);
+ }
+ catch (InterruptedException ex)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ }
+
+ public E next()
+ {
+ return queue.poll();
+ }
+
+ public void remove()
+ {
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java
new file mode 100644
index 0000000000..332af6c9e8
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java
@@ -0,0 +1,90 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.common.util;
+
+
+/**
+ * @author Simon McDuff
+ */
+public class PropertyChanged<T>
+{
+ Object notifier = new Object();
+
+ T value;
+
+ RuntimeException exception = null;
+
+ public PropertyChanged(T value)
+ {
+ this.value = value;
+ }
+
+ public T get()
+ {
+ return value;
+ }
+
+ public void set(T newValue)
+ {
+ synchronized(notifier)
+ {
+ value = newValue;
+ notifier.notifyAll();
+ }
+ }
+
+ public void setException(RuntimeException exception)
+ {
+ synchronized(notifier)
+ {
+ this.exception = exception;
+ notifier.notifyAll();
+ }
+ }
+
+ public void acquire(Object accept, Object refuse)
+ {
+ acquire(accept, refuse, 0);
+ }
+
+ public void acquire(Object accept, Object refuse, long timeout)
+ {
+ synchronized(notifier)
+ {
+ while (!equalToOneElement(accept, refuse))
+ {
+ try
+ {
+ notifier.wait(timeout);
+ }
+ catch (InterruptedException ex)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ }
+
+ private boolean equalToOneElement(Object accept, Object refuse)
+ {
+ if (this.exception != null)
+ throw this.exception;
+
+ if (accept != null && accept.equals(value))
+ return true;
+
+ if (refuse != null && refuse.equals(value))
+ throw new IllegalStateException();
+
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/StateConcurrentQueue.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/StateConcurrentQueue.java
new file mode 100644
index 0000000000..ebe812848f
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/StateConcurrentQueue.java
@@ -0,0 +1,67 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.common.util;
+
+import org.eclipse.emf.cdo.common.query.ResultWriterQueue;
+
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+/**
+ * @author Simon McDuff
+ */
+public class StateConcurrentQueue<E> extends ConcurrentLinkedQueue<E> implements ResultWriterQueue<E>
+{
+ private static final long serialVersionUID = 1L;
+
+ private boolean done = false;
+
+ private RuntimeException exception = null;
+
+ public StateConcurrentQueue()
+ {
+ }
+
+ public void setRuntimeException(RuntimeException exception)
+ {
+ this.exception = exception;
+ }
+
+ public E poll()
+ {
+ if (exception != null) throw exception;
+
+ return super.poll();
+ }
+
+ public boolean isDone()
+ {
+ return done;
+ }
+
+ public void release()
+ {
+ done = true;
+ }
+
+ public void setException(RuntimeException exception)
+ {
+ this.exception = exception;
+ }
+
+ public void isReleased()
+ {
+ synchronized(this)
+ {
+
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOAbstractQueryResultImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOAbstractQueryResultImpl.java
new file mode 100644
index 0000000000..8c7e0cc871
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOAbstractQueryResultImpl.java
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.internal.common.query;
+
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
+import org.eclipse.emf.cdo.common.query.ResultReaderQueue;
+import org.eclipse.emf.cdo.common.query.ResultWriterQueue;
+import org.eclipse.emf.cdo.common.util.PollIterator;
+import org.eclipse.emf.cdo.common.util.StateConcurrentQueue;
+
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+/**
+ * @author Simon McDuff
+ */
+public abstract class CDOAbstractQueryResultImpl<T> extends Lifecycle implements ResultReaderQueue<T>
+{
+ protected long queryID = -1;
+
+ protected CDOQueryParameter cdoQueryParameter;
+
+ protected StateConcurrentQueue<Object> queue = new StateConcurrentQueue<Object>();
+
+ protected Iterator<Object> nextObject = new PollIterator<Object>(queue);
+
+ public CDOAbstractQueryResultImpl(CDOQueryParameter cdoQueryParameter)
+ {
+ this.cdoQueryParameter = cdoQueryParameter;
+ }
+
+ public ResultWriterQueue<Object> getResultQueue()
+ {
+ return queue;
+ }
+
+ public void setQueryID(long queryID)
+ {
+ this.queryID = queryID;
+ }
+
+ public boolean isDone()
+ {
+ return queue.isDone();
+ }
+
+ public long getQueryID()
+ {
+ return queryID;
+ }
+
+ public List<T> getAsList()
+ {
+ ArrayList<T> result = new ArrayList<T>();
+ while (hasNext())
+ {
+ result.add(next());
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryParameterImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryParameterImpl.java
new file mode 100644
index 0000000000..746f5f4434
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryParameterImpl.java
@@ -0,0 +1,89 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.internal.common.query;
+
+import org.eclipse.emf.cdo.common.id.CDOIDObjectFactory;
+import org.eclipse.emf.cdo.common.model.CDOPackageManager;
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
+import org.eclipse.emf.cdo.common.util.CDOInstanceUtil;
+
+import org.eclipse.net4j.util.io.ExtendedDataInput;
+import org.eclipse.net4j.util.io.ExtendedDataOutput;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+/**
+ * @author Simon McDuff
+ */
+public class CDOQueryParameterImpl implements CDOQueryParameter
+{
+ private String queryLanguage;
+
+ private String queryString;
+
+ private Map<String, Object> parameters = new HashMap<String, Object>();
+
+ public CDOQueryParameterImpl(String language, String queryString)
+ {
+ this.queryLanguage = language;
+ this.queryString = queryString;
+ }
+
+ public CDOQueryParameterImpl(ExtendedDataInput in, CDOIDObjectFactory objectFactory, CDOPackageManager packageManager) throws IOException
+ {
+ queryLanguage = in.readString();
+ queryString = in.readString();
+ int size = in.readInt();
+ for (int i =0; i< size; i++)
+ {
+ String key = in.readString();
+ Object object = CDOInstanceUtil.readObject(in, objectFactory, packageManager);
+ parameters.put(key, object);
+ }
+
+ //CDOClassRef classRef = new CDOClassRefImpl(in,null);
+ //rootClass = (CDOClassImpl)classRef.resolve(packageManager);
+
+ }
+
+ public void write(ExtendedDataOutput out) throws IOException
+ {
+ out.writeString(queryLanguage);
+ out.writeString(queryString);
+
+ out.writeInt(parameters.size());
+ for (Entry<String, Object> entry : parameters.entrySet())
+ {
+ out.writeString(entry.getKey());
+ Object value = entry.getValue();
+ CDOInstanceUtil.writeObject(out, value);
+ }
+ }
+
+
+
+ public String getQueryString()
+ {
+ return queryString;
+ }
+
+ public String getQueryLanguage()
+ {
+ return this.queryLanguage;
+ }
+
+ public Map<String, Object> getParameters()
+ {
+ return parameters;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryState.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryState.java
new file mode 100644
index 0000000000..8bd3b608e1
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryState.java
@@ -0,0 +1,22 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.internal.common.query;
+
+/**
+ * @author Simon McDuff
+ */
+public enum CDOQueryState
+{
+ INIT,
+ ACTIVAT,
+ DONE,
+ CANCEL
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreReader.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreReader.java
index 892b4327ee..a2ff483f36 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreReader.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreReader.java
@@ -21,6 +21,7 @@ import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.common.model.CDOPackage;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
import org.eclipse.emf.cdo.common.model.CDOType;
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.server.IPackageManager;
@@ -290,4 +291,9 @@ public class DBStoreReader extends DBStoreAccessor implements IDBStoreReader
CDOClassRef type = readObjectType(id);
return type.resolve(packageManager);
}
+
+ public CloseableIterator<Object> createQueryIterator(CDOQueryParameter queryParameter)
+ {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server/META-INF/MANIFEST.MF
index efb0325a7c..1b0d6948f3 100644
--- a/plugins/org.eclipse.emf.cdo.server/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server/META-INF/MANIFEST.MF
@@ -10,7 +10,8 @@ Bundle-Activator: org.eclipse.emf.cdo.internal.server.bundle.OM$Activator
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)";resolution:=optional,
- org.eclipse.emf.cdo.protocol;bundle-version="[2.0.0,3.0.0)";visibility:=reexport
+ org.eclipse.emf.cdo.common;bundle-version="[2.0.0,3.0.0)";visibility:=reexport
Export-Package: org.eclipse.emf.cdo.internal.server;version="2.0.0",
- org.eclipse.emf.cdo.internal.server.protocol;version="2.0.0",
+ org.eclipse.emf.cdo.internal.server.bundle;version="2.0.0";x-internal:=true,
+ org.eclipse.emf.cdo.internal.server.protocol;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests",
org.eclipse.emf.cdo.server;version="2.0.0"
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java
index e43e8a4678..94b5f1c42a 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java
@@ -8,6 +8,9 @@
* Contributors:
* Simon McDuff - initial API and implementation
* Eike Stepper - maintenance
+ * Simon McDuff - 233273: [QUERY] Develop Query mechanism
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=233273
+ *
**************************************************************************/
package org.eclipse.emf.cdo.internal.server;
@@ -212,4 +215,18 @@ public class MEMStore extends LongIDStore
return null;
}
+
+ public List<CDORevision> getRevisions()
+ {
+ ArrayList<CDORevision> simpleRevisions = new ArrayList<CDORevision>();
+ Iterator<List<CDORevision>> itr = revisions.values().iterator();
+ while (itr.hasNext())
+ {
+ List<CDORevision> list = itr.next();
+ CDORevision revision = list.get(list.size() - 1);
+ simpleRevisions.add(revision);
+ }
+ return simpleRevisions;
+ }
+
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java
index 766a281adb..09fe189faf 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java
@@ -11,11 +11,14 @@
**************************************************************************/
package org.eclipse.emf.cdo.internal.server;
+
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.model.CDOClassRef;
import org.eclipse.emf.cdo.common.model.CDOFeature;
import org.eclipse.emf.cdo.common.model.CDOPackage;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
@@ -180,4 +183,42 @@ public class MEMStoreAccessor extends StoreAccessor implements IStoreReader, ISt
{
newRevisions.clear();
}
+
+ public CloseableIterator<Object> createQueryIterator(CDOQueryParameter queryParameter)
+ {
+ if (queryParameter.getQueryLanguage().equals("TEST"))
+ {
+ // queryParameter.getQueryString().equals("SLOW");
+ MEMStoreQueryExecution queryExecution = new MEMStoreQueryExecution(this.getStore());
+
+ Object context = queryParameter.getParameters().get("context");
+
+ if (context != null)
+ {
+ if (context instanceof CDOClass)
+ {
+ final CDOClass cdoClass = (CDOClass)context;
+
+ queryExecution.addFilter(new Object()
+ {
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ CDORevision revision = (CDORevision)obj;
+ return revision.getCDOClass().equals( cdoClass );
+ }
+
+ }
+ );
+ }
+ }
+
+ queryExecution.activate();
+
+ return queryExecution;
+ }
+ throw new RuntimeException("Unsupported language " + queryParameter.getQueryLanguage());
+
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreQueryExecution.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreQueryExecution.java
new file mode 100644
index 0000000000..466232d961
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreQueryExecution.java
@@ -0,0 +1,105 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.internal.server;
+
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+
+import org.eclipse.net4j.util.collection.CloseableIterator;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * @author Simon McDuff
+ */
+public class MEMStoreQueryExecution implements CloseableIterator<Object>
+{
+ private MEMStore store = null;
+
+ Iterator<CDORevision> revisions;
+
+ Object nextObject = null;
+
+ ArrayList<Object> filters = new ArrayList<Object>();
+
+ public MEMStoreQueryExecution(MEMStore memStore)
+ {
+ store = memStore;
+ revisions = store.getRevisions().iterator();
+ }
+
+ public void addFilter(Object filter)
+ {
+ filters.add(filter);
+ }
+
+ public void activate()
+ {
+ nextObject = nextObject();
+ }
+
+ public Object nextObject()
+ {
+ nextObject = null;
+
+ while (revisions.hasNext() && nextObject == null)
+ {
+ nextObject = revisions.next();
+
+ for (Object filter : filters)
+ {
+ if (!filter.equals(nextObject))
+ {
+ nextObject = null;
+ break;
+ }
+ }
+ }
+ return nextObject;
+ }
+
+ public boolean hasNext()
+ {
+ try
+ {
+ Thread.sleep(500);
+ }
+ catch (InterruptedException ex)
+ {
+ Thread.currentThread().interrupt();
+ }
+
+ return nextObject != null;
+ }
+
+ public Object next()
+ {
+ try
+ {
+ return nextObject;
+ }
+ finally
+ {
+ nextObject = nextObject();
+ }
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void close()
+ {
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java
index 56e4acfb2f..7ac03a84b9 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java
@@ -7,6 +7,8 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Simon McDuff - 233273: [QUERY] Develop Query mechanism
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=233273
**************************************************************************/
package org.eclipse.emf.cdo.internal.server;
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java
index 89576f1a21..aecff28caa 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.model.CDOClassRef;
import org.eclipse.emf.cdo.common.model.CDOFeature;
import org.eclipse.emf.cdo.common.model.CDOPackage;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStoreChunkReader;
@@ -97,4 +98,9 @@ public class NOOPStoreAccessor extends StoreAccessor implements IStoreReader, IS
{
throw new UnsupportedOperationException();
}
+
+ public CloseableIterator<Object> createQueryIterator(CDOQueryParameter queryParameter)
+ {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryManager.java
new file mode 100644
index 0000000000..d4cb15d494
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryManager.java
@@ -0,0 +1,197 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.internal.server;
+
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
+import org.eclipse.emf.cdo.common.query.ResultWriterQueue;
+import org.eclipse.emf.cdo.internal.server.bundle.OM;
+import org.eclipse.emf.cdo.server.IStoreReader;
+import org.eclipse.emf.cdo.server.IView;
+import org.eclipse.emf.cdo.server.StoreUtil;
+
+import org.eclipse.net4j.util.collection.CloseableIterator;
+import org.eclipse.net4j.util.container.SingleDeltaContainerEvent;
+import org.eclipse.net4j.util.container.IContainerDelta.Kind;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+/**
+ * @author Simon McDuff
+ */
+public class QueryManager
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SESSION, QueryManager.class);
+
+ private Map<Long, QueryContext> queryContexts = new ConcurrentHashMap<Long, QueryContext>();
+
+ private Map<Long, Future<?>> associateThreads = new ConcurrentHashMap<Long, Future<?>>();
+
+ private ExecutorService executors = Executors.newFixedThreadPool(10);
+
+ private long nextQuery = 0;
+
+ public QueryManager()
+ {
+ }
+
+ synchronized long nextQuery()
+ {
+ return nextQuery++;
+ }
+
+ private Future<?> execute(QueryContext queryContext)
+ {
+ Future<?> future = executors.submit(queryContext);
+
+ registerQueryNative(queryContext, future);
+
+ return future;
+ }
+
+ class QueryContext implements Runnable
+ {
+ QueryResult queryResult;
+
+ IListener listener = null;
+
+ IStoreReader reader = null;
+
+ public QueryContext(IStoreReader reader, QueryResult queryResult)
+ {
+ this.queryResult = queryResult;
+ this.reader = reader;
+ }
+
+ private void removeListener()
+ {
+ final IView view = (IView)getQueryResult().getView();
+ view.getSession().removeListener(listener);
+ listener = null;
+ }
+
+ private void addListener()
+ {
+ if (listener == null)
+ {
+ final IView view = (IView) getQueryResult().getView();
+
+ listener = new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof SingleDeltaContainerEvent)
+ {
+ SingleDeltaContainerEvent<?> deltaEvent = (SingleDeltaContainerEvent<?>)event;
+ if (deltaEvent.getDeltaKind() == Kind.REMOVED && deltaEvent.getDeltaElement() == view)
+ {
+ // Cancel the query when view is closing
+ cancel(getQueryResult().getQueryID());
+ }
+ }
+ }
+ };
+
+ // Add listener to the session
+ view.getSession().addListener(listener);
+ }
+ }
+
+ public void run()
+ {
+
+ CloseableIterator<Object> itrResult = reader.createQueryIterator(queryResult.getQueryParameter());
+
+ ResultWriterQueue<Object> resultQueue = queryResult.getResultWriterQueue();
+
+ try
+ {
+ while (itrResult.hasNext())
+ {
+ resultQueue.add(itrResult.next());
+ }
+ }
+ catch (RuntimeException exception)
+ {
+ resultQueue.setException(exception);
+ }
+ catch (Exception exception)
+ {
+ resultQueue.setException(new RuntimeException(exception));
+ }
+ finally
+ {
+ resultQueue.release();
+
+ itrResult.close();
+
+ unregisterQueryNative(this);
+
+ }
+ }
+
+ public QueryResult getQueryResult()
+ {
+ return queryResult;
+ }
+ }
+
+ public QueryResult execute(IView view, CDOQueryParameter queryParameter)
+ {
+
+ QueryResult queryResult = new QueryResult(view, queryParameter, nextQuery());
+
+ QueryContext queryContext = new QueryContext(StoreUtil.getReader(), queryResult);
+
+ execute(queryContext);
+
+ return queryResult;
+ }
+
+ public boolean isRunning(long queryID)
+ {
+ QueryContext queryContext = queryContexts.get(queryID);
+
+ return queryContext != null;
+ }
+
+ public void cancel(long queryID)
+ {
+ Future<?> queryContext = associateThreads.get(queryID);
+
+ if (queryContext == null || queryContext.isDone())
+ throw new RuntimeException("Query " + queryID + " is not running anymore");
+
+ if (TRACER.isEnabled()) TRACER.trace("Stopping QueryNative thread: " + queryContext);
+
+ queryContext.cancel(true);
+ }
+
+ synchronized public void registerQueryNative(final QueryContext queryContext, Future<?> future)
+ {
+ queryContexts.put(queryContext.getQueryResult().getQueryID(), queryContext);
+ associateThreads.put(queryContext.getQueryResult().getQueryID(), future);
+ queryContext.addListener();
+ }
+
+ synchronized public void unregisterQueryNative(final QueryContext queryContext)
+ {
+ queryContexts.remove(queryContext.getQueryResult().getQueryID());
+ associateThreads.remove(queryContext.getQueryResult().getQueryID());
+ queryContext.removeListener();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryResult.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryResult.java
new file mode 100644
index 0000000000..d7b34fa816
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/QueryResult.java
@@ -0,0 +1,79 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.internal.server;
+
+import org.eclipse.emf.cdo.common.CDOProtocolView;
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
+import org.eclipse.emf.cdo.common.query.ResultWriterQueue;
+import org.eclipse.emf.cdo.common.util.PollIterator;
+import org.eclipse.emf.cdo.common.util.StateConcurrentQueue;
+import org.eclipse.emf.cdo.server.IView;
+
+import java.util.Iterator;
+
+/**
+ * @author Simon McDuff
+ */
+public class QueryResult
+{
+ private long queryID;
+
+ private CDOProtocolView view;
+
+ private CDOQueryParameter queryParameter;
+
+ private StateConcurrentQueue<Object> linkQueue = new StateConcurrentQueue<Object>();
+
+ protected Iterator<Object> nextObject = new PollIterator<Object>(linkQueue);
+
+ public QueryResult(IView view, CDOQueryParameter parameter, long queryID)
+ {
+ this.queryID = queryID;
+ this.view = view;
+ this.queryParameter = parameter;
+ }
+
+ public CDOQueryParameter getQueryParameter()
+ {
+ return queryParameter;
+ }
+
+ public ResultWriterQueue<Object> getResultWriterQueue()
+ {
+ return linkQueue;
+ }
+
+ public CDOProtocolView getView()
+ {
+ return view;
+ }
+
+ public long getQueryID()
+ {
+ return queryID;
+ }
+
+ public boolean hasNext()
+ {
+ return nextObject.hasNext();
+ }
+
+ public Object next()
+ {
+ return nextObject.next();
+ }
+
+ public boolean hasNextNow()
+ {
+ return !linkQueue.isEmpty();
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
index dd663f812c..2d3c706638 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
@@ -8,6 +8,9 @@
* Contributors:
* Eike Stepper - initial API and implementation
* Simon McDuff - https://bugs.eclipse.org/bugs/show_bug.cgi?id=201266
+ * Simon McDuff - 233273: [QUERY] Develop Query mechanism
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=233273
+ *
**************************************************************************/
package org.eclipse.emf.cdo.internal.server;
@@ -53,6 +56,8 @@ public class Repository extends Container<IRepositoryElement> implements IReposi
private ResourceManager resourceManager = createResourceManager();
private RevisionManager revisionManager = createRevisionManager();
+
+ private QueryManager queryManager = createQueryManager();
private IRepositoryElement[] elements;
@@ -162,6 +167,11 @@ public class Repository extends Container<IRepositoryElement> implements IReposi
return revisionManager;
}
+ public QueryManager getQueryManager()
+ {
+ return queryManager;
+ }
+
public IRepositoryElement[] getElements()
{
return elements;
@@ -215,7 +225,11 @@ public class Repository extends Container<IRepositoryElement> implements IReposi
{
return new RevisionManager(this);
}
-
+
+ protected QueryManager createQueryManager()
+ {
+ return new QueryManager();
+ }
@Override
protected void doBeforeActivate() throws Exception
{
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
index 0f9f42a690..2a0c7b5a2d 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
@@ -7,6 +7,8 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Simon McDuff - 233273: [QUERY] Develop Query mechanism
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=233273
**************************************************************************/
package org.eclipse.emf.cdo.internal.server.protocol;
@@ -75,8 +77,15 @@ public class CDOServerProtocol extends CDOProtocolImpl
case CDOProtocolConstants.SIGNAL_COMMIT_TRANSACTION:
return new CommitTransactionIndication();
+ case CDOProtocolConstants.SIGNAL_QUERY:
+ return new QueryIndication();
+
+ case CDOProtocolConstants.SIGNAL_QUERY_CANCEL:
+ return new QueryCancelIndication();
+
default:
return null;
+
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/QueryCancelIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/QueryCancelIndication.java
new file mode 100644
index 0000000000..0769f12c7b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/QueryCancelIndication.java
@@ -0,0 +1,72 @@
+/***************************************************************************
+ * Copyright (c) 2004-2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.internal.server.protocol;
+
+import org.eclipse.emf.cdo.common.CDOProtocolConstants;
+import org.eclipse.emf.cdo.internal.server.bundle.OM;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import java.io.IOException;
+
+/**
+ * @author Simon McDuff
+ */
+public class QueryCancelIndication extends CDOReadIndication
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, QueryCancelIndication.class);
+
+ private long queryID = -1;
+
+ public QueryCancelIndication()
+ {
+ super();
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return CDOProtocolConstants.SIGNAL_QUERY_CANCEL;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+
+ queryID = in.readLong();
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Query " + queryID + " will be cancel");
+ }
+
+ }
+
+ /**
+ * @see org.eclipse.net4j.signal.IndicationWithResponse#responding(org.eclipse.net4j.util.io.ExtendedDataOutputStream)
+ */
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws IOException
+ {
+ try
+ {
+ getRepository().getQueryManager().cancel(queryID);
+ out.writeByte(0);
+ }
+ catch (Exception exception)
+ {
+ out.writeByte(1);
+ out.writeString(exception.getMessage());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/QueryIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/QueryIndication.java
new file mode 100644
index 0000000000..949b913655
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/QueryIndication.java
@@ -0,0 +1,111 @@
+/***************************************************************************
+ * Copyright (c) 2004-2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.internal.server.protocol;
+
+import org.eclipse.emf.cdo.common.CDOProtocolConstants;
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
+import org.eclipse.emf.cdo.common.util.CDOInstanceUtil;
+import org.eclipse.emf.cdo.internal.common.query.CDOQueryParameterImpl;
+import org.eclipse.emf.cdo.internal.server.QueryManager;
+import org.eclipse.emf.cdo.internal.server.QueryResult;
+import org.eclipse.emf.cdo.internal.server.bundle.OM;
+import org.eclipse.emf.cdo.server.IView;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import java.io.IOException;
+
+/**
+ * @author Simon McDuff
+ */
+public class QueryIndication extends CDOReadIndication
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, QueryIndication.class);
+
+ private QueryResult queryResult = null;
+
+ public QueryIndication()
+ {
+ super();
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return CDOProtocolConstants.SIGNAL_QUERY;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+ int viewID = in.readInt();
+
+ CDOQueryParameter cdoQuery = new CDOQueryParameterImpl(in, getStore().getCDOIDObjectFactory(), getPackageManager());
+
+ IView view = getSession().getView(viewID);
+
+ QueryManager queryManager = getRepository().getQueryManager();
+
+ queryResult = queryManager.execute(view, cdoQuery);
+ }
+
+ /**
+ * @see org.eclipse.net4j.signal.IndicationWithResponse#responding(org.eclipse.net4j.util.io.ExtendedDataOutputStream)
+ */
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws IOException
+ {
+ try
+ {
+ int numberOfResult = 0;
+
+ // Return queryID immediately.
+ out.writeLong(queryResult.getQueryID());
+ out.flush();
+
+ while (queryResult.hasNext())
+ {
+ Object object = queryResult.next();
+
+ // Object to return
+ numberOfResult++;
+ out.writeByte(0);
+ CDOInstanceUtil.writeInstance(out, object);
+
+ if (!queryResult.hasNextNow())
+ {
+ // Flush only if empty
+ out.flush();
+ }
+ }
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Query had " + numberOfResult + " objects return");
+ }
+
+ // DONE
+ out.writeByte(1);
+ }
+ catch (Exception exception)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(exception);
+ }
+
+ // Exception occured
+ out.writeByte(2);
+ out.writeString(exception.getMessage());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
index e0e1ad3641..273a0f1c33 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
@@ -7,14 +7,16 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Simon McDuff - 233273: [QUERY] Develop Query mechanism
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=233273
**************************************************************************/
package org.eclipse.emf.cdo.server;
+import org.eclipse.emf.cdo.common.id.CDOIDLibraryDescriptor;
+import org.eclipse.emf.cdo.common.id.CDOIDLibraryProvider;
+import org.eclipse.emf.cdo.common.id.CDOIDObjectFactory;
+import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.internal.server.Repository;
-import org.eclipse.emf.cdo.protocol.id.CDOIDLibraryDescriptor;
-import org.eclipse.emf.cdo.protocol.id.CDOIDLibraryProvider;
-import org.eclipse.emf.cdo.protocol.id.CDOIDObjectFactory;
-import org.eclipse.emf.cdo.protocol.revision.delta.CDORevisionDelta;
/**
* @author Eike Stepper
@@ -104,4 +106,5 @@ public interface IStore extends IRepositoryElement
* @return a writer that can be used to write to this store in the context of the given view, never <code>null</code>.
*/
public IStoreWriter getWriter(IView view);
+
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java
index 7fd4f6f947..67861e94ef 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.model.CDOClassRef;
import org.eclipse.emf.cdo.common.model.CDOFeature;
import org.eclipse.emf.cdo.common.model.CDOPackage;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.net4j.util.collection.CloseableIterator;
@@ -30,6 +31,8 @@ public interface IStoreReader extends IStoreAccessor
public ISession getSession();
public IStoreChunkReader createChunkReader(CDORevision revision, CDOFeature feature);
+
+ public CloseableIterator<Object> createQueryIterator(CDOQueryParameter queryParameter);
public Collection<CDOPackageInfo> readPackageInfos();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/QueryTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/QueryTest.java
new file mode 100644
index 0000000000..ab8f30a951
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/QueryTest.java
@@ -0,0 +1,198 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.tests;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.internal.server.Repository;
+import org.eclipse.emf.cdo.query.CDOQuery;
+import org.eclipse.emf.cdo.query.CDOQueryResult;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.Model1Package;
+
+import org.eclipse.emf.internal.cdo.query.CDOQueryImpl;
+import org.eclipse.emf.internal.cdo.query.CDOQueryResultIteratorImpl;
+
+import org.eclipse.net4j.util.collection.CloseableIterator;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Simon McDuff
+ */
+public class QueryTest extends AbstractCDOTest
+{
+ static String LANGUAGE_TEST = "TEST";
+
+ public void testBasicQuery() throws Exception
+ {
+
+ Set<Object> objects = new HashSet<Object>();
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+
+ CDOResource resource1 = transaction.createResource("/test1");
+ objects.add(resource1);
+ Company company1 = Model1Factory.eINSTANCE.createCompany();
+ Category category1 = Model1Factory.eINSTANCE.createCategory();
+
+ resource1.getContents().add(company1);
+ company1.getCategories().add(category1);
+
+ objects.add(company1);
+ objects.add(category1);
+
+ company1.setName("TEST");
+
+ transaction.commit();
+
+ CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "TEST");
+ List<Object> queryResult = cdoQuery.getResultList(Object.class);
+ assertEquals(3, queryResult.size());
+ for (Object object : queryResult)
+ {
+ assertEquals(true, objects.contains(object));
+ }
+
+ transaction.close();
+ session.close();
+ }
+
+ public void testBasicQuery_EClassParameter() throws Exception
+ {
+
+ Set<Object> objects = new HashSet<Object>();
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+
+ CDOResource resource1 = transaction.createResource("/test1");
+ objects.add(resource1);
+ Company company1 = Model1Factory.eINSTANCE.createCompany();
+ Category category1 = Model1Factory.eINSTANCE.createCategory();
+
+ resource1.getContents().add(company1);
+ company1.getCategories().add(category1);
+
+ objects.add(company1);
+ objects.add(category1);
+
+ company1.setName("TEST");
+
+ transaction.commit();
+
+ System.out.println(category1.eClass().getEPackage().getNsURI());
+
+ CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "TEST");
+
+ cdoQuery.setParameter("context", Model1Package.eINSTANCE.getCategory());
+
+ List<Category> queryResult = cdoQuery.getResultList(Category.class);
+
+ assertEquals(1, queryResult.size());
+ assertEquals(category1, queryResult.get(0));
+
+ transaction.close();
+ session.close();
+ }
+ public void testQueryCancel_successful() throws Exception
+ {
+ CDOTransaction transaction = initialize(100);
+
+ CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "TEST");
+ CloseableIterator<Object> queryResult = ((CDOQueryImpl)cdoQuery).getResultIterator(Object.class);
+
+ queryResult.close();
+
+ assertEquals(false, ((Repository)getRepository()).getQueryManager().isRunning(
+ ((CDOQueryResultIteratorImpl)queryResult).getQueryID()));
+
+ transaction.close();
+ transaction.getSession().close();
+ }
+
+ public void testQueryCancel_ViewClose() throws Exception
+ {
+ CDOTransaction transaction = initialize(100);
+
+ CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "TEST");
+ CloseableIterator<Object> queryResult = cdoQuery.getResultIterator(Object.class);
+
+ Thread.sleep(300);
+ // queryResult.cancel();
+ transaction.close();
+ assertEquals(false, ((Repository)getRepository()).getQueryManager().isRunning(
+ ((CDOQueryResultIteratorImpl)queryResult).getQueryID()));
+ transaction.getSession().close();
+ }
+
+ public void testQueryCancel_SessionClose() throws Exception
+ {
+ CDOTransaction transaction = initialize(100);
+
+ CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "TEST");
+ CloseableIterator<Object> queryResult = cdoQuery.getResultIterator(Object.class);
+
+ Thread.sleep(300);
+
+ transaction.getSession().close();
+
+ assertEquals(false, ((Repository)getRepository()).getQueryManager().isRunning(
+ ((CDOQueryResultIteratorImpl)queryResult).getQueryID()));
+
+ }
+
+ public void testQueryCancel_exception() throws Exception
+ {
+ CDOTransaction transaction = initialize(2);
+
+ CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "TEST");
+ CDOQueryResult<Object> queryResult = cdoQuery.getResultIterator(Object.class);
+
+ while (!queryResult.isDone())
+ {
+ Thread.sleep(10);
+ }
+ try
+ {
+ queryResult.close();
+ assertEquals(false, true);
+ }
+ catch (Exception exception)
+ {
+
+ }
+
+ transaction.close();
+ transaction.getSession().close();
+ }
+
+ CDOTransaction initialize(int number)
+ {
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+
+ CDOResource resource1 = transaction.createResource("/test1");
+
+ for (int i = 0; i < number; i++)
+ {
+ Category category1 = Model1Factory.eINSTANCE.createCategory();
+ resource1.getContents().add(category1);
+ }
+
+ transaction.commit();
+ return transaction;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF
index edc25118d7..7cd89bdb89 100644
--- a/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo/META-INF/MANIFEST.MF
@@ -12,15 +12,17 @@ Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.emf.ecore;bundle-version="[2.4.0,3.0.0)";visibility:=reexport,
org.eclipse.emf.ecore.xmi;bundle-version="[2.4.0,3.0.0)";visibility:=reexport,
- org.eclipse.emf.cdo.protocol;bundle-version="[2.0.0,3.0.0)";visibility:=reexport
+ org.eclipse.emf.cdo.common;bundle-version="[2.0.0,3.0.0)";visibility:=reexport
Export-Package: org.eclipse.emf.cdo;version="2.0.0",
org.eclipse.emf.cdo.analyzer;version="2.0.0",
org.eclipse.emf.cdo.eresource;version="2.0.0",
org.eclipse.emf.cdo.eresource.impl;version="2.0.0",
org.eclipse.emf.cdo.eresource.util;version="2.0.0",
+ org.eclipse.emf.cdo.query;version="2.0.0",
org.eclipse.emf.cdo.util;version="2.0.0",
org.eclipse.emf.internal.cdo;version="0.90",
org.eclipse.emf.internal.cdo.analyzer;version="2.0.0",
org.eclipse.emf.internal.cdo.bundle;version="2.0.0";x-friends:="org.eclipse.emf.cdo.ui",
org.eclipse.emf.internal.cdo.protocol;version="2.0.0",
+ org.eclipse.emf.internal.cdo.query;version="2.0.0",
org.eclipse.emf.internal.cdo.util;version="2.0.0"
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
index 5ad0494686..6cebdbe5f8 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
@@ -16,6 +16,7 @@ import org.eclipse.emf.cdo.common.CDOProtocolView;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.query.CDOQuery;
import org.eclipse.net4j.util.event.INotifier;
@@ -72,7 +73,8 @@ public interface CDOView extends CDOProtocolView, INotifier
public CDORevision getRevision(CDOID id);
public boolean hasResource(String path);
-
+
+ public CDOQuery createQuery(String language, String queryString);
/**
* @see ResourceSet#getResource(URI, boolean)
*/
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/query/CDOQuery.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/query/CDOQuery.java
new file mode 100644
index 0000000000..f90b6e78df
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/query/CDOQuery.java
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.query;
+
+import java.util.List;
+
+/**
+ * @author Simon McDuff
+ */
+public interface CDOQuery
+{
+
+ public <T> CDOQueryResult<T> getResultIterator(Class<T> classObject) throws Exception;
+
+
+ public <T> List<T> getResultList(Class<T> classObject) throws Exception;
+
+ /**
+ * Set the maximum number of results to retrieve.
+ * @param maxResult
+ * @return the same query instance
+ * @throws IllegalArgumentException if argument is negative
+ */
+ public CDOQuery setMaxResults(int maxResult);
+ public int getMaxResults();
+
+ /**
+ * Bind an argument to a named parameter.
+ * @param name the parameter name
+ * @param value
+ * @return the same query instance
+ * @throws IllegalArgumentException if parameter name does not
+ * correspond to parameter in query string
+ * or argument is of incorrect type
+ */
+ public CDOQuery setParameter(String name, Object value);
+
+
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/query/CDOQueryResult.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/query/CDOQueryResult.java
new file mode 100644
index 0000000000..adfb3f9f4e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/query/CDOQueryResult.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.query;
+
+import org.eclipse.emf.cdo.common.query.ResultReaderQueue;
+
+/**
+ * @author Simon McDuff
+ */
+public interface CDOQueryResult<T> extends ResultReaderQueue<T>
+{
+
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
index 3b7e97209b..c3374b7513 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
@@ -31,6 +31,8 @@ import org.eclipse.emf.cdo.common.util.TransportException;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.EresourceFactory;
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
+import org.eclipse.emf.cdo.internal.common.query.CDOQueryParameterImpl;
+import org.eclipse.emf.cdo.query.CDOQuery;
import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.ReadOnlyException;
@@ -38,6 +40,7 @@ import org.eclipse.emf.cdo.util.ReadOnlyException;
import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.protocol.ResourceIDRequest;
import org.eclipse.emf.internal.cdo.protocol.ResourcePathRequest;
+import org.eclipse.emf.internal.cdo.query.CDOQueryImpl;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
@@ -201,6 +204,13 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
return id != null && !id.isNull();
}
+ public CDOQuery createQuery(String language, String queryString)
+ {
+ CDOQueryParameterImpl parameter = new CDOQueryParameterImpl(language, queryString);
+
+ return new CDOQueryImpl(this, parameter);
+ }
+
public CDOID getResourceID(String path)
{
try
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryCancelRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryCancelRequest.java
new file mode 100644
index 0000000000..b1abfd4e6e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryCancelRequest.java
@@ -0,0 +1,64 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.protocol;
+
+import org.eclipse.emf.cdo.common.CDOProtocolConstants;
+
+import org.eclipse.emf.internal.cdo.bundle.OM;
+
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import java.io.IOException;
+
+/**
+ * @author Simon McDuff
+ */
+public class QueryCancelRequest extends CDOClientRequest<Object>
+{
+ private static final ContextTracer PROTOCOL = new ContextTracer(OM.DEBUG_PROTOCOL, QueryCancelRequest.class);
+
+ private long queryID;
+
+ public QueryCancelRequest(long queryID, IChannel channel)
+ {
+ super(channel);
+ this.queryID = queryID;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return CDOProtocolConstants.SIGNAL_QUERY_CANCEL;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws IOException
+ {
+ if (PROTOCOL.isEnabled()) PROTOCOL.trace("Cancel query " + queryID);
+ // Write ViewID
+ out.writeLong(queryID);
+ }
+
+ @Override
+ protected Object confirming(ExtendedDataInputStream in) throws IOException
+ {
+ byte result = in.readByte();
+ if (result == 1)
+ {
+ String exception = in.readString();
+ throw new RuntimeException(exception);
+ }
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryRequest.java
new file mode 100644
index 0000000000..70a895150b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryRequest.java
@@ -0,0 +1,133 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.protocol;
+
+import org.eclipse.emf.cdo.common.CDOProtocolConstants;
+import org.eclipse.emf.cdo.common.query.ResultWriterQueue;
+import org.eclipse.emf.cdo.common.util.CDOInstanceUtil;
+import org.eclipse.emf.cdo.internal.common.query.CDOQueryParameterImpl;
+
+import org.eclipse.emf.internal.cdo.bundle.OM;
+import org.eclipse.emf.internal.cdo.query.CDOQueryResultIteratorImpl;
+
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Simon McDuff
+ */
+public class QueryRequest extends CDOClientRequest<Object>
+{
+ private static final ContextTracer PROTOCOL = new ContextTracer(OM.DEBUG_PROTOCOL, QueryRequest.class);
+
+ private int viewID;
+
+ private CDOQueryParameterImpl cdoQuery;
+
+ private CDOQueryResultIteratorImpl<?> queryResult;
+
+ public QueryRequest(int viewID, IChannel channel, CDOQueryResultIteratorImpl<?> queryResult,
+ CDOQueryParameterImpl cdoQuery)
+ {
+ super(channel);
+
+ this.viewID = viewID;
+ this.cdoQuery = cdoQuery;
+ this.queryResult = queryResult;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return CDOProtocolConstants.SIGNAL_QUERY;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws IOException
+ {
+ // Write ViewID
+ out.writeInt(viewID);
+
+ cdoQuery.write(out);
+
+ }
+
+ @Override
+ protected List<Object> confirming(ExtendedDataInputStream in) throws IOException
+ {
+
+ List<Object> returnList = new ArrayList<Object>();
+
+ queryResult.setQueryID(in.readLong());
+
+ LifecycleUtil.activate(queryResult);
+
+ ResultWriterQueue<Object> resulQueue = queryResult.getResultQueue();
+
+ try
+ {
+ int numberOfObjectReceived = 0;
+
+ while (true)
+ {
+ byte state = in.readByte();
+
+ if (state == 0)
+ {
+ // result
+ Object element = CDOInstanceUtil.readInstance(in, getSession());
+
+ resulQueue.add(element);
+
+ numberOfObjectReceived++;
+ }
+ else if (state == 1)
+ {
+ // End of result
+ break;
+ }
+ else if (state == 2)
+ {
+ // Exception on the server
+ String exceptionString = in.readString();
+ throw new RuntimeException(exceptionString);
+ }
+ }
+
+ if (PROTOCOL.isEnabled())
+ {
+ PROTOCOL.trace("Query executed [" + numberOfObjectReceived + " elements received]");
+ }
+ }
+ catch (RuntimeException ex)
+ {
+ resulQueue.setException(ex);
+
+ }
+ catch (Throwable throwable)
+ {
+ resulQueue.setException(new RuntimeException(throwable.getMessage(), throwable));
+ }
+ finally
+ {
+ resulQueue.release();
+ }
+
+ return returnList;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java
new file mode 100644
index 0000000000..eba9e4aad1
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java
@@ -0,0 +1,155 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.query;
+
+import org.eclipse.emf.cdo.common.model.CDOClass;
+import org.eclipse.emf.cdo.internal.common.query.CDOQueryParameterImpl;
+import org.eclipse.emf.cdo.query.CDOQuery;
+import org.eclipse.emf.cdo.query.CDOQueryResult;
+
+import org.eclipse.emf.internal.cdo.CDOViewImpl;
+import org.eclipse.emf.internal.cdo.InternalCDOObject;
+import org.eclipse.emf.internal.cdo.protocol.QueryRequest;
+import org.eclipse.emf.internal.cdo.util.FSMUtil;
+import org.eclipse.emf.internal.cdo.util.ModelUtil;
+
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+
+import org.eclipse.emf.ecore.EClass;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map.Entry;
+
+/**
+ * @author Simon McDuff
+ */
+public class CDOQueryImpl implements CDOQuery
+{
+ CDOQueryParameterImpl queryParameter;
+
+ HashMap<String, Object> parameters = new HashMap<String, Object>();
+
+ CDOViewImpl view = null;
+
+ int maxResult = -1;
+
+ public CDOQueryImpl(CDOViewImpl cdoView, CDOQueryParameterImpl queryParameter)
+ {
+ view = cdoView;
+ this.queryParameter = queryParameter;
+ }
+
+ protected CDOQueryParameterImpl createQueryParameter()
+ {
+ CDOQueryParameterImpl queryParameter = new CDOQueryParameterImpl(this.queryParameter.getQueryLanguage(),
+ this.queryParameter.getQueryString());
+
+ for (Entry<String, Object> entry : parameters.entrySet())
+ {
+ Object value = entry.getValue();
+
+ value = adapt(value);
+
+ queryParameter.getParameters().put(entry.getKey(), value);
+ }
+ return queryParameter;
+ }
+
+ public <T> List<T> getResultList(Class<T> classObject) throws Exception
+ {
+ CDOQueryParameterImpl queryParameter = createQueryParameter();
+
+ CDOQueryResultIteratorImpl<T> queryResult = new CDOQueryResultIteratorImpl<T>(view, queryParameter);
+
+ new QueryRequest(view.getViewID(), view.getSession().getChannel(), queryResult, queryParameter).send();
+
+ return queryResult.getAsList();
+ }
+
+ public <T> CDOQueryResult<T> getResultIterator(Class<T> classObject)
+ {
+ final CDOQueryParameterImpl queryParameter = createQueryParameter();
+ final CDOQueryResultIteratorImpl<T> queryResult = new CDOQueryResultIteratorImpl<T>(view, queryParameter);
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+
+ new QueryRequest(view.getViewID(), view.getSession().getChannel(), queryResult, queryParameter).send();
+ }
+ catch (RuntimeException ex)
+ {
+ queryResult.getResultQueue().setException(ex);
+
+ // Be sure we activate queryResultObject
+ if (!queryResult.isActive()) LifecycleUtil.activate(queryResult);
+ }
+ catch (Exception ex)
+ {
+ queryResult.getResultQueue().setException(new RuntimeException(ex));
+
+ // Be sure we activate queryResult
+ if (!queryResult.isActive()) LifecycleUtil.activate(queryResult);
+ }
+ }
+ };
+
+ new Thread(runnable).start();
+
+ queryResult.waitForActivate();
+
+ return queryResult;
+ }
+
+ protected Object adapt(Object object)
+ {
+ if (object instanceof EClass)
+ {
+ EClass eClass = (EClass)object;
+ CDOClass cdoClass = ModelUtil.getCDOClass(eClass, view.getSession().getPackageManager());
+ return cdoClass;
+ }
+ else if (object instanceof InternalCDOObject)
+ {
+ InternalCDOObject internalCDOObject = FSMUtil.adapt(object, view);
+
+ if (internalCDOObject.cdoID() == null) throw new UnsupportedOperationException("Object not persisted");
+
+ if (internalCDOObject.cdoID().isTemporary()) throw new UnsupportedOperationException("Object not persisted");
+
+ return internalCDOObject.cdoID();
+ }
+
+ return object;
+ }
+
+ public CDOQuery setMaxResults(int maxResult)
+ {
+ this.maxResult = maxResult;
+ return this;
+ }
+
+ public int getMaxResults()
+ {
+ return maxResult;
+ }
+
+ public CDOQuery setParameter(String name, Object value)
+ {
+ parameters.put(name, value);
+ return this;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java
new file mode 100644
index 0000000000..11dd0c81be
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java
@@ -0,0 +1,124 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.query;
+
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.query.CDOQueryParameter;
+import org.eclipse.emf.cdo.common.util.PropertyChanged;
+import org.eclipse.emf.cdo.internal.common.query.CDOAbstractQueryResultImpl;
+import org.eclipse.emf.cdo.query.CDOQueryResult;
+
+import org.eclipse.emf.internal.cdo.protocol.QueryCancelRequest;
+
+import org.eclipse.net4j.util.lifecycle.ILifecycleState;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * @author Simon McDuff
+ */
+public class CDOQueryResultIteratorImpl<T> extends CDOAbstractQueryResultImpl<T> implements CDOQueryResult<T>
+{
+ protected CDOView cdoView;
+
+ protected boolean cancelled = false;
+
+ protected PropertyChanged<ILifecycleState> state = new PropertyChanged<ILifecycleState>(getLifecycleState());
+
+ public CDOQueryResultIteratorImpl(CDOView cdoView, CDOQueryParameter cdoQueryParameter)
+ {
+ super(cdoQueryParameter);
+ this.cdoView = cdoView;
+ }
+
+ public void waitForActivate()
+ {
+ state.acquire(ILifecycleState.ACTIVE, null);
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ state.set(ILifecycleState.ACTIVE);
+ super.doActivate();
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ state.set(ILifecycleState.INACTIVE);
+ super.doDeactivate();
+ }
+
+ public boolean hasNext()
+ {
+ return nextObject.hasNext();
+ }
+
+ public T next()
+ {
+ return adapt(nextObject.next());
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected T adapt(Object object)
+ {
+ if (object instanceof CDOID)
+ {
+ if (((CDOID)object).isNull()) return null;
+ return (T)cdoView.getObject((CDOID)object, true);
+ }
+ return (T)object;
+ }
+
+ public void close()
+ {
+ cancelled = true;
+ try
+ {
+ new QueryCancelRequest(queryID, cdoView.getSession().getChannel()).send();
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public boolean cancel(boolean arg0)
+ {
+ close();
+ return true;
+ }
+
+ public T get() throws InterruptedException, ExecutionException
+ {
+ return null;
+ }
+
+ public T get(long arg0, TimeUnit arg1) throws InterruptedException, ExecutionException, TimeoutException
+ {
+ return null;
+ }
+
+ public boolean isCancelled()
+ {
+ return cancelled;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/ECDOIDList.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/ECDOIDList.java
new file mode 100644
index 0000000000..15d59d409e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/ECDOIDList.java
@@ -0,0 +1,192 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+
+package org.eclipse.emf.internal.cdo.query;
+
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.common.id.CDOID;
+
+import org.eclipse.emf.common.util.EList;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * @author Simon McDuff
+ */
+public class ECDOIDList<T> implements EList<T>
+{
+ private List<Object> listOfIDs;
+
+ private CDOView cdoView;
+
+ public ECDOIDList(CDOView view, List<Object> list)
+ {
+ this.listOfIDs = list;
+ this.cdoView = view;
+ }
+ @SuppressWarnings("unchecked")
+ protected T adapt(CDOID object)
+ {
+ if (object.isNull())
+ return null;
+
+ return (T)cdoView.getObject((CDOID)object, true);
+ }
+
+ public boolean add(T o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void add(int index, T element)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @SuppressWarnings("unchecked")
+ public T get(int index)
+ {
+ Object object = this.listOfIDs.get(index);
+ if (object instanceof CDOID)
+ {
+ object = adapt((CDOID)object);
+ // replace the old object with the new
+ listOfIDs.set(index, object);
+ }
+ return (T)object;
+ }
+
+ public boolean isEmpty()
+ {
+ return listOfIDs.isEmpty();
+ }
+
+ class ECDOIDListIterator implements Iterator<T>
+ {
+ ListIterator<Object> iterator;
+
+ ECDOIDListIterator(ListIterator<Object> itr)
+ {
+ this.iterator = itr;
+ }
+
+ public boolean hasNext()
+ {
+ return iterator.hasNext();
+ }
+ @SuppressWarnings("unchecked")
+ public T next()
+ {
+ Object object = iterator.next();
+ if (object instanceof CDOID)
+ {
+ object = adapt((CDOID)object);
+ // replace the old object with the new
+ iterator.set(object);
+ }
+ return (T)object;
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ public Iterator<T> iterator()
+ {
+ return new ECDOIDListIterator(this.listOfIDs.listIterator());
+ }
+ public void move(int newPosition, T object)
+ {
+ }
+ public T move(int newPosition, int oldPosition)
+ {
+ return null;
+ }
+ public boolean addAll(Collection<? extends T> arg0)
+ {
+ return false;
+ }
+ public boolean addAll(int arg0, Collection<? extends T> arg1)
+ {
+ return false;
+ }
+ public void clear()
+ {
+ }
+ public boolean contains(Object arg0)
+ {
+ return false;
+ }
+ public boolean containsAll(Collection<?> arg0)
+ {
+ return false;
+ }
+ public int indexOf(Object arg0)
+ {
+ return 0;
+ }
+ public int lastIndexOf(Object arg0)
+ {
+ return 0;
+ }
+ public ListIterator<T> listIterator()
+ {
+ return null;
+ }
+ public ListIterator<T> listIterator(int arg0)
+ {
+ return null;
+ }
+ public boolean remove(Object arg0)
+ {
+ return false;
+ }
+ public T remove(int arg0)
+ {
+ return null;
+ }
+ public boolean removeAll(Collection<?> arg0)
+ {
+ return false;
+ }
+ public boolean retainAll(Collection<?> arg0)
+ {
+ return false;
+ }
+ public T set(int arg0, T arg1)
+ {
+ return null;
+ }
+ public int size()
+ {
+ return 0;
+ }
+ public List<T> subList(int arg0, int arg1)
+ {
+ return null;
+ }
+ public Object[] toArray()
+ {
+ return null;
+ }
+ public <T> T[] toArray(T[] arg0)
+ {
+ return null;
+ }
+
+
+}

Back to the top