From 16cb0d22809f2897ec88fc80068deb5e0ef8c174 Mon Sep 17 00:00:00 2001 From: Ilya Ermakov Date: Fri, 28 Nov 2014 13:09:38 +0300 Subject: SQLContainer removeItem Error when isModified (#8802) This patch makes commit() work properly if an item was modified and later deleted. Change-Id: I5a00024112e7b6bb7ab3750c292a872937f03af9 --- .../data/util/sqlcontainer/SQLContainer.java | 26 ++++++++++++---------- .../sqlcontainer/SQLContainerTableQueryTest.java | 14 ++++++++++++ 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 @@ -1136,6 +1136,20 @@ public class SQLContainerTableQueryTest { .getValue()); } + @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", -- cgit v1.2.3