Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Taal2009-07-17 09:02:19 +0000
committerMartin Taal2009-07-17 09:02:19 +0000
commitf13eceacd20c860707746f29d4de9c2c872897b6 (patch)
tree1c35e823808e0b86a716491d4b7c72f15bdcc844 /plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query
parent24f709f6dfa5a038c13e548b4933b9bc69f3e8e8 (diff)
downloadcdo-f13eceacd20c860707746f29d4de9c2c872897b6.tar.gz
cdo-f13eceacd20c860707746f29d4de9c2c872897b6.tar.xz
cdo-f13eceacd20c860707746f29d4de9c2c872897b6.zip
[282612] CDOQuery results should support array of primitive types
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOEList.java239
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java214
2 files changed, 212 insertions, 241 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOEList.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOEList.java
deleted file mode 100644
index d25d9bbaaf..0000000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOEList.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Simon McDuff - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.internal.cdo.query;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.view.CDOView;
-
-import org.eclipse.emf.common.util.EList;
-
-import java.lang.reflect.Array;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * TODO Simon: Do we really need this list?
- *
- * @author Simon McDuff
- */
-public class CDOEList<T> implements EList<T>
-{
- private CDOView view;
-
- private List<Object> objects;
-
- public CDOEList(CDOView view, List<Object> objects)
- {
- this.view = view;
- this.objects = objects;
- }
-
- @SuppressWarnings("unchecked")
- protected T adapt(CDOID id)
- {
- if (CDOIDUtil.isNull(id))
- {
- return null;
- }
-
- return (T)view.getObject(id, 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.objects.get(index);
- if (object instanceof CDOID)
- {
- object = adapt((CDOID)object);
- }
-
- return (T)object;
- }
-
- public boolean isEmpty()
- {
- return objects.isEmpty();
- }
-
- public Iterator<T> iterator()
- {
- return new ECDOIDIterator(this.objects.iterator());
- }
-
- public void move(int newPosition, T object)
- {
- throw new UnsupportedOperationException();
- }
-
- public T move(int newPosition, int oldPosition)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(Collection<? extends T> arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(int arg0, Collection<? extends T> arg1)
- {
- throw new UnsupportedOperationException();
- }
-
- public void clear()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean contains(Object arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean containsAll(Collection<?> arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public int indexOf(Object arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public int lastIndexOf(Object arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public ListIterator<T> listIterator()
- {
- throw new UnsupportedOperationException();
- }
-
- public ListIterator<T> listIterator(int arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean remove(Object arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public T remove(int arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean removeAll(Collection<?> arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean retainAll(Collection<?> arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public T set(int arg0, T arg1)
- {
- throw new UnsupportedOperationException();
- }
-
- public int size()
- {
- return objects.size();
- }
-
- public List<T> subList(int arg0, int arg1)
- {
- throw new UnsupportedOperationException();
- }
-
- public Object[] toArray()
- {
- Object array[] = new Object[size()];
- return toArray(array);
- }
-
- @SuppressWarnings("unchecked")
- public <E> E[] toArray(E[] input)
- {
- int size = size();
- if (input.length < size)
- {
- input = (E[])Array.newInstance(input.getClass(), size);
- }
-
- // TODO It will be more efficient to load all objects at once.
- for (int i = 0; i < size; i++)
- {
- input[i] = (E)get(i);
- }
-
- if (input.length > size)
- {
- input[size] = null;
- }
-
- return input;
- }
-
- /**
- * @author Simon McDuff
- */
- private class ECDOIDIterator implements Iterator<T>
- {
- private Iterator<Object> iterator;
-
- public ECDOIDIterator(Iterator<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);
- }
-
- return (T)object;
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- }
-}
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
index 8caf9af18e..7faca491bf 100644
--- 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
@@ -4,7 +4,7 @@
* 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
* Eike Stepper - maintenance
@@ -15,10 +15,15 @@ import org.eclipse.emf.cdo.common.CDOQueryInfo;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.spi.cdo.AbstractQueryIterator;
+import java.lang.reflect.Array;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
/**
* @author Simon McDuff
@@ -49,6 +54,26 @@ public class CDOQueryResultIteratorImpl<T> extends AbstractQueryIterator<T>
return (T)getView().getObject((CDOID)object, true);
}
+ // Support a query return value of Object[]
+ if (object instanceof Object[])
+ {
+ Object[] objects = (Object[])object;
+ Object[] resolvedObjects = new Object[objects.length];
+ for (int i = 0; i < objects.length; i++)
+ {
+ if (objects[i] instanceof CDOID)
+ {
+ resolvedObjects[i] = adapt(objects[i]);
+ }
+ else
+ {
+ resolvedObjects[i] = objects[i];
+ }
+ }
+
+ return (T)resolvedObjects;
+ }
+
return (T)object;
}
@@ -61,6 +86,191 @@ public class CDOQueryResultIteratorImpl<T> extends AbstractQueryIterator<T>
result.add(super.next());
}
- return new CDOEList<T>(getView(), result);
+ return new QueryResultList(result);
+ }
+
+ /**
+ * @author Simon McDuff
+ */
+ private class QueryResultList implements EList<T>
+ {
+ private List<Object> objects;
+
+ public QueryResultList(List<Object> objects)
+ {
+ this.objects = objects;
+ }
+
+ public boolean add(T o)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void add(int index, T element)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public T get(int index)
+ {
+ return adapt(objects.get(index));
+ }
+
+ public boolean isEmpty()
+ {
+ return objects.isEmpty();
+ }
+
+ public Iterator<T> iterator()
+ {
+ return new ECDOIDIterator(this.objects.iterator());
+ }
+
+ public void move(int newPosition, T object)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public T move(int newPosition, int oldPosition)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection<? extends T> arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(int arg0, Collection<? extends T> arg1)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean contains(Object arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean containsAll(Collection<?> arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int indexOf(Object arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int lastIndexOf(Object arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public ListIterator<T> listIterator()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public ListIterator<T> listIterator(int arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public T remove(int arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection<?> arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection<?> arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public T set(int arg0, T arg1)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size()
+ {
+ return objects.size();
+ }
+
+ public List<T> subList(int arg0, int arg1)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object[] toArray()
+ {
+ Object array[] = new Object[size()];
+ return toArray(array);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <E> E[] toArray(E[] input)
+ {
+ int size = size();
+ if (input.length < size)
+ {
+ input = (E[])Array.newInstance(input.getClass(), size);
+ }
+
+ // TODO It will be more efficient to load all objects at once.
+ for (int i = 0; i < size; i++)
+ {
+ input[i] = (E)get(i);
+ }
+
+ if (input.length > size)
+ {
+ input[size] = null;
+ }
+
+ return input;
+ }
+
+ /**
+ * @author Simon McDuff
+ */
+ private class ECDOIDIterator implements Iterator<T>
+ {
+ private Iterator<Object> iterator;
+
+ public ECDOIDIterator(Iterator<Object> iterator)
+ {
+ this.iterator = iterator;
+ }
+
+ public boolean hasNext()
+ {
+ return iterator.hasNext();
+ }
+
+ public T next()
+ {
+ return adapt(iterator.next());
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
}
}

Back to the top