]> source.dussan.org Git - vaadin-framework.git/commitdiff
getPrevItemId should return null if id not found (#10124) 47/247/3
authorArtur Signell <artur@vaadin.com>
Mon, 12 Nov 2012 14:38:43 +0000 (16:38 +0200)
committerVaadin Code Review <review@vaadin.com>
Wed, 28 Nov 2012 11:47:12 +0000 (11:47 +0000)
Change-Id: I9c0a07610e942bf8fac5832341a4fb31bfd6342a

server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java

index 305b7d5861b8ca05bec0172c68e3fd7b77aaa6cb..12cb892090e5173e7e532dc8c435a5ce8875c9b8 100644 (file)
@@ -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;
+        }
     }
 
     /*
index 64288326f037c1786b8cb128cd2d0736e009fb74..844ef705b1d7386e233419b894f59ea13bffbd2d 100644 (file)
@@ -161,6 +161,24 @@ public class SQLContainerTest {
         Assert.assertEquals("Ville", item.getItemProperty("NAME").getValue());
     }
 
+    @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 {