From 9148b35e9ea0cc6882ba2f8560d97138d7ca362a Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Fri, 27 Jul 2012 10:01:38 +0000 Subject: [PATCH] #9155 Add refresh() to SQLContainer.removeContainerFilter(), one more (manual) test for SQLContainer and refactoring another test. svn changeset:24029/svn branch:6.8 --- .../data/util/sqlcontainer/SQLContainer.java | 1 + .../sqlcontainer/CheckboxUpdateProblem.java | 78 ---------------- .../sqlcontainer/ComboBoxUpdateProblem.java | 27 ++++++ .../sqlcontainer/DatabaseHelper.java | 91 +++++++++++++++++++ 4 files changed, 119 insertions(+), 78 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/containers/sqlcontainer/ComboBoxUpdateProblem.java create mode 100644 tests/testbench/com/vaadin/tests/containers/sqlcontainer/DatabaseHelper.java diff --git a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java index 242a977614..156b51b94c 100644 --- a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java +++ b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java @@ -510,6 +510,7 @@ public class SQLContainer implements Container, Container.Filterable, */ public void removeContainerFilter(Filter filter) { filters.remove(filter); + refresh(); } /** diff --git a/tests/testbench/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java b/tests/testbench/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java index 86aee2d5ab..e06db94589 100644 --- a/tests/testbench/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java +++ b/tests/testbench/com/vaadin/tests/containers/sqlcontainer/CheckboxUpdateProblem.java @@ -1,8 +1,6 @@ package com.vaadin.tests.containers.sqlcontainer; -import java.sql.Connection; import java.sql.SQLException; -import java.sql.Statement; import com.vaadin.Application; import com.vaadin.data.Container.ItemSetChangeEvent; @@ -10,11 +8,6 @@ import com.vaadin.data.Container.ItemSetChangeListener; import com.vaadin.data.Item; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; -import com.vaadin.data.util.sqlcontainer.AllTests; -import com.vaadin.data.util.sqlcontainer.SQLContainer; -import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool; -import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool; -import com.vaadin.data.util.sqlcontainer.query.TableQuery; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; @@ -116,75 +109,4 @@ public class CheckboxUpdateProblem extends Application implements } - private class DatabaseHelper { - - private JDBCConnectionPool connectionPool = null; - private SQLContainer testContainer = null; - private static final String TABLENAME = "testtable"; - - public DatabaseHelper() { - initConnectionPool(); - initDatabase(); - initContainers(); - } - - private void initDatabase() { - try { - Connection conn = connectionPool.reserveConnection(); - Statement statement = conn.createStatement(); - try { - statement.execute("drop table " + TABLENAME); - } catch (SQLException e) { - // Will fail if table doesn't exist, which is OK. - conn.rollback(); - } - switch (AllTests.db) { - case MYSQL: - statement - .execute("create table " - + TABLENAME - + " (id integer auto_increment not null, field1 varchar(100), field2 boolean, primary key(id))"); - break; - case POSTGRESQL: - statement - .execute("create table " - + TABLENAME - + " (\"id\" serial primary key, \"field1\" varchar(100), \"field2\" boolean)"); - break; - } - statement.executeUpdate("insert into " + TABLENAME - + " values(default, 'Kalle', 'true')"); - statement.close(); - conn.commit(); - connectionPool.releaseConnection(conn); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - private void initContainers() { - try { - TableQuery q1 = new TableQuery(TABLENAME, connectionPool); - q1.setVersionColumn("id"); - testContainer = new SQLContainer(q1); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - private void initConnectionPool() { - try { - connectionPool = new SimpleJDBCConnectionPool( - AllTests.dbDriver, AllTests.dbURL, AllTests.dbUser, - AllTests.dbPwd, 2, 5); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public SQLContainer getTestContainer() { - return testContainer; - } - } - } \ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/containers/sqlcontainer/ComboBoxUpdateProblem.java b/tests/testbench/com/vaadin/tests/containers/sqlcontainer/ComboBoxUpdateProblem.java new file mode 100644 index 0000000000..ed6d39bb62 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/containers/sqlcontainer/ComboBoxUpdateProblem.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.containers.sqlcontainer; + +import com.vaadin.Application; +import com.vaadin.ui.AbstractSelect.Filtering; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Window; + +/** + * See http://dev.vaadin.com/ticket/9155 . + */ +public class ComboBoxUpdateProblem extends Application { + private final DatabaseHelper databaseHelper = new DatabaseHelper(); + + @Override + public void init() { + setMainWindow(new Window("Test window")); + + ComboBox combo = new ComboBox("Names", + databaseHelper.getTestContainer()); + combo.setItemCaptionPropertyId("FIELD1"); + combo.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS); + combo.setImmediate(true); + + getMainWindow().addComponent(combo); + } + +} \ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/containers/sqlcontainer/DatabaseHelper.java b/tests/testbench/com/vaadin/tests/containers/sqlcontainer/DatabaseHelper.java new file mode 100644 index 0000000000..b7b1e74eb0 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/containers/sqlcontainer/DatabaseHelper.java @@ -0,0 +1,91 @@ +package com.vaadin.tests.containers.sqlcontainer; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +import com.vaadin.data.util.sqlcontainer.AllTests; +import com.vaadin.data.util.sqlcontainer.SQLContainer; +import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool; +import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool; +import com.vaadin.data.util.sqlcontainer.query.TableQuery; + +class DatabaseHelper { + + private JDBCConnectionPool connectionPool = null; + private SQLContainer testContainer = null; + private static final String TABLENAME = "testtable"; + + public DatabaseHelper() { + initConnectionPool(); + initDatabase(); + initContainers(); + } + + private void initDatabase() { + try { + Connection conn = connectionPool.reserveConnection(); + Statement statement = conn.createStatement(); + try { + statement.execute("drop table " + TABLENAME); + } catch (SQLException e) { + // Will fail if table doesn't exist, which is OK. + conn.rollback(); + } + switch (AllTests.db) { + case HSQLDB: + statement + .execute("create table " + + TABLENAME + + " (id integer GENERATED BY DEFAULT AS IDENTITY, field1 varchar(100), field2 boolean, primary key(id))"); + break; + case MYSQL: + statement + .execute("create table " + + TABLENAME + + " (id integer auto_increment not null, field1 varchar(100), field2 boolean, primary key(id))"); + break; + case POSTGRESQL: + statement + .execute("create table " + + TABLENAME + + " (\"id\" serial primary key, \"field1\" varchar(100), \"field2\" boolean)"); + break; + } + statement.executeUpdate("insert into " + TABLENAME + + " values(default, 'Kalle', 'true')"); + statement.executeUpdate("insert into " + TABLENAME + + " values(default, 'Ville', 'true')"); + statement.executeUpdate("insert into " + TABLENAME + + " values(default, 'Jussi', 'true')"); + statement.close(); + conn.commit(); + connectionPool.releaseConnection(conn); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void initContainers() { + try { + TableQuery q1 = new TableQuery(TABLENAME, connectionPool); + q1.setVersionColumn("id"); + testContainer = new SQLContainer(q1); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void initConnectionPool() { + try { + connectionPool = new SimpleJDBCConnectionPool(AllTests.dbDriver, + AllTests.dbURL, AllTests.dbUser, AllTests.dbPwd, 2, 5); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public SQLContainer getTestContainer() { + return testContainer; + } +} \ No newline at end of file -- 2.39.5