diff options
author | Ilya Ermakov <ilya403403@gmail.com> | 2014-12-03 13:43:15 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-12-12 06:31:02 +0000 |
commit | 3bc4ff53736ed2a0c3e9e362be3e7de481d1d00f (patch) | |
tree | 28eb03f89768f73dd5bfd625a2a7ea10a0cc5ea2 | |
parent | dd879668f5f74dfea8a804f3ff3c1e7c2f89a5a3 (diff) | |
download | vaadin-framework-3bc4ff53736ed2a0c3e9e362be3e7de481d1d00f.tar.gz vaadin-framework-3bc4ff53736ed2a0c3e9e362be3e7de481d1d00f.zip |
Make SQLContainer.removeAllItems() work properly with paging (#12882)
With this patch removeAllItems() works properly when
items need to be fetched from database.
Change-Id: Ic008ae7c67610cbdde7d71fa071494508678ac8f
-rw-r--r-- | server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java | 1 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java | 20 |
2 files changed, 20 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 70b392ab80..c0c660c084 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java @@ -652,7 +652,6 @@ public class SQLContainer implements Container, Container.Filterable, if (cachedItems.isEmpty()) { getPage(); } - int size = size(); // this protects against infinite looping int counter = 0; int oldIndex; 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 93a27352a5..fbae0ee159 100644 --- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java +++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java @@ -1071,6 +1071,26 @@ public class SQLContainerTableQueryTest { Assert.assertEquals(0, container.size()); } + // Set timeout to ensure there is no infinite looping (#12882) + @Test(timeout = 1000) + public void removeAllItems_manyItems_commit_shouldSucceed() + throws SQLException { + SQLContainer container = new SQLContainer(new TableQuery("people", + connectionPool, SQLTestsConstants.sqlGen)); + final int itemNumber = (SQLContainer.CACHE_RATIO + 1) + * SQLContainer.DEFAULT_PAGE_LENGTH + 1; + container.removeAllItems(); + Assert.assertEquals(container.size(), 0); + for (int i = 0; i < itemNumber; ++i) { + container.addItem(); + } + container.commit(); + Assert.assertEquals(container.size(), itemNumber); + Assert.assertTrue(container.removeAllItems()); + container.commit(); + Assert.assertEquals(container.size(), 0); + } + @Test public void commit_tableAddedItem_shouldBeWrittenToDB() throws SQLException { TableQuery query = new TableQuery("people", connectionPool, |