aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2012-09-04 16:47:42 +0300
committerHenri Sara <hesara@vaadin.com>2012-09-04 16:47:42 +0300
commite8a5f2082d854085fc9da33d5f837900ef347f4f (patch)
treeebb7cb59236a8605252de61d5fd00d6facdaa6c1 /server
parent99a423cea5a273d7ddcc39a959895931d12533df (diff)
downloadvaadin-framework-e8a5f2082d854085fc9da33d5f837900ef347f4f.tar.gz
vaadin-framework-e8a5f2082d854085fc9da33d5f837900ef347f4f.zip
Fix SQLContainer indexed access and related tests (#9472)
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java14
-rw-r--r--server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java7
-rw-r--r--server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java9
3 files changed, 24 insertions, 6 deletions
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
index 7a63e8c6c2..1b479a21d8 100644
--- a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
+++ b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
@@ -661,7 +661,8 @@ public class SQLContainer implements Container, Container.Filterable,
throw new IndexOutOfBoundsException("Index is negative! index="
+ index);
}
-
+ // make sure the size field is valid
+ updateCount();
if (index < size) {
if (itemIndexes.keySet().contains(index)) {
return itemIndexes.get(index);
@@ -671,7 +672,9 @@ public class SQLContainer implements Container, Container.Filterable,
} else {
// The index is in the added items
int offset = index - size;
- return addedItems.get(offset).getId();
+ // TODO this is very inefficient if looping - should improve
+ // getItemIds(int, int)
+ return getFilteredAddedItems().get(offset).getId();
}
}
@@ -694,7 +697,12 @@ public class SQLContainer implements Container, Container.Filterable,
@Override
public Object nextItemId(Object itemId) {
- return getIdByIndex(indexOfId(itemId) + 1);
+ int index = indexOfId(itemId) + 1;
+ try {
+ return getIdByIndex(index);
+ } catch (IndexOutOfBoundsException e) {
+ return null;
+ }
}
/*
diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java
index 438c40823d..7b3d8a4cf2 100644
--- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java
+++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java
@@ -1468,7 +1468,12 @@ public class SQLContainerTableQueryTest {
container.getContainerProperty(container.getIdByIndex(3),
"NAME").getValue());
- Assert.assertNull(container.getIdByIndex(4));
+ try {
+ container.getIdByIndex(4);
+ Assert.fail("SQLContainer.getIdByIndex() returned a value for an index beyond the end of the container");
+ } catch (IndexOutOfBoundsException e) {
+ // should throw exception - item is filtered out
+ }
Assert.assertNull(container.nextItemId(container.getIdByIndex(3)));
Assert.assertFalse(container.containsId(id2));
diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
index 6649bc16e8..0856b3c08c 100644
--- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
+++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
@@ -2322,8 +2322,13 @@ public class SQLContainerTest {
container.getContainerProperty(container.getIdByIndex(3),
"NAME").getValue());
- Assert.assertNull(container.getIdByIndex(4));
- Assert.assertNull(container.nextItemId(container.getIdByIndex(3)));
+ try {
+ container.getIdByIndex(4);
+ Assert.fail("SQLContainer.getIdByIndex() returned a value for an index beyond the end of the container");
+ } catch (IndexOutOfBoundsException e) {
+ // should throw exception - item is filtered out
+ }
+ container.nextItemId(container.getIdByIndex(3));
Assert.assertFalse(container.containsId(id2));
Assert.assertFalse(container.getItemIds().contains(id2));