]> source.dussan.org Git - vaadin-framework.git/commitdiff
SQLContainer removeItem Error when isModified (#8802)
authorIlya Ermakov <ilya403403@gmail.com>
Fri, 28 Nov 2014 10:09:38 +0000 (13:09 +0300)
committerSauli Tähkäpää <sauli@vaadin.com>
Tue, 9 Dec 2014 10:17:27 +0000 (12:17 +0200)
This patch makes commit() work properly if an item was modified and later deleted.

Change-Id: I5a00024112e7b6bb7ab3750c292a872937f03af9

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

index 683140d27955fb87172f14031c0a7d4c80a5a845..70b392ab800b95b689941125b820633a9d88c84f 100644 (file)
@@ -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 */
index d907f12321eefdf76c4cca099b7d2d2fb65fd6b8..93a27352a56b51f800968e83e7810c2af344ed64 100644 (file)
@@ -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",