]> source.dussan.org Git - vaadin-framework.git/commitdiff
Do not leave transaction open if remove fails (#17858)
authorArtur Signell <artur@vaadin.com>
Fri, 15 May 2015 19:59:05 +0000 (22:59 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 18 May 2015 16:48:06 +0000 (16:48 +0000)
Change-Id: Iae9243bd0dc90e130e2866adef472a4d09c4a16f

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

index c0c660c084adff334b7fd294f4c24eb311a03f3d..f07b7ecc587a35b8c3102e1d0abcca78ee4a2b5f 100644 (file)
@@ -1012,9 +1012,15 @@ public class SQLContainer implements Container, Container.Filterable,
             queryDelegate.beginTransaction();
             /* Perform buffered deletions */
             for (RowItem item : removedItems.values()) {
-                if (!queryDelegate.removeRow(item)) {
+                try {
+                    if (!queryDelegate.removeRow(item)) {
+                        throw new SQLException(
+                                "Removal failed for row with ID: "
+                                        + item.getId());
+                    }
+                } catch (IllegalArgumentException e) {
                     throw new SQLException("Removal failed for row with ID: "
-                            + item.getId());
+                            + item.getId(), e);
                 }
             }
             /* Perform buffered modifications */
index 92d0c49205c2addf52bb19d4fd97d2d10579feec..b2cc9a5d0c5734d807b4ca1928eb655f05419971 100644 (file)
@@ -99,23 +99,14 @@ public class SQLContainerTableQueryTest {
         assertTrue(container.removeItem(container.lastItemId()));
     }
 
-    @Test
+    @Test(expected = SQLException.class)
     public void itemWithNonExistingVersionColumnCannotBeRemoved()
             throws SQLException {
         query.setVersionColumn("version");
 
         container.removeItem(container.lastItemId());
 
-        // FIXME Remove try-catch when https://dev.vaadin.com/ticket/17858 is
-        // fixed
-        try {
-            container.commit();
-            Assert.fail("Commit should not succeed when version column does not exist");
-        } catch (IllegalArgumentException e) {
-            // This should not be here at all as commit() should not leave the
-            // transaction open!
-            container.getQueryDelegate().rollback();
-        }
+        container.commit();
     }
 
     @Test