From e21098304736e32a74f359e8dfb80e587337085d Mon Sep 17 00:00:00 2001 From: Jonatan Kronqvist Date: Thu, 8 Sep 2011 10:53:55 +0000 Subject: Applied patch fixing #7391 svn changeset:20926/svn branch:6.7 --- .../data/util/sqlcontainer/SQLContainer.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java index f25252b8c0..f6b22bfecb 100644 --- a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java +++ b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java @@ -1199,7 +1199,18 @@ public class SQLContainer implements Container, Container.Filterable, } /* Cache item */ itemIndexes.put(rowCount, id); - cachedItems.put(id, new RowItem(this, id, itemProperties)); + + // if an item with the id is contained in the modified + // cache, then use this record and add it to the cached + // items. Otherwise create a new item + int modifiedIndex = indexInModifiedCache(id); + if (modifiedIndex != -1) { + cachedItems.put(id, modifiedItems.get(modifiedIndex)); + } else { + cachedItems.put(id, new RowItem(this, id, + itemProperties)); + } + rowCount++; } } @@ -1229,6 +1240,24 @@ public class SQLContainer implements Container, Container.Filterable, } } + /** + * Returns the index of the item with the given itemId for the modified + * cache. + * + * @param itemId + * @return the index of the item with the itemId in the modified cache. Or + * -1 if not found. + */ + private int indexInModifiedCache(Object itemId) { + for (int ix = 0; ix < modifiedItems.size(); ix++) { + RowItem item = modifiedItems.get(ix); + if (item.getId().equals(itemId)) { + return ix; + } + } + return -1; + } + private int sizeOfAddedItems() { return getFilteredAddedItems().size(); } -- cgit v1.2.3