Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon McDuff2008-08-07 21:00:41 -0400
committerSimon McDuff2008-08-07 21:00:41 -0400
commit0fabc3ba6f3c85942279966e62473ab2e3dddccd (patch)
treec3d1da5730ab26be8da80c0f68b13c22fec2014f
parent5d9ea2ef3f568c69a9a47c0ddf5a758520128855 (diff)
downloadcdo-0fabc3ba6f3c85942279966e62473ab2e3dddccd.tar.gz
cdo-0fabc3ba6f3c85942279966e62473ab2e3dddccd.tar.xz
cdo-0fabc3ba6f3c85942279966e62473ab2e3dddccd.zip
[238414] Merge simon_pre_0_9 to HEAD
https://bugs.eclipse.org/bugs/show_bug.cgi?id=238414
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/CDOQueryQueue.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultReaderQueue.java35
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOInstanceUtil.java58
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CloseableBlockingIterator.java (renamed from plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultWriterQueue.java)13
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CloseableQueue.java (renamed from plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ExceptionHolder.java)14
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/ConcurrentValue.java (renamed from plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java)26
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PollIterator.java58
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/StateConcurrentQueue.java342
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/AbstractQueryResult.java111
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOAbstractQueryResultImpl.java73
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryInfoImpl.java (renamed from plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryParameterImpl.java)30
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryState.java19
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreReader.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AutoAttacherTest.java19
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/QueryTest.java43
16 files changed, 527 insertions, 331 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/CDOQueryQueue.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/CDOQueryQueue.java
index 38e6757039..237e9377df 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/CDOQueryQueue.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/CDOQueryQueue.java
@@ -16,7 +16,7 @@ import org.eclipse.emf.cdo.common.util.CloseableQueue;
* @author Simon McDuff
* @since 2.0
*/
-public interface CDOQueryQueue<E> extends CloseableQueue<E>, ExceptionHolder
+public interface CDOQueryQueue<E> extends CloseableQueue<E>
{
-
+ void setException(Throwable exception);
}
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
deleted file mode 100644
index b0668d9265..0000000000
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ResultReaderQueue.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/***************************************************************************
- * 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;
-
-/**
- * @author Simon McDuff
- * @since 2.0
- */
-public interface ResultReaderQueue<T> extends CloseableIterator<T>
-{
- /**
- * Returns <tt>true</tt> if this task was cancelled before it completed normally.
- *
- * @return <tt>true</tt> if this task was cancelled before it completed
- */
- boolean isCancelled();
-
- /**
- * Returns <tt>true</tt> if this task completed. Completion may be due to normal termination, an exception, or
- * cancellation -- in all of these cases, this method will return <tt>true</tt>.
- *
- * @return <tt>true</tt> if this task completed
- */
- boolean isDone();
-}
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
index 457fca17ef..1829b10edb 100644
--- 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
@@ -32,7 +32,7 @@ import java.util.Map;
*/
public class CDOInstanceUtil
{
- public static Map<Class<?>, CDOType> idTypes = new HashMap<Class<?>, CDOType>();
+ private static Map<Class<?>, CDOType> idTypes = new HashMap<Class<?>, CDOType>();
static
{
@@ -43,6 +43,8 @@ public class CDOInstanceUtil
idTypes.put(Integer.class, CDOType.INT);
idTypes.put(Double.class, CDOType.DOUBLE);
idTypes.put(Byte.class, CDOType.BYTE);
+ idTypes.put(Character.class, CDOType.CHAR);
+ idTypes.put(Float.class, CDOType.FLOAT);
}
private CDOInstanceUtil()
@@ -51,31 +53,27 @@ public class CDOInstanceUtil
}
/**
- * @param out
- * @param id
- * @throws IOException
+ * Write into a {@link ExtendedDataOutput} CDOClass, CDORevision or primitive.
*/
- static public void writeObject(ExtendedDataOutput out, Object id) throws IOException
+ static public void writeObjectOrClass(ExtendedDataOutput out, Object id) throws IOException
{
if (id instanceof CDOClass)
{
- out.writeByte(0);
+ out.writeBoolean(true);
CDOModelUtil.writeClassRef(out, ((CDOClass)id).createClassRef(), null);
return;
}
- out.writeByte(1);
+ out.writeBoolean(false);
- writeInstance(out, id);
+ writeObject(out, id);
}
/**
- * @param out
- * @param id
- * @throws IOException
+ * Write into a {@link ExtendedDataOutput} CDORevision or primitive.
*/
- static public void writeInstance(ExtendedDataOutput out, Object id) throws IOException
+ static public void writeObject(ExtendedDataOutput out, Object id) throws IOException
{
if (id == null)
{
@@ -90,43 +88,47 @@ public class CDOInstanceUtil
if (id instanceof CDOID)
{
+ if (((CDOID)id).isTemporary())
+ {
+ throw new IllegalArgumentException("Do not support temporary for " + id);
+ }
+
type = CDOType.OBJECT;
}
else
{
type = idTypes.get(id.getClass());
- }
- if (type == null) throw new IllegalStateException("No type for object " + 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
+ * Read from an {@link ExtendedDataInput} CDORevision or primitive.
*/
- static public Object readInstance(ExtendedDataInput in, CDOIDObjectFactory objectFactory) throws IOException
+ static public Object readObject(ExtendedDataInput in, CDOIDObjectFactory idObjectFactory) throws IOException
{
CDOType type = CDOModelUtil.readType(in);
- return type.readValue(in, objectFactory);
+ return type.readValue(in, idObjectFactory);
}
- static public Object readObject(ExtendedDataInput in, CDOIDObjectFactory objectFactory,
+ /**
+ * Read from an {@link ExtendedDataInput} CDOClass, CDORevision or primitive.
+ */
+ static public Object readObjectOrClass(ExtendedDataInput in, CDOIDObjectFactory idObjectFactory,
CDOPackageManager packageManager) throws IOException
{
- byte value = in.readByte();
-
- if (value == 0)
+ boolean isClass = in.readBoolean();
+ if (isClass)
{
return CDOModelUtil.readClassRef(in).resolve(packageManager);
}
- else if (value == 1)
- {
- readInstance(in, objectFactory);
- }
- throw new IllegalStateException();
+ return readObject(in, idObjectFactory);
}
}
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/util/CloseableBlockingIterator.java
index b3ad1c244a..1419b810e9 100644
--- 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/util/CloseableBlockingIterator.java
@@ -8,17 +8,18 @@
* Contributors:
* Simon McDuff - initial API and implementation
**************************************************************************/
-package org.eclipse.emf.cdo.common.query;
+package org.eclipse.emf.cdo.common.util;
-import java.util.Queue;
+import org.eclipse.net4j.util.collection.CloseableIterator;
/**
* @author Simon McDuff
* @since 2.0
*/
-public interface ResultWriterQueue<E> extends Queue<E>
+public interface CloseableBlockingIterator<T> extends CloseableIterator<T>
{
- void setException(RuntimeException exception);
-
- void release();
+ /**
+ * Non-blocking call.
+ */
+ T peek();
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ExceptionHolder.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CloseableQueue.java
index 115da6ad77..e474a93a49 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/query/ExceptionHolder.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CloseableQueue.java
@@ -6,15 +6,19 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Simon McDuff - initial API and implementation
+ * Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.emf.cdo.common.query;
+package org.eclipse.emf.cdo.common.util;
+
+import org.eclipse.net4j.util.collection.Closeable;
+
+import java.util.Queue;
/**
- * @author Simon McDuff
+ * @author Eike Stepper
* @since 2.0
*/
-public interface ExceptionHolder
+public interface CloseableQueue<E> extends Queue<E>, Closeable
{
- void setException(Throwable exception);
+
}
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/ConcurrentValue.java
index 03215bc149..56e55dc032 100644
--- 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/ConcurrentValue.java
@@ -14,15 +14,13 @@ package org.eclipse.emf.cdo.common.util;
* @author Simon McDuff
* @since 2.0
*/
-public class PropertyChanged<T>
+public class ConcurrentValue<T>
{
Object notifier = new Object();
T value;
- RuntimeException exception = null;
-
- public PropertyChanged(T value)
+ public ConcurrentValue(T value)
{
this.value = value;
}
@@ -41,29 +39,23 @@ public class PropertyChanged<T>
}
}
- public void setException(RuntimeException exception)
+ public void reevaluate()
{
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)
+ public void acquire(Object accept)
{
synchronized (notifier)
{
- while (!equalToOneElement(accept, refuse))
+ while (!equalToOneElement(accept))
{
try
{
- notifier.wait(timeout);
+ notifier.wait();
}
catch (InterruptedException ex)
{
@@ -73,14 +65,10 @@ public class PropertyChanged<T>
}
}
- private boolean equalToOneElement(Object accept, Object refuse)
+ private boolean equalToOneElement(Object accept)
{
- 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/PollIterator.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PollIterator.java
deleted file mode 100644
index a71f333740..0000000000
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PollIterator.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/***************************************************************************
- * 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
- * @since 2.0
- */
-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()
- {
- throw new UnsupportedOperationException();
- }
-
-}
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
index c6f9d82480..1874277420 100644
--- 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
@@ -10,50 +10,360 @@
**************************************************************************/
package org.eclipse.emf.cdo.common.util;
-import org.eclipse.emf.cdo.common.query.ResultWriterQueue;
+import org.eclipse.emf.cdo.common.query.CDOQueryQueue;
-import java.util.concurrent.ConcurrentLinkedQueue;
+import org.eclipse.net4j.util.WrappedException;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
/**
* @author Simon McDuff
* @since 2.0
*/
-public class StateConcurrentQueue<E> extends ConcurrentLinkedQueue<E> implements ResultWriterQueue<E>
+public class StateConcurrentQueue<E> implements CDOQueryQueue<E>
{
+ private QueueEntry<E> QUEUE_CLOSED = new QueueEntry<E>();
+
private static final long serialVersionUID = 1L;
- private boolean done = false;
+ private PriorityBlockingQueue<QueueEntry<E>> queue;
+
+ private boolean closed = false;
+
+ static class QueueEntry<E> implements java.util.Comparator<QueueEntry<E>>
+ {
+ static AtomicLong nextSeq = new AtomicLong(0);
+
+ private long seqNumber = 0;
+
+ private Object internalObject;
+
+ public QueueEntry()
+ {
+ seqNumber = Long.MAX_VALUE;
+ }
- private RuntimeException exception = null;
+ public QueueEntry(E object)
+ {
+ internalObject = object;
+ seqNumber = nextSeq.getAndIncrement();
+ }
+
+ public QueueEntry(Throwable object)
+ {
+ internalObject = object;
+ seqNumber = nextSeq.getAndIncrement();
+ }
+
+ public Object getObject()
+ {
+ return internalObject;
+ }
+
+ @SuppressWarnings("unchecked")
+ public E getObjectWithException()
+ {
+ Throwable exception = getException();
+ if (exception != null)
+ {
+ throw WrappedException.wrap((Exception)exception);
+ }
+ return (E)internalObject;
+ }
+
+ public Throwable getException()
+ {
+ if (internalObject instanceof Throwable)
+ {
+ return (Throwable)internalObject;
+ }
+ return null;
+ }
+
+ public int compare(QueueEntry<E> o1, QueueEntry<E> o2)
+ {
+ if (o1.getException() != null)
+ {
+ return -1;
+ }
+ if (o2.getException() != null)
+ {
+ return 1;
+ }
+
+ if (o1 == o2)
+ {
+ return 0;
+ }
+ return (o1.seqNumber < o2.seqNumber ? -1 : 1);
+ }
+ };
+
+ public class CloseableBlockingIteratorImpl implements CloseableBlockingIterator<E>
+ {
+ private boolean closed = false;
+
+ private E nextElement = null;
+
+ public E peek()
+ {
+
+ if (nextElement == null)
+ {
+ return StateConcurrentQueue.this.peek();
+ }
+ return nextElement;
+ }
+
+ public boolean hasNext()
+ {
+ if (nextElement == null)
+ {
+ try
+ {
+ nextElement = take();
+ }
+ catch (InterruptedException ex)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ return nextElement != null;
+ }
+
+ public E next()
+ {
+ try
+ {
+ return nextElement;
+ }
+ finally
+ {
+ nextElement = null;
+ }
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void close()
+ {
+ this.closed = true;
+ }
+
+ public boolean isClosed()
+ {
+ return this.closed;
+ }
+
+ }
public StateConcurrentQueue()
{
+ queue = new PriorityBlockingQueue<QueueEntry<E>>(10, new QueueEntry<E>());
+
}
- public void setRuntimeException(RuntimeException exception)
+ public void setException(Throwable exception)
{
- this.exception = exception;
+ queue.add(new QueueEntry<E>(exception));
}
- public E poll()
+ public void close()
+ {
+ synchronized (this)
+ {
+ if (!isClosed())
+ {
+ closed = true;
+
+ queue.add(QUEUE_CLOSED);
+ }
+ }
+ }
+
+ public boolean isClosed()
+ {
+ return closed;
+ }
+
+ public boolean add(E e)
+ {
+ return queue.add(new QueueEntry<E>(e));
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean addAll(Collection c)
+ {
+ return queue.addAll(c);
+ }
+
+ public void clear()
+ {
+ queue.clear();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Comparator comparator()
+ {
+ return queue.comparator();
+ }
+
+ public boolean contains(Object o)
+ {
+ return queue.contains(o);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean containsAll(Collection c)
+ {
+ return queue.containsAll(c);
+ }
+
+ @SuppressWarnings("unchecked")
+ public int drainTo(Collection c, int maxElements)
+ {
+ return queue.drainTo(c, maxElements);
+ }
+
+ @SuppressWarnings("unchecked")
+ public int drainTo(Collection c)
+ {
+ return queue.drainTo(c);
+ }
+
+ public E element()
+ {
+ return checkObject(queue.element());
+ }
+
+ public boolean equals(Object obj)
{
- if (exception != null) throw exception;
+ return queue.equals(obj);
+ }
- return super.poll();
+ public int hashCode()
+ {
+ return queue.hashCode();
}
- public boolean isDone()
+ public boolean isEmpty()
{
- return done;
+ return queue.isEmpty();
}
- public void release()
+ public Iterator<E> iterator()
{
- done = true;
+ return new CloseableBlockingIteratorImpl();
}
- public void setException(RuntimeException exception)
+ public boolean offer(E e, long timeout, TimeUnit unit)
{
- this.exception = exception;
+ return queue.offer(new QueueEntry<E>(e), timeout, unit);
}
+
+ public boolean offer(E e)
+ {
+ return true;
+ }
+
+ public E peek()
+ {
+ return checkObject(queue.peek());
+ }
+
+ public E poll(long timeout, TimeUnit unit) throws InterruptedException
+ {
+ return checkObject(queue.poll(timeout, unit));
+ }
+
+ public void put(E e)
+ {
+ queue.put(new QueueEntry<E>(e));
+ }
+
+ public int remainingCapacity()
+ {
+ return queue.remainingCapacity();
+ }
+
+ public E remove()
+ {
+ return checkObject(queue.remove());
+ }
+
+ public boolean remove(Object o)
+ {
+ return queue.remove(o);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean removeAll(Collection c)
+ {
+ return queue.removeAll(c);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean retainAll(Collection c)
+ {
+ return queue.retainAll(c);
+ }
+
+ public int size()
+ {
+ return queue.size();
+ }
+
+ public E take() throws InterruptedException
+ {
+ QueueEntry<E> entry = null;
+ try
+ {
+ entry = queue.take();
+ }
+ catch (InterruptedException ex)
+ {
+ Thread.currentThread().interrupt();
+ }
+ return checkObject(entry);
+ }
+
+ public Object[] toArray()
+ {
+ return queue.toArray();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] toArray(Object[] a)
+ {
+ return queue.toArray(a);
+ }
+
+ public String toString()
+ {
+ return queue.toString();
+ }
+
+ public E poll()
+ {
+ QueueEntry<E> entry = queue.poll();
+ return checkObject(entry);
+ }
+
+ private E checkObject(QueueEntry<E> entry)
+ {
+ if (entry == QUEUE_CLOSED)
+ {
+ return null;
+ }
+ return entry.getObjectWithException();
+ }
+
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/AbstractQueryResult.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/AbstractQueryResult.java
new file mode 100644
index 0000000000..63cc077963
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/AbstractQueryResult.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.common.query;
+
+import org.eclipse.emf.cdo.common.CDOProtocolView;
+import org.eclipse.emf.cdo.common.query.CDOQueryInfo;
+import org.eclipse.emf.cdo.common.query.CDOQueryQueue;
+import org.eclipse.emf.cdo.common.util.CloseableBlockingIterator;
+import org.eclipse.emf.cdo.common.util.StateConcurrentQueue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Simon McDuff
+ * @since 2.0
+ */
+public class AbstractQueryResult<T> implements CloseableBlockingIterator<T>
+{
+ private long queryID;
+
+ private CDOProtocolView view;
+
+ private CDOQueryInfo queryInfo;
+
+ private StateConcurrentQueue<Object> linkQueue = new StateConcurrentQueue<Object>();
+
+ private CloseableBlockingIterator<Object> queueItr = (CloseableBlockingIterator<Object>)linkQueue.iterator();
+
+ public AbstractQueryResult(CDOProtocolView view, CDOQueryInfo queryInfo, long queryID)
+ {
+ this.queryID = queryID;
+ this.view = view;
+ this.queryInfo = queryInfo;
+ }
+
+ public CDOQueryInfo getQueryInfo()
+ {
+ return queryInfo;
+ }
+
+ public CDOQueryQueue<Object> getQueue()
+ {
+ return linkQueue;
+ }
+
+ public CDOProtocolView getView()
+ {
+ return view;
+ }
+
+ public long getQueryID()
+ {
+ return queryID;
+ }
+
+ public void setQueryID(long queryID)
+ {
+ this.queryID = queryID;
+ }
+
+ @SuppressWarnings("unchecked")
+ public T peek()
+ {
+ return (T)queueItr.peek();
+ }
+
+ public boolean hasNext()
+ {
+ return queueItr.hasNext();
+ }
+
+ @SuppressWarnings("unchecked")
+ public T next()
+ {
+ return (T)queueItr.next();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void close()
+ {
+ queueItr.close();
+ }
+
+ public boolean isClosed()
+ {
+ return queueItr.isClosed();
+ }
+
+ 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/CDOAbstractQueryResultImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOAbstractQueryResultImpl.java
deleted file mode 100644
index 523c4d3039..0000000000
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOAbstractQueryResultImpl.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/***************************************************************************
- * 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/CDOQueryInfoImpl.java
index e56e43a0dd..6dad77be74 100644
--- 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/CDOQueryInfoImpl.java
@@ -12,13 +12,14 @@ 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.query.CDOQueryInfo;
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.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -26,23 +27,23 @@ import java.util.Map.Entry;
/**
* @author Simon McDuff
*/
-public class CDOQueryParameterImpl implements CDOQueryParameter
+public class CDOQueryInfoImpl implements CDOQueryInfo
{
- private String queryLanguage;
+ protected String queryLanguage;
- private String queryString;
+ protected String queryString;
- private Map<String, Object> parameters = new HashMap<String, Object>();
+ protected Map<String, Object> parameters = new HashMap<String, Object>();
- private int maxResult = -1;
+ protected int maxResult = -1;
- public CDOQueryParameterImpl(String language, String queryString)
+ public CDOQueryInfoImpl(String language, String queryString)
{
this.queryLanguage = language;
this.queryString = queryString;
}
- public CDOQueryParameterImpl(ExtendedDataInput in, CDOIDObjectFactory objectFactory, CDOPackageManager packageManager)
+ public CDOQueryInfoImpl(ExtendedDataInput in, CDOIDObjectFactory objectFactory, CDOPackageManager packageManager)
throws IOException
{
queryLanguage = in.readString();
@@ -53,7 +54,7 @@ public class CDOQueryParameterImpl implements CDOQueryParameter
for (int i = 0; i < size; i++)
{
String key = in.readString();
- Object object = CDOInstanceUtil.readObject(in, objectFactory, packageManager);
+ Object object = CDOInstanceUtil.readObjectOrClass(in, objectFactory, packageManager);
parameters.put(key, object);
}
}
@@ -69,7 +70,7 @@ public class CDOQueryParameterImpl implements CDOQueryParameter
{
out.writeString(entry.getKey());
Object value = entry.getValue();
- CDOInstanceUtil.writeObject(out, value);
+ CDOInstanceUtil.writeObjectOrClass(out, value);
}
}
@@ -85,10 +86,15 @@ public class CDOQueryParameterImpl implements CDOQueryParameter
public Map<String, Object> getParameters()
{
- return parameters;
+ return Collections.unmodifiableMap(parameters);
}
- public int getMaxResult()
+ public void addParameter(String key, Object value)
+ {
+ parameters.put(key, value);
+ }
+
+ public int getMaxResults()
{
return maxResult;
}
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
deleted file mode 100644
index 501ccb1236..0000000000
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/query/CDOQueryState.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/***************************************************************************
- * 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 977bbcc155..c21147aa16 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,7 +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.query.CDOQueryInfo;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.server.IPackageManager;
@@ -292,9 +292,10 @@ public class DBStoreReader extends DBStoreAccessor implements IDBStoreReader
return type.resolve(packageManager);
}
- public CloseableIterator<Object> createQueryIterator(CDOQueryParameter queryParameter)
+ public CloseableIterator<Object> createQueryIterator(CDOQueryInfo queryInfo)
{
- throw new UnsupportedOperationException();
+ // DO NOT MERGE THAT
+ throw new UnsupportedOperationException();
}
public void refreshRevisions()
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
index fedc46aadf..aa09212448 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
@@ -264,6 +264,12 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
return null;
}
+
+ public boolean isClosed()
+ {
+ // DO NOT MERGE THAT
+ return false;
+ }
};
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AutoAttacherTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AutoAttacherTest.java
index 09d6503d23..b10060a21d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AutoAttacherTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AutoAttacherTest.java
@@ -13,7 +13,6 @@ package org.eclipse.emf.cdo.tests;
import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
-import org.eclipse.emf.cdo.tests.model1.Order;
import org.eclipse.emf.cdo.tests.model1.OrderDetail;
import org.eclipse.emf.cdo.tests.model1.Product;
import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
@@ -28,7 +27,7 @@ import org.eclipse.emf.internal.cdo.CDOTransactionImpl;
public class AutoAttacherTest extends AbstractCDOTest
{
- public void testBasic() throws Exception
+ public void testSimple() throws Exception
{
CDOSession session = openModel1Session();
@@ -44,10 +43,7 @@ public class AutoAttacherTest extends AbstractCDOTest
resource1.getContents().add(product);
assertEquals(resource1, product.eResource());
- // assertEquals(resource1, ((EObjectImpl)product).eDirectResource());
-
assertNew(product, transaction);
-
}
OrderDetail orderDetail = Model1Factory.eINSTANCE.createOrderDetail();
@@ -56,22 +52,11 @@ public class AutoAttacherTest extends AbstractCDOTest
product.getOrderDetails().add(orderDetail);
assertNew(orderDetail, transaction);
}
-
- Order order = Model1Factory.eINSTANCE.createOrder();
- {
- // Bidirectionnel/containment relationship
- assertTransient(order);
- // Fail for now. Need to be able to handle that case!
- // order.getOrderDetails().add(orderDetail);
-
- // assertTransient(order);
- }
-
transaction.close();
session.close();
}
- public void testBasic2() throws Exception
+ public void testAddingObjectAndCrawl() throws Exception
{
CDOSession session = openModel1Session();
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
index f6c1a0fa12..3cebe5ad86 100644
--- 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
@@ -15,7 +15,6 @@ 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;
@@ -59,7 +58,7 @@ public class QueryTest extends AbstractCDOTest
transaction.commit();
CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "QUERYSTRING");
- List<Object> queryResult = cdoQuery.getResultList(Object.class);
+ List<Object> queryResult = cdoQuery.getResult(Object.class);
assertEquals(3, queryResult.size());
for (Object object : queryResult)
{
@@ -98,7 +97,7 @@ public class QueryTest extends AbstractCDOTest
cdoQuery.setParameter("context", Model1Package.eINSTANCE.getCategory());
- List<Category> queryResult = cdoQuery.getResultList(Category.class);
+ List<Category> queryResult = cdoQuery.getResult(Category.class);
assertEquals(1, queryResult.size());
assertEquals(category1, queryResult.get(0));
@@ -112,7 +111,7 @@ public class QueryTest extends AbstractCDOTest
CDOTransaction transaction = initialize(1000);
CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "QUERYSTRING");
- CloseableIterator<Object> queryResult = cdoQuery.getResultIterator(Object.class);
+ CloseableIterator<Object> queryResult = cdoQuery.getResultAsync(Object.class);
queryResult.close();
@@ -128,10 +127,7 @@ public class QueryTest extends AbstractCDOTest
CDOTransaction transaction = initialize(100);
CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "QUERYSTRING");
- CloseableIterator<Object> queryResult = cdoQuery.getResultIterator(Object.class);
-
- Thread.sleep(300);
- // queryResult.cancel();
+ CloseableIterator<Object> queryResult = cdoQuery.getResultAsync(Object.class);
transaction.close();
assertEquals(false, ((Repository)getRepository()).getQueryManager().isRunning(
((CDOQueryResultIteratorImpl<?>)queryResult).getQueryID()));
@@ -143,10 +139,7 @@ public class QueryTest extends AbstractCDOTest
CDOTransaction transaction = initialize(100);
CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "QUERYSTRING");
- CloseableIterator<Object> queryResult = cdoQuery.getResultIterator(Object.class);
-
- Thread.sleep(300);
-
+ CloseableIterator<Object> queryResult = cdoQuery.getResultAsync(Object.class);
transaction.getSession().close();
assertEquals(false, ((Repository)getRepository()).getQueryManager().isRunning(
@@ -154,32 +147,6 @@ public class QueryTest extends AbstractCDOTest
}
- public void testQueryCancel_exception() throws Exception
- {
- CDOTransaction transaction = initialize(2);
-
- CDOQuery cdoQuery = transaction.createQuery(LANGUAGE_TEST, "QUERYSTRING");
- CDOQueryResult<Object> queryResult = cdoQuery.getResultIterator(Object.class);
-
- while (!queryResult.isDone())
- {
- Thread.sleep(10);
- }
-
- try
- {
- queryResult.cancel();
- fail("Should throw an exception");
- }
- catch (Exception exception)
- {
-
- }
-
- transaction.close();
- transaction.getSession().close();
- }
-
CDOTransaction initialize(int number)
{
CDOSession session = openModel1Session();

Back to the top