diff options
author | Henri Sara <hesara@vaadin.com> | 2012-08-31 13:29:42 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2012-08-31 14:09:58 +0300 |
commit | 01646b14df5708e50e4eb031ec5b4f0da4ab5d15 (patch) | |
tree | aea2f654ed4f0ddca0f61708d1a3be8edb09deaf /server/src/com/vaadin/data/util/sqlcontainer | |
parent | 61a1218d388b85b496e0fd98f2a5c5226ab4f83d (diff) | |
download | vaadin-framework-01646b14df5708e50e4eb031ec5b4f0da4ab5d15.tar.gz vaadin-framework-01646b14df5708e50e4eb031ec5b4f0da4ab5d15.zip |
Add Container.Indexed.getItemIds(int, int) for a range of items (#8028)
This permits optimization of data fetches from various containers
where getting single items by index in a loop might be costly.
Also add a helper method in ContainerHelpers to make it easier to
implement the new method where performance of fetching an id by index is
not an issue. SQLContainer still uses this helper instead of an
optimized implementation.
Diffstat (limited to 'server/src/com/vaadin/data/util/sqlcontainer')
-rw-r--r-- | server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java index a53f32b96e..7a63e8c6c2 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java @@ -33,6 +33,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.data.Container; +import com.vaadin.data.ContainerHelpers; import com.vaadin.data.Item; import com.vaadin.data.Property; import com.vaadin.data.util.filter.Compare.Equal; @@ -656,9 +657,11 @@ public class SQLContainer implements Container, Container.Filterable, @Override public Object getIdByIndex(int index) { - if (index < 0 || index > size() - 1) { - return null; + if (index < 0) { + throw new IndexOutOfBoundsException("Index is negative! index=" + + index); } + if (index < size) { if (itemIndexes.keySet().contains(index)) { return itemIndexes.get(index); @@ -672,6 +675,13 @@ public class SQLContainer implements Container, Container.Filterable, } } + @Override + public List<Object> getItemIds(int startIndex, int numberOfIds) { + // TODO create a better implementation + return (List<Object>) ContainerHelpers.getItemIdsUsingGetIdByIndex( + startIndex, numberOfIds, this); + } + /**********************************************/ /** Methods from interface Container.Ordered **/ /**********************************************/ |