Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_397948_Test.java134
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java171
2 files changed, 143 insertions, 162 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_397948_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_397948_Test.java
new file mode 100644
index 0000000000..1e8c9274eb
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_397948_Test.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.view.CDOQuery;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * Bug 397948: UnsupportedOperationException CDOQueryResultIteratorImpl$QueryResultList.contains(CDOQueryResultIteratorImpl.java:204)
+ *
+ * @author Eike Stepper
+ */
+@Requires("MEM")
+public class Bugzilla_397948_Test extends AbstractCDOTest
+{
+ public void testContains() throws Exception
+ {
+ List<Category> result = executeQuery();
+ result.contains(getModel1Factory().createCategory());
+ }
+
+ public void testGet() throws Exception
+ {
+ List<Category> result = executeQuery();
+ result.get(0);
+ result.get(1);
+ }
+
+ public void testIndexOf() throws Exception
+ {
+ List<Category> result = executeQuery();
+ result.indexOf(getModel1Factory().createCategory());
+ }
+
+ public void testLastIndexOf() throws Exception
+ {
+ List<Category> result = executeQuery();
+ result.lastIndexOf(getModel1Factory().createCategory());
+ }
+
+ public void testIsEmpty() throws Exception
+ {
+ List<Category> result = executeQuery();
+ result.isEmpty();
+ }
+
+ public void testIterator() throws Exception
+ {
+ List<Category> result = executeQuery();
+ Iterator<Category> iterator = result.iterator();
+ iterator.next();
+ iterator.next();
+ }
+
+ public void testListIterator() throws Exception
+ {
+ List<Category> result = executeQuery();
+ ListIterator<Category> iterator = result.listIterator();
+ iterator.next();
+ iterator.next();
+ iterator.previous();
+ iterator.previous();
+ }
+
+ public void testListIteratorFromEnd() throws Exception
+ {
+ List<Category> result = executeQuery();
+ ListIterator<Category> iterator = result.listIterator(2);
+ iterator.previous();
+ iterator.previous();
+ iterator.next();
+ iterator.next();
+ }
+
+ public void testSubList() throws Exception
+ {
+ List<Category> result = executeQuery();
+ assertEquals(2, result.subList(0, 2).size());
+ assertEquals(1, result.subList(1, 2).size());
+ assertEquals(0, result.subList(2, 2).size());
+ }
+
+ public void testToArray() throws Exception
+ {
+ List<Category> result = executeQuery();
+ result.toArray();
+ result.toArray(new Category[result.size()]);
+ }
+
+ private List<Category> executeQuery() throws CommitException
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/test1"));
+
+ Company company = getModel1Factory().createCompany();
+ company.setName("TEST");
+ resource.getContents().add(company);
+
+ Category category1 = getModel1Factory().createCategory();
+ company.getCategories().add(category1);
+
+ Category category2 = getModel1Factory().createCategory();
+ company.getCategories().add(category2);
+
+ transaction.commit();
+
+ CDOQuery query = transaction.createQuery("TEST", "QUERYSTRING");
+ query.setParameter("context", getModel1Package().getCategory());
+
+ List<Category> result = query.getResult(Category.class);
+ assertEquals(2, result.size());
+ return result;
+ }
+}
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 ff66345f24..51d59afcbd 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
@@ -22,12 +22,9 @@ 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.AbstractList;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
/**
@@ -140,7 +137,7 @@ public class CDOQueryResultIteratorImpl<T> extends AbstractQueryIterator<T>
/**
* @author Simon McDuff
*/
- private class QueryResultList implements EList<T>
+ private class QueryResultList extends AbstractList<T> implements EList<T>
{
private List<Object> objects;
@@ -149,29 +146,22 @@ public class CDOQueryResultIteratorImpl<T> extends AbstractQueryIterator<T>
this.objects = objects;
}
- public boolean add(T o)
- {
- throw new UnsupportedOperationException();
- }
-
- public void add(int index, T element)
- {
- throw new UnsupportedOperationException();
- }
-
+ @Override
public T get(int index)
{
return adapt(objects.get(index));
}
- public boolean isEmpty()
+ @Override
+ public int size()
{
- return objects.isEmpty();
+ return objects.size();
}
- public Iterator<T> iterator()
+ @Override
+ public String toString()
{
- return new ECDOIDIterator(this.objects.iterator());
+ return "QueryResultList" + objects.toString();
}
public void move(int newPosition, T object)
@@ -183,148 +173,5 @@ public class CDOQueryResultIteratorImpl<T> extends AbstractQueryIterator<T>
{
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;
- }
-
- @Override
- public String toString()
- {
- return objects.toString();
- }
-
- /**
- * @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