summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Ermakov <ilya403403@gmail.com>2014-11-28 13:09:38 +0300
committerSauli Tähkäpää <sauli@vaadin.com>2014-12-09 12:17:27 +0200
commit16cb0d22809f2897ec88fc80068deb5e0ef8c174 (patch)
tree391470da3bfd32d89898e69fb7df77cb49425c03
parent3e3a1cd47da6478a0c308b42925928b9e11ef968 (diff)
downloadvaadin-framework-16cb0d22809f2897ec88fc80068deb5e0ef8c174.tar.gz
vaadin-framework-16cb0d22809f2897ec88fc80068deb5e0ef8c174.zip
SQLContainer removeItem Error when isModified (#8802)
This patch makes commit() work properly if an item was modified and later deleted. Change-Id: I5a00024112e7b6bb7ab3750c292a872937f03af9
-rw-r--r--server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java26
-rw-r--r--server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java14
2 files changed, 28 insertions, 12 deletions
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
index 683140d279..70b392ab80 100644
--- a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
+++ b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java
@@ -1020,18 +1020,20 @@ public class SQLContainer implements Container, Container.Filterable,
}
/* Perform buffered modifications */
for (RowItem item : modifiedItems) {
- if (queryDelegate.storeRow(item) > 0) {
- /*
- * Also reset the modified state in the item in case it is
- * reused e.g. in a form.
- */
- item.commit();
- } else {
- queryDelegate.rollback();
- refresh();
- throw new ConcurrentModificationException(
- "Item with the ID '" + item.getId()
- + "' has been externally modified.");
+ if (!removedItems.containsKey(item.getId())) {
+ if (queryDelegate.storeRow(item) > 0) {
+ /*
+ * Also reset the modified state in the item in case it
+ * is reused e.g. in a form.
+ */
+ item.commit();
+ } else {
+ queryDelegate.rollback();
+ refresh();
+ throw new ConcurrentModificationException(
+ "Item with the ID '" + item.getId()
+ + "' has been externally modified.");
+ }
}
}
/* Perform buffered additions */
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 d907f12321..93a27352a5 100644
--- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java
+++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java
@@ -1137,6 +1137,20 @@ public class SQLContainerTableQueryTest {
}
@Test
+ public void commit_removeModifiedItem_shouldSucceed() throws SQLException {
+ TableQuery query = new TableQuery("people", connectionPool,
+ SQLTestsConstants.sqlGen);
+ SQLContainer container = new SQLContainer(query);
+ int size = container.size();
+ Object key = container.firstItemId();
+ Item row = container.getItem(key);
+ row.getItemProperty("NAME").setValue("Pekka");
+ Assert.assertTrue(container.removeItem(key));
+ container.commit();
+ Assert.assertEquals(size - 1, container.size());
+ }
+
+ @Test
public void rollback_tableItemAdded_discardsAddedItem() throws SQLException {
SQLContainer container = new SQLContainer(new TableQuery("people",
connectionPool, SQLTestsConstants.sqlGen));