summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-11-12 16:38:43 +0200
committerVaadin Code Review <review@vaadin.com>2012-11-28 11:47:12 +0000
commit7fecb899c85c038415633857865cc5f20a3ab20e (patch)
tree8f67aa0f779aeb4060674b77f6b372e381031bb4
parent42f402de0e2ecb9e2816156ed78225cb41258390 (diff)
downloadvaadin-framework-7fecb899c85c038415633857865cc5f20a3ab20e.tar.gz
vaadin-framework-7fecb899c85c038415633857865cc5f20a3ab20e.zip
getPrevItemId should return null if id not found (#10124)
Change-Id: I9c0a07610e942bf8fac5832341a4fb31bfd6342a
-rw-r--r--server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java7
-rw-r--r--server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java18
2 files changed, 24 insertions, 1 deletions
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
index 305b7d5861..12cb892090 100644
--- a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
+++ b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
@@ -713,7 +713,12 @@ public class SQLContainer implements Container, Container.Filterable,
@Override
public Object prevItemId(Object itemId) {
- return getIdByIndex(indexOfId(itemId) - 1);
+ int prevIndex = indexOfId(itemId) - 1;
+ try {
+ return getIdByIndex(prevIndex);
+ } catch (IndexOutOfBoundsException e) {
+ return null;
+ }
}
/*
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 64288326f0..844ef705b1 100644
--- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
+++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
@@ -162,6 +162,24 @@ public class SQLContainerTest {
}
@Test
+ public void nextItemNullAtEnd_freeformExistingItem() throws SQLException {
+ SQLContainer container = new SQLContainer(new FreeformQuery(
+ "SELECT * FROM people", connectionPool, "ID"));
+ Object lastItemId = container.lastItemId();
+ Object afterLast = container.nextItemId(lastItemId);
+ Assert.assertNull(afterLast);
+ }
+
+ @Test
+ public void prevItemNullAtStart_freeformExistingItem() throws SQLException {
+ SQLContainer container = new SQLContainer(new FreeformQuery(
+ "SELECT * FROM people", connectionPool, "ID"));
+ Object firstItemId = container.firstItemId();
+ Object beforeFirst = container.prevItemId(firstItemId);
+ Assert.assertNull(beforeFirst);
+ }
+
+ @Test
public void getItem_freeform5000RowsWithParameter1337_returnsItemWithId1337()
throws SQLException {
DataGenerator.addFiveThousandPeople(connectionPool);