com.atlassian.jira.ofbiz
Class PagedDatabaseIterable<E,K>

java.lang.Object
  extended by com.atlassian.jira.ofbiz.PagedDatabaseIterable<E,K>
All Implemented Interfaces:
EnclosedIterable<E>, Sized

public abstract class PagedDatabaseIterable<E,K>
extends Object
implements EnclosedIterable<E>

A abstract implementation of EnclosedIterable that takes a list of ids and then pages them by opening an OfBizListIterator for each page.

This implementation supports preserving the order of the elements in the returned list but will load all the elements into memory in order to do so.

This implementation uses the DatabaseIterator but implements paging and sorting on top of it.

Since:
v3.13

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.jira.util.collect.EnclosedIterable
EnclosedIterable.Functions, EnclosedIterable.ListResolver<T>
 
Constructor Summary
PagedDatabaseIterable(List<K> ids)
          Use where the order of the result is not important.
PagedDatabaseIterable(List<K> ids, Resolver<E,K> keyResolver)
          Use where the order of the result is important.
PagedDatabaseIterable(List<K> ids, Resolver<E,K> keyResolver, int pageSize)
          Use where the order of the result is important.
 
Method Summary
protected abstract  OfBizListIterator createListIterator(List<K> ids)
          Create a new iterator from the subset of ids.
 void foreach(Consumer<E> consumer)
          Apply the sink to all elements in the Collection.
protected abstract  Resolver<org.ofbiz.core.entity.GenericValue,E> getResolver()
          Used to turn generic values into Domain objects
 boolean isEmpty()
           
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PagedDatabaseIterable

public PagedDatabaseIterable(List<K> ids)
Use where the order of the result is not important.

Parameters:
ids - a List must not be null

PagedDatabaseIterable

public PagedDatabaseIterable(List<K> ids,
                             Resolver<E,K> keyResolver)
Use where the order of the result is important.

Parameters:
ids - a List must not be null
keyResolver - to get a domain object's key (ie. the element in the ids list). Null if sort order is unimportant

PagedDatabaseIterable

public PagedDatabaseIterable(List<K> ids,
                             Resolver<E,K> keyResolver,
                             int pageSize)
Use where the order of the result is important.

Parameters:
ids - a List must not be null
keyResolver - to get a domain object's key (ie. the element in the ids list). Null if sort order is unimportant
pageSize - the size of the pages to use
Method Detail

foreach

public final void foreach(Consumer<E> consumer)
Description copied from interface: EnclosedIterable
Apply the sink to all elements in the Collection.

Specified by:
foreach in interface EnclosedIterable<E>

createListIterator

protected abstract OfBizListIterator createListIterator(List<K> ids)
Create a new iterator from the subset of ids.

Parameters:
ids - list of ids
Returns:
an instance of OfBizListIterator

getResolver

protected abstract Resolver<org.ofbiz.core.entity.GenericValue,E> getResolver()
Used to turn generic values into Domain objects

Returns:
a resolver

size

public final int size()
Specified by:
size in interface EnclosedIterable<E>
Specified by:
size in interface Sized
Returns:
the likely size of the objects passed into the sink in EnclosedIterable.foreach(Consumer). Be careful depending on this size being exact, as in many cases its best efforts value or may be unstable due to concurrent changes.

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface EnclosedIterable<E>
Specified by:
isEmpty in interface Sized
Returns:
true if the there is no data behind it.


Copyright © 2002-2013 Atlassian. All Rights Reserved.