From 36a201f22f66989bf7a78ce8afce1ee64aaa0a22 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 6 Mar 2013 14:55:15 +0200 Subject: Fixed focus and tab index handling for UI (#11129) Change-Id: I80377792ade11946337e2900a7ea84209ae1d060 --- server/src/com/vaadin/ui/UI.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index d12c8d89c9..796d1f08ea 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -78,7 +78,7 @@ import com.vaadin.util.CurrentInstance; * @since 7.0 */ public abstract class UI extends AbstractSingleComponentContainer implements - Action.Container, Action.Notifier, LegacyComponent { + Action.Container, Action.Notifier, LegacyComponent, Focusable { /** * The application to which this UI belongs @@ -183,6 +183,11 @@ public abstract class UI extends AbstractSingleComponentContainer implements return (UIState) super.getState(); } + @Override + protected UIState getState(boolean markAsDirty) { + return (UIState) super.getState(markAsDirty); + } + @Override public Class getStateType() { // This is a workaround for a problem with creating the correct state @@ -1039,4 +1044,14 @@ public abstract class UI extends AbstractSingleComponentContainer implements } super.setContent(content); } + + @Override + public void setTabIndex(int tabIndex) { + getState().tabIndex = tabIndex; + } + + @Override + public int getTabIndex() { + return getState(false).tabIndex; + } } -- cgit v1.2.3 From 6b49a6dce955537ea093db85ebc50d070690820b Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 12 Mar 2013 16:22:36 +0200 Subject: Eliminate connection/statement/result set leaks in TableQuery (#10582) Includes some refactoring to extract common parts of FreeformQuery and TableQuery to AbstractTransactionalQuery. svn changeset:25541/svn branch:6.8 Added missing Serializable for AbstractTransactionalQuery (#10582). svn changeset:25559/svn branch:6.8 Conflicts: server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java Change-Id: I3d055e0f071739ac4536fddb0f49b8d6b8e6d07b --- .../query/AbstractTransactionalQuery.java | 185 ++++++++++++++++++ .../util/sqlcontainer/query/FreeformQuery.java | 130 ++----------- .../data/util/sqlcontainer/query/TableQuery.java | 207 +++++++++------------ 3 files changed, 292 insertions(+), 230 deletions(-) create mode 100644 server/src/com/vaadin/data/util/sqlcontainer/query/AbstractTransactionalQuery.java (limited to 'server') diff --git a/server/src/com/vaadin/data/util/sqlcontainer/query/AbstractTransactionalQuery.java b/server/src/com/vaadin/data/util/sqlcontainer/query/AbstractTransactionalQuery.java new file mode 100644 index 0000000000..3264118732 --- /dev/null +++ b/server/src/com/vaadin/data/util/sqlcontainer/query/AbstractTransactionalQuery.java @@ -0,0 +1,185 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.data.util.sqlcontainer.query; + +import java.io.Serializable; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool; + +/** + * Common base class for database query classes that handle connections and + * transactions. + * + * @author Vaadin Ltd + * @since 6.8.9 + */ +abstract class AbstractTransactionalQuery implements Serializable { + + private JDBCConnectionPool connectionPool; + private transient Connection activeConnection; + + AbstractTransactionalQuery() { + } + + AbstractTransactionalQuery(JDBCConnectionPool connectionPool) { + this.connectionPool = connectionPool; + } + + /** + * Reserves a connection with auto-commit off if no transaction is in + * progress. + * + * @throws IllegalStateException + * if a transaction is already open + * @throws SQLException + * if a connection could not be obtained or configured + */ + public void beginTransaction() throws UnsupportedOperationException, + SQLException { + if (isInTransaction()) { + throw new IllegalStateException("A transaction is already active!"); + } + activeConnection = connectionPool.reserveConnection(); + activeConnection.setAutoCommit(false); + } + + /** + * Commits (if not in auto-commit mode) and releases the active connection. + * + * @throws SQLException + * if not in a transaction managed by this query + */ + public void commit() throws UnsupportedOperationException, SQLException { + if (!isInTransaction()) { + throw new SQLException("No active transaction"); + } + if (!activeConnection.getAutoCommit()) { + activeConnection.commit(); + } + connectionPool.releaseConnection(activeConnection); + activeConnection = null; + } + + /** + * Rolls back and releases the active connection. + * + * @throws SQLException + * if not in a transaction managed by this query + */ + public void rollback() throws UnsupportedOperationException, SQLException { + if (!isInTransaction()) { + throw new SQLException("No active transaction"); + } + activeConnection.rollback(); + connectionPool.releaseConnection(activeConnection); + activeConnection = null; + } + + /** + * Check that a transaction is active. + * + * @throws SQLException + * if no active transaction + */ + protected void ensureTransaction() throws SQLException { + if (!isInTransaction()) { + throw new SQLException("No active transaction!"); + } + } + + /** + * Closes a statement and a resultset, then releases the connection if it is + * not part of an active transaction. A failure in closing one of the + * parameters does not prevent closing the rest. + * + * If the statement is a {@link PreparedStatement}, its parameters are + * cleared prior to closing the statement. + * + * Although JDBC specification does state that closing a statement closes + * its result set and closing a connection closes statements and result + * sets, this method does try to close the result set and statement + * explicitly whenever not null. This can guard against bugs in certain JDBC + * drivers and reduce leaks in case e.g. closing the result set succeeds but + * closing the statement or connection fails. + * + * @param conn + * the connection to release + * @param statement + * the statement to close, may be null to skip closing + * @param rs + * the result set to close, may be null to skip closing + * @throws SQLException + * if closing the result set or the statement fails + */ + protected void releaseConnection(Connection conn, Statement statement, + ResultSet rs) throws SQLException { + try { + try { + if (null != rs) { + rs.close(); + } + } finally { + if (null != statement) { + if (statement instanceof PreparedStatement) { + try { + ((PreparedStatement) statement).clearParameters(); + } catch (Exception e) { + // will be closed below anyway + } + } + statement.close(); + } + } + } finally { + releaseConnection(conn); + } + } + + /** + * Returns the currently active connection, reserves and returns a new + * connection if no active connection. + * + * @return previously active or newly reserved connection + * @throws SQLException + */ + protected Connection getConnection() throws SQLException { + if (activeConnection != null) { + return activeConnection; + } + return connectionPool.reserveConnection(); + } + + protected boolean isInTransaction() { + return activeConnection != null; + } + + /** + * Releases the connection if it is not part of an active transaction. + * + * @param conn + * the connection to release + */ + private void releaseConnection(Connection conn) { + if (conn != activeConnection && conn != null) { + connectionPool.releaseConnection(conn); + } + } +} diff --git a/server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java b/server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java index 299183f5e6..6895e02147 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java @@ -34,13 +34,12 @@ import com.vaadin.data.util.sqlcontainer.query.generator.StatementHelper; import com.vaadin.data.util.sqlcontainer.query.generator.filter.QueryBuilder; @SuppressWarnings("serial") -public class FreeformQuery implements QueryDelegate { +public class FreeformQuery extends AbstractTransactionalQuery implements + QueryDelegate { FreeformQueryDelegate delegate = null; private String queryString; private List primaryKeyColumns; - private JDBCConnectionPool connectionPool; - private transient Connection activeConnection = null; /** * Prevent no-parameters instantiation of FreeformQuery @@ -67,6 +66,7 @@ public class FreeformQuery implements QueryDelegate { @Deprecated public FreeformQuery(String queryString, List primaryKeyColumns, JDBCConnectionPool connectionPool) { + super(connectionPool); if (primaryKeyColumns == null) { primaryKeyColumns = new ArrayList(); } @@ -83,7 +83,6 @@ public class FreeformQuery implements QueryDelegate { this.queryString = queryString; this.primaryKeyColumns = Collections .unmodifiableList(primaryKeyColumns); - this.connectionPool = connectionPool; } /** @@ -189,13 +188,6 @@ public class FreeformQuery implements QueryDelegate { return count; } - private Connection getConnection() throws SQLException { - if (activeConnection != null) { - return activeConnection; - } - return connectionPool.reserveConnection(); - } - /** * Fetches the results for the query. This implementation always fetches the * entire record set, ignoring the offset and page length parameters. In @@ -210,9 +202,7 @@ public class FreeformQuery implements QueryDelegate { @Override @SuppressWarnings({ "deprecation", "finally" }) public ResultSet getResults(int offset, int pagelength) throws SQLException { - if (activeConnection == null) { - throw new SQLException("No active transaction!"); - } + ensureTransaction(); String query = queryString; if (delegate != null) { /* First try using prepared statement */ @@ -220,8 +210,8 @@ public class FreeformQuery implements QueryDelegate { try { StatementHelper sh = ((FreeformStatementDelegate) delegate) .getQueryStatement(offset, pagelength); - PreparedStatement pstmt = activeConnection - .prepareStatement(sh.getQueryString()); + PreparedStatement pstmt = getConnection().prepareStatement( + sh.getQueryString()); sh.setParameterValuesToStatement(pstmt); return pstmt.executeQuery(); } catch (UnsupportedOperationException e) { @@ -234,7 +224,7 @@ public class FreeformQuery implements QueryDelegate { // This is fine, we'll just use the default queryString. } } - Statement statement = activeConnection.createStatement(); + Statement statement = getConnection().createStatement(); ResultSet rs; try { rs = statement.executeQuery(query); @@ -322,14 +312,14 @@ public class FreeformQuery implements QueryDelegate { */ @Override public int storeRow(RowItem row) throws SQLException { - if (activeConnection == null) { + if (!isInTransaction()) { throw new IllegalStateException("No transaction is active!"); } else if (primaryKeyColumns.isEmpty()) { throw new UnsupportedOperationException( "Cannot store items fetched with a read-only freeform query!"); } if (delegate != null) { - return delegate.storeRow(activeConnection, row); + return delegate.storeRow(getConnection(), row); } else { throw new UnsupportedOperationException( "FreeFormQueryDelegate not set!"); @@ -345,68 +335,36 @@ public class FreeformQuery implements QueryDelegate { */ @Override public boolean removeRow(RowItem row) throws SQLException { - if (activeConnection == null) { + if (!isInTransaction()) { throw new IllegalStateException("No transaction is active!"); } else if (primaryKeyColumns.isEmpty()) { throw new UnsupportedOperationException( "Cannot remove items fetched with a read-only freeform query!"); } if (delegate != null) { - return delegate.removeRow(activeConnection, row); + return delegate.removeRow(getConnection(), row); } else { throw new UnsupportedOperationException( "FreeFormQueryDelegate not set!"); } } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.data.util.sqlcontainer.query.QueryDelegate#beginTransaction() - */ @Override public synchronized void beginTransaction() throws UnsupportedOperationException, SQLException { - if (activeConnection != null) { - throw new IllegalStateException("A transaction is already active!"); - } - activeConnection = connectionPool.reserveConnection(); - activeConnection.setAutoCommit(false); + super.beginTransaction(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.data.util.sqlcontainer.query.QueryDelegate#commit() - */ @Override public synchronized void commit() throws UnsupportedOperationException, SQLException { - if (activeConnection == null) { - throw new SQLException("No active transaction"); - } - if (!activeConnection.getAutoCommit()) { - activeConnection.commit(); - } - connectionPool.releaseConnection(activeConnection); - activeConnection = null; + super.commit(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.data.util.sqlcontainer.query.QueryDelegate#rollback() - */ @Override public synchronized void rollback() throws UnsupportedOperationException, SQLException { - if (activeConnection == null) { - throw new SQLException("No active transaction"); - } - activeConnection.rollback(); - connectionPool.releaseConnection(activeConnection); - activeConnection = null; + super.rollback(); } /* @@ -492,66 +450,6 @@ public class FreeformQuery implements QueryDelegate { return contains; } - /** - * Releases the connection if it is not part of an active transaction. - * - * @param conn - * the connection to release - */ - private void releaseConnection(Connection conn) { - if (conn != activeConnection) { - connectionPool.releaseConnection(conn); - } - } - - /** - * Closes a statement and a resultset, then releases the connection if it is - * not part of an active transaction. A failure in closing one of the - * parameters does not prevent closing the rest. - * - * If the statement is a {@link PreparedStatement}, its parameters are - * cleared prior to closing the statement. - * - * Although JDBC specification does state that closing a statement closes - * its result set and closing a connection closes statements and result - * sets, this method does try to close the result set and statement - * explicitly whenever not null. This can guard against bugs in certain JDBC - * drivers and reduce leaks in case e.g. closing the result set succeeds but - * closing the statement or connection fails. - * - * @param conn - * the connection to release - * @param statement - * the statement to close, may be null to skip closing - * @param rs - * the result set to close, may be null to skip closing - * @throws SQLException - * if closing the result set or the statement fails - */ - private void releaseConnection(Connection conn, Statement statement, - ResultSet rs) throws SQLException { - try { - try { - if (null != rs) { - rs.close(); - } - } finally { - if (null != statement) { - if (statement instanceof PreparedStatement) { - try { - ((PreparedStatement) statement).clearParameters(); - } catch (Exception e) { - // will be closed below anyway - } - } - statement.close(); - } - } - } finally { - releaseConnection(conn); - } - } - private String modifyWhereClause(Object... keys) { // Build the where rules for the provided keys StringBuffer where = new StringBuffer(); diff --git a/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java b/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java index 63e4b3362c..caed5526e3 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java @@ -47,8 +47,8 @@ import com.vaadin.data.util.sqlcontainer.query.generator.SQLGenerator; import com.vaadin.data.util.sqlcontainer.query.generator.StatementHelper; @SuppressWarnings("serial") -public class TableQuery implements QueryDelegate, - QueryDelegate.RowIdChangeNotifier { +public class TableQuery extends AbstractTransactionalQuery implements + QueryDelegate, QueryDelegate.RowIdChangeNotifier { /** Table name, primary key column name(s) and version column name */ private String tableName; @@ -62,18 +62,13 @@ public class TableQuery implements QueryDelegate, /** SQLGenerator instance to use for generating queries */ private SQLGenerator sqlGenerator; - /** Fields related to Connection and Transaction handling */ - private JDBCConnectionPool connectionPool; - private transient Connection activeConnection; - private boolean transactionOpen; - /** Row ID change listeners */ private LinkedList rowIdChangeListeners; /** Row ID change events, stored until commit() is called */ private final List bufferedEvents = new ArrayList(); /** Set to true to output generated SQL Queries to System.out */ - private boolean debug = false; + private final boolean debug = false; /** Prevent no-parameters instantiation of TableQuery */ @SuppressWarnings("unused") @@ -93,6 +88,7 @@ public class TableQuery implements QueryDelegate, */ public TableQuery(String tableName, JDBCConnectionPool connectionPool, SQLGenerator sqlGenerator) { + super(connectionPool); if (tableName == null || tableName.trim().length() < 1 || connectionPool == null || sqlGenerator == null) { throw new IllegalArgumentException( @@ -100,7 +96,6 @@ public class TableQuery implements QueryDelegate, } this.tableName = tableName; this.sqlGenerator = sqlGenerator; - this.connectionPool = connectionPool; fetchMetaData(); } @@ -129,17 +124,27 @@ public class TableQuery implements QueryDelegate, StatementHelper sh = sqlGenerator.generateSelectQuery(tableName, filters, null, 0, 0, "COUNT(*)"); boolean shouldCloseTransaction = false; - if (!transactionOpen) { + if (!isInTransaction()) { shouldCloseTransaction = true; beginTransaction(); } - ResultSet r = executeQuery(sh); - r.next(); - int count = r.getInt(1); - r.getStatement().close(); - r.close(); - if (shouldCloseTransaction) { - commit(); + ResultSet r = null; + int count = -1; + try { + r = executeQuery(sh); + r.next(); + count = r.getInt(1); + } finally { + try { + if (r != null) { + releaseConnection(r.getStatement().getConnection(), + r.getStatement(), r); + } + } finally { + if (shouldCloseTransaction) { + commit(); + } + } } return count; } @@ -240,28 +245,30 @@ public class TableQuery implements QueryDelegate, setVersionColumnFlagInProperty(row); /* Generate query */ StatementHelper sh = sqlGenerator.generateInsertQuery(tableName, row); - PreparedStatement pstmt = activeConnection.prepareStatement( - sh.getQueryString(), primaryKeyColumns.toArray(new String[0])); - sh.setParameterValuesToStatement(pstmt); - getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); - int result = pstmt.executeUpdate(); - if (result > 0) { - /* - * If affected rows exist, we'll get the new RowId, commit the - * transaction and return the new RowId. - */ - ResultSet generatedKeys = pstmt.getGeneratedKeys(); - RowId newId = getNewRowId(row, generatedKeys); - generatedKeys.close(); - pstmt.clearParameters(); - pstmt.close(); + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet generatedKeys = null; + connection = getConnection(); + try { + pstmt = connection.prepareStatement(sh.getQueryString(), + primaryKeyColumns.toArray(new String[0])); + sh.setParameterValuesToStatement(pstmt); + getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); + int result = pstmt.executeUpdate(); + RowId newId = null; + if (result > 0) { + /* + * If affected rows exist, we'll get the new RowId, commit the + * transaction and return the new RowId. + */ + generatedKeys = pstmt.getGeneratedKeys(); + newId = getNewRowId(row, generatedKeys); + } + // transaction has to be closed in any case commit(); return newId; - } else { - pstmt.clearParameters(); - pstmt.close(); - /* On failure return null */ - return null; + } finally { + releaseConnection(connection, pstmt, generatedKeys); } } @@ -307,14 +314,8 @@ public class TableQuery implements QueryDelegate, @Override public void beginTransaction() throws UnsupportedOperationException, SQLException { - if (transactionOpen && activeConnection != null) { - throw new IllegalStateException(); - } - getLogger().log(Level.FINE, "DB -> begin transaction"); - activeConnection = connectionPool.reserveConnection(); - activeConnection.setAutoCommit(false); - transactionOpen = true; + super.beginTransaction(); } /* @@ -324,14 +325,8 @@ public class TableQuery implements QueryDelegate, */ @Override public void commit() throws UnsupportedOperationException, SQLException { - if (transactionOpen && activeConnection != null) { - getLogger().log(Level.FINE, "DB -> commit"); - activeConnection.commit(); - connectionPool.releaseConnection(activeConnection); - } else { - throw new SQLException("No active transaction"); - } - transactionOpen = false; + getLogger().log(Level.FINE, "DB -> commit"); + super.commit(); /* Handle firing row ID change events */ RowIdChangeEvent[] unFiredEvents = bufferedEvents @@ -353,14 +348,8 @@ public class TableQuery implements QueryDelegate, */ @Override public void rollback() throws UnsupportedOperationException, SQLException { - if (transactionOpen && activeConnection != null) { - getLogger().log(Level.FINE, "DB -> rollback"); - activeConnection.rollback(); - connectionPool.releaseConnection(activeConnection); - } else { - throw new SQLException("No active transaction"); - } - transactionOpen = false; + getLogger().log(Level.FINE, "DB -> rollback"); + super.rollback(); } /* @@ -402,16 +391,18 @@ public class TableQuery implements QueryDelegate, * @throws SQLException */ private ResultSet executeQuery(StatementHelper sh) throws SQLException { - Connection c = null; - if (transactionOpen && activeConnection != null) { - c = activeConnection; - } else { - throw new SQLException("No active transaction!"); + ensureTransaction(); + Connection connection = getConnection(); + PreparedStatement pstmt = null; + try { + pstmt = connection.prepareStatement(sh.getQueryString()); + sh.setParameterValuesToStatement(pstmt); + getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); + return pstmt.executeQuery(); + } catch (SQLException e) { + releaseConnection(null, pstmt, null); + throw e; } - PreparedStatement pstmt = c.prepareStatement(sh.getQueryString()); - sh.setParameterValuesToStatement(pstmt); - getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); - return pstmt.executeQuery(); } /** @@ -426,27 +417,17 @@ public class TableQuery implements QueryDelegate, * @throws SQLException */ private int executeUpdate(StatementHelper sh) throws SQLException { - Connection c = null; PreparedStatement pstmt = null; + Connection connection = null; try { - if (transactionOpen && activeConnection != null) { - c = activeConnection; - } else { - c = connectionPool.reserveConnection(); - } - pstmt = c.prepareStatement(sh.getQueryString()); + connection = getConnection(); + pstmt = connection.prepareStatement(sh.getQueryString()); sh.setParameterValuesToStatement(pstmt); getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); int retval = pstmt.executeUpdate(); return retval; } finally { - if (pstmt != null) { - pstmt.clearParameters(); - pstmt.close(); - } - if (!transactionOpen) { - connectionPool.releaseConnection(c); - } + releaseConnection(connection, pstmt, null); } } @@ -467,16 +448,12 @@ public class TableQuery implements QueryDelegate, */ private int executeUpdateReturnKeys(StatementHelper sh, RowItem row) throws SQLException { - Connection c = null; PreparedStatement pstmt = null; ResultSet genKeys = null; + Connection connection = null; try { - if (transactionOpen && activeConnection != null) { - c = activeConnection; - } else { - c = connectionPool.reserveConnection(); - } - pstmt = c.prepareStatement(sh.getQueryString(), + connection = getConnection(); + pstmt = connection.prepareStatement(sh.getQueryString(), primaryKeyColumns.toArray(new String[0])); sh.setParameterValuesToStatement(pstmt); getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); @@ -486,16 +463,7 @@ public class TableQuery implements QueryDelegate, bufferedEvents.add(new RowIdChangeEvent(row.getId(), newId)); return result; } finally { - if (genKeys != null) { - genKeys.close(); - } - if (pstmt != null) { - pstmt.clearParameters(); - pstmt.close(); - } - if (!transactionOpen) { - connectionPool.releaseConnection(c); - } + releaseConnection(connection, pstmt, genKeys); } } @@ -505,13 +473,15 @@ public class TableQuery implements QueryDelegate, * Also tries to get the escape string to be used in search strings. */ private void fetchMetaData() { - Connection c = null; + Connection connection = null; + ResultSet rs = null; + ResultSet tables = null; try { - c = connectionPool.reserveConnection(); - DatabaseMetaData dbmd = c.getMetaData(); + connection = getConnection(); + DatabaseMetaData dbmd = connection.getMetaData(); if (dbmd != null) { tableName = SQLUtil.escapeSQL(tableName); - ResultSet tables = dbmd.getTables(null, null, tableName, null); + tables = dbmd.getTables(null, null, tableName, null); if (!tables.next()) { tables = dbmd.getTables(null, null, tableName.toUpperCase(), null); @@ -525,7 +495,7 @@ public class TableQuery implements QueryDelegate, } } tables.close(); - ResultSet rs = dbmd.getPrimaryKeys(null, null, tableName); + rs = dbmd.getPrimaryKeys(null, null, tableName); List names = new ArrayList(); while (rs.next()) { names.add(rs.getString("COLUMN_NAME")); @@ -554,7 +524,15 @@ public class TableQuery implements QueryDelegate, } catch (SQLException e) { throw new RuntimeException(e); } finally { - connectionPool.releaseConnection(c); + try { + releaseConnection(connection, null, rs); + } catch (SQLException ignore) { + } finally { + try { + tables.close(); + } catch (SQLException ignore) { + } + } } } @@ -648,7 +626,7 @@ public class TableQuery implements QueryDelegate, filtersAndKeys, orderBys, 0, 0, "*"); boolean shouldCloseTransaction = false; - if (!transactionOpen) { + if (!isInTransaction()) { shouldCloseTransaction = true; beginTransaction(); } @@ -658,14 +636,15 @@ public class TableQuery implements QueryDelegate, boolean contains = rs.next(); return contains; } finally { - if (rs != null) { - if (rs.getStatement() != null) { - rs.getStatement().close(); + try { + if (rs != null) { + releaseConnection(rs.getStatement().getConnection(), + rs.getStatement(), rs); + } + } finally { + if (shouldCloseTransaction) { + commit(); } - rs.close(); - } - if (shouldCloseTransaction) { - commit(); } } } -- cgit v1.2.3 From 5cba827316eed64508ffb254edb95f303f44eab9 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 11:14:24 +0200 Subject: Fixed client-server value sync problem in CheckBox (#11028) Change-Id: I1bac8e8a746bcc97b3ce929e76cf3476ad793bf6 --- server/src/com/vaadin/ui/CheckBox.java | 17 +++++ .../tests/components/AbstractTestUIWithLog.java | 36 ++++++++++ .../checkbox/CheckBoxRevertValueChange.html | 82 ++++++++++++++++++++++ .../checkbox/CheckBoxRevertValueChange.java | 65 +++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java create mode 100644 uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html create mode 100644 uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java (limited to 'server') diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java index 0ace0a4f26..ac33f5e410 100644 --- a/server/src/com/vaadin/ui/CheckBox.java +++ b/server/src/com/vaadin/ui/CheckBox.java @@ -16,6 +16,8 @@ package com.vaadin.ui; +import org.json.JSONException; + import com.vaadin.data.Property; import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; @@ -37,6 +39,21 @@ public class CheckBox extends AbstractField { return; } + /* + * Client side updates the state before sending the event so we need + * to make sure the cached state is updated to match the client. If + * we do not do this, a reverting setValue() call in a listener will + * not cause the new state to be sent to the client. + * + * See #11028, #10030. + */ + try { + getUI().getConnectorTracker().getDiffState(CheckBox.this) + .put("checked", checked); + } catch (JSONException e) { + throw new RuntimeException(e); + } + final Boolean oldValue = getValue(); final Boolean newValue = checked; diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java b/uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java new file mode 100644 index 0000000000..cace7c3404 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.VerticalLayout; + +public abstract class AbstractTestUIWithLog extends AbstractTestUI { + + protected Log log = new Log(5); + + @Override + public void init(VaadinRequest request) { + super.init(request); + ((VerticalLayout) getContent()).addComponent(log, 0); + } + + protected void log(String message) { + log.log(message); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html new file mode 100644 index 0000000000..ea5849f99f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html @@ -0,0 +1,82 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.checkbox.CheckBoxRevertValueChange?restartApplication
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]10,5
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_01. I said no checking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]off
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[1]93,10
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_02. I said no checking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]off
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]5,8
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_03. I said no unchecking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]on
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[1]78,12
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_04. I said no unchecking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]on
+ + diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java new file mode 100644 index 0000000000..5b086fb935 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.checkbox; + +import com.vaadin.annotations.PreserveOnRefresh; +import com.vaadin.data.Property; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.CheckBox; + +@PreserveOnRefresh +public class CheckBoxRevertValueChange extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final CheckBox alwaysUnchecked = new CheckBox("You may not check me"); + alwaysUnchecked + .addValueChangeListener(new Property.ValueChangeListener() { + public void valueChange(Property.ValueChangeEvent event) { + if (alwaysUnchecked.getValue()) { + log("I said no checking!"); + alwaysUnchecked.setValue(false); + } + } + }); + final CheckBox alwaysChecked = new CheckBox("You may not uncheck me"); + alwaysChecked.setValue(true); + alwaysChecked + .addValueChangeListener(new Property.ValueChangeListener() { + public void valueChange(Property.ValueChangeEvent event) { + if (!alwaysChecked.getValue()) { + log("I said no unchecking!"); + alwaysChecked.setValue(true); + } + } + }); + + addComponent(alwaysUnchecked); + addComponent(alwaysChecked); + } + + @Override + protected String getTestDescription() { + return "Ensure checking of a checkbox can be reverted on the server side without making the client go out of sync"; + } + + @Override + protected Integer getTicketNumber() { + return 11028; + } + +} -- cgit v1.2.3 From d2d4279e9946f9b193c0b706ecad9e01a5bf77c3 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 13 Mar 2013 09:50:41 +0200 Subject: Fixed setting column width back to undefined by setting it to -1. #7922 svn changeset:25591/svn branch:6.8 Conflicts: server/src/com/vaadin/ui/Table.java Reverted change included by mistake in changeset [25591] for #7922 svn changeset:25606/svn branch:6.8 Change-Id: I6765a52ab213c131cca053227ee72b0007552f7f --- client/src/com/vaadin/client/ui/VScrollTable.java | 24 +++++-- server/src/com/vaadin/ui/Table.java | 71 ++++++++++++------ .../table/TableColumnWidthsAndExpandRatios.html | 83 ++++++++++++++++++++++ .../table/TableColumnWidthsAndExpandRatios.java | 57 +++++++++++++++ 4 files changed, 208 insertions(+), 27 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html create mode 100644 uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java (limited to 'server') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 6f9fd6da88..4d61fba429 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -3056,7 +3056,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, .hasNext(); columnIndex++) { if (it.next() == this) { break; - } + } } } final int cw = scrollBody.getColWidth(columnIndex); @@ -3266,10 +3266,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } if (col.hasAttribute("width")) { - final String widthStr = col.getStringAttribute("width"); // Make sure to accomodate for the sort indicator if // necessary. - int width = Integer.parseInt(widthStr); + int width = col.getIntAttribute("width"); int widthWithoutAddedIndent = width; // get min width with indent, no padding @@ -3301,12 +3300,25 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // save min width without indent c.setWidth(widthWithoutAddedIndent, true); } + } else if (col.hasAttribute("er")) { + c.setExpandRatio(col.getFloatAttribute("er")); + } else if (recalcWidths) { c.setUndefinedWidth(); + + } else { + boolean hadExpandRatio = c.getExpandRatio() > 0; + boolean hadDefinedWidth = c.isDefinedWidth(); + if (hadExpandRatio || hadDefinedWidth) { + // Someone has removed a expand width or the defined + // width on the server side (setting it to -1), make the + // column undefined again and measure columns again. + c.setUndefinedWidth(); + c.setExpandRatio(0); + refreshContentWidths = true; + } } - if (col.hasAttribute("er")) { - c.setExpandRatio(col.getFloatAttribute("er")); - } + if (col.hasAttribute("collapsed")) { // ensure header is properly removed from parent (case when // collapsing happens via servers side api) diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 641c0ff1f6..3d7cb42050 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -396,10 +396,14 @@ public class Table extends AbstractSelect implements Action.Container, private HashMap columnAlignments = new HashMap(); /** - * Holds column widths in pixels (Integer) or expand ratios (Float) for - * visible columns (by propertyId). + * Holds column widths in pixels for visible columns (by propertyId). */ - private final HashMap columnWidths = new HashMap(); + private final HashMap columnWidths = new HashMap(); + + /** + * Holds column expand rations for visible columns (by propertyId). + */ + private final HashMap columnExpandRatios = new HashMap(); /** * Holds column generators @@ -886,10 +890,14 @@ public class Table extends AbstractSelect implements Action.Container, // id to store the width of the row header. propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } + + // Setting column width should remove any expand ratios as well + columnExpandRatios.remove(propertyId); + if (width < 0) { columnWidths.remove(propertyId); } else { - columnWidths.put(propertyId, Integer.valueOf(width)); + columnWidths.put(propertyId, width); } markAsDirty(); } @@ -930,21 +938,39 @@ public class Table extends AbstractSelect implements Action.Container, * the expandRatio used to divide excess space for this column */ public void setColumnExpandRatio(Object propertyId, float expandRatio) { + if (propertyId == null) { + // Since propertyId is null, this is the row header. Use the magic + // id to store the width of the row header. + propertyId = ROW_HEADER_FAKE_PROPERTY_ID; + } + + // Setting the column expand ratio should remove and defined column + // width + columnWidths.remove(propertyId); + if (expandRatio < 0) { - columnWidths.remove(propertyId); + columnExpandRatios.remove(propertyId); } else { - columnWidths.put(propertyId, new Float(expandRatio)); + columnExpandRatios.put(propertyId, expandRatio); } + + requestRepaint(); } + /** + * Gets the column expand ratio for a columnd. See + * {@link #setColumnExpandRatio(Object, float)} + * + * @param propertyId + * columns property id + * @return the expandRatio used to divide excess space for this column + */ public float getColumnExpandRatio(Object propertyId) { - final Object width = columnWidths.get(propertyId); - if (width == null || !(width instanceof Float)) { + final Float width = columnExpandRatios.get(propertyId); + if (width == null) { return -1; } - final Float value = (Float) width; - return value.floatValue(); - + return width.floatValue(); } /** @@ -959,12 +985,11 @@ public class Table extends AbstractSelect implements Action.Container, // id to retrieve the width of the row header. propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } - final Object width = columnWidths.get(propertyId); - if (width == null || !(width instanceof Integer)) { + final Integer width = columnWidths.get(propertyId); + if (width == null) { return -1; } - final Integer value = (Integer) width; - return value.intValue(); + return width.intValue(); } /** @@ -3434,6 +3459,7 @@ public class Table extends AbstractSelect implements Action.Container, target.startTag("column"); target.addAttribute("cid", ROW_HEADER_COLUMN_KEY); paintColumnWidth(target, ROW_HEADER_FAKE_PROPERTY_ID); + paintColumnExpandRatio(target, ROW_HEADER_FAKE_PROPERTY_ID); target.endTag("column"); } final Collection sortables = getSortableContainerPropertyIds(); @@ -3461,6 +3487,7 @@ public class Table extends AbstractSelect implements Action.Container, .toString()); } paintColumnWidth(target, colId); + paintColumnExpandRatio(target, colId); target.endTag("column"); } } @@ -3706,12 +3733,14 @@ public class Table extends AbstractSelect implements Action.Container, private void paintColumnWidth(PaintTarget target, final Object columnId) throws PaintException { if (columnWidths.containsKey(columnId)) { - if (getColumnWidth(columnId) > -1) { - target.addAttribute("width", - String.valueOf(getColumnWidth(columnId))); - } else { - target.addAttribute("er", getColumnExpandRatio(columnId)); - } + target.addAttribute("width", getColumnWidth(columnId)); + } + } + + private void paintColumnExpandRatio(PaintTarget target, + final Object columnId) throws PaintException { + if (columnExpandRatios.containsKey(columnId)) { + target.addAttribute("er", getColumnExpandRatio(columnId)); } } diff --git a/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html new file mode 100644 index 0000000000..75d98ce2e6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html @@ -0,0 +1,83 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.table.TableColumnWidthsAndExpandRatios?restartApplication
screenCaptureinitial-all-columns-undefined
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]-300,0
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[1]/domChild[0]-300,0
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]-300,0
screenCapturecolumns-defined-width
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[0]/VNativeButton[0]114,4
screenCapturecolumn1-undefined
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[1]/VNativeButton[0]98,13
screenCapturecolumn2-undefined
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[2]/VNativeButton[0]40,10
screenCapturecolumns-undefined-width
+ + diff --git a/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java new file mode 100644 index 0000000000..747c99468f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.Table; + +public class TableColumnWidthsAndExpandRatios extends TestBase { + + @Override + protected void setup() { + getLayout().setSizeFull(); + + final Table table = new Table(); + table.setSizeFull(); + + table.addContainerProperty("column1", String.class, "Humpty"); + table.addContainerProperty("column2", String.class, "Dumpty"); + table.addContainerProperty("column3", String.class, "Doe"); + + for (int row = 0; row < 100; row++) { + table.addItem(); + } + + HorizontalLayout buttons = new HorizontalLayout(); + for (Object col : table.getContainerPropertyIds()) { + buttons.addComponent(createResetButton(col, table)); + } + + addComponent(table); + addComponent(buttons); + } + + private NativeButton createResetButton(final Object property, + final Table table) { + return new NativeButton("Reset " + property + " width", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + table.setColumnWidth(property, -1); + } + }); + } + + @Override + protected String getDescription() { + return "Changing column width to -1 should remove any previous size measurements"; + } + + @Override + protected Integer getTicketNumber() { + return 7922; + } + +} -- cgit v1.2.3 From a9d93e91ad4c70272c0714f4b92032800100a6af Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Thu, 14 Mar 2013 15:18:06 +0200 Subject: Ignored test case where Tree memory leak is checked since it cannot be fixed before 7.1 (no-merge) #11053 Change-Id: I723b7fc01184da19f448de4c43d3dee715c01242 --- .../tests/server/component/tree/TreeTest.java | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'server') diff --git a/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java b/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java index c1d7653c01..634e6a86f3 100644 --- a/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java @@ -1,24 +1,31 @@ package com.vaadin.tests.server.component.tree; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.lang.reflect.Field; import java.util.HashSet; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; import com.vaadin.data.Container; import com.vaadin.data.util.HierarchicalContainer; import com.vaadin.data.util.IndexedContainer; import com.vaadin.ui.Tree; -public class TreeTest extends TestCase { +public class TreeTest { private Tree tree; private Tree tree2; private Tree tree3; private Tree tree4; - @Override - protected void setUp() { + @Before + public void setUp() { tree = new Tree(); tree.addItem("parent"); tree.addItem("child"); @@ -44,6 +51,7 @@ public class TreeTest extends TestCase { tree4.setParent("child", "parent"); } + @Test public void testRemoveChildren() { assertTrue(tree.hasChildren("parent")); tree.removeItem("child"); @@ -62,6 +70,7 @@ public class TreeTest extends TestCase { assertFalse(tree4.hasChildren("parent")); } + @Test public void testContainerTypeIsHierarchical() { assertTrue(HierarchicalContainer.class.isAssignableFrom(tree .getContainerDataSource().getClass())); @@ -75,6 +84,11 @@ public class TreeTest extends TestCase { .getContainerDataSource().getClass())); } + @Ignore("This test tests that item ids which are removed are also " + + "removed from the expand list to prevent a memory leak. " + + "Fixing the memory leak cannot be done without changing some API (see #11053) " + + "so ignoring this test for the 7.0.x series.") + @Test public void testRemoveExpandedItems() throws Exception { tree.expandItem("parent"); tree.expandItem("child"); @@ -113,6 +127,7 @@ public class TreeTest extends TestCase { assertNull(expandedItemId); } + @Test public void testRemoveExpandedItemsOnContainerChange() throws Exception { tree.expandItem("parent"); tree.expandItem("child"); -- cgit v1.2.3 From 12228618971e94fee1264a2e5018a1d24be64137 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 14 Mar 2013 16:31:41 +0200 Subject: Deprecated AbstractComponentContainer.getComponentIterator (#11328) Change-Id: I24298165f0b078d42415cfce65118eed5587623c --- server/src/com/vaadin/ui/AbstractComponentContainer.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'server') diff --git a/server/src/com/vaadin/ui/AbstractComponentContainer.java b/server/src/com/vaadin/ui/AbstractComponentContainer.java index ca83286311..4aacad680f 100644 --- a/server/src/com/vaadin/ui/AbstractComponentContainer.java +++ b/server/src/com/vaadin/ui/AbstractComponentContainer.java @@ -339,6 +339,12 @@ public abstract class AbstractComponentContainer extends AbstractComponent true); } + /** + * {@inheritDoc} + * + * @deprecated As of 7.0, use {@link #iterator()} instead. + */ + @Deprecated @Override public Iterator getComponentIterator() { return iterator(); -- cgit v1.2.3