com.atlassian.jira.ofbiz
Class PagedDatabaseIterable

java.lang.Object
  extended by com.atlassian.jira.ofbiz.PagedDatabaseIterable
All Implemented Interfaces:
CloseableIterable, Sized

public abstract class PagedDatabaseIterable
extends Object
implements CloseableIterable

A abstract implementation of CloseableIterable 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.CloseableIterable
CloseableIterable.ListResolver
 
Constructor Summary
PagedDatabaseIterable(List ids)
          Use where the order of the result is not important.
PagedDatabaseIterable(List ids, Resolver keyResolver)
          Use where the order of the result is important.
PagedDatabaseIterable(List ids, Resolver keyResolver, int pageSize)
          Use where the order of the result is important.
 
Method Summary
protected abstract  OfBizListIterator createListIterator(List ids)
          Create a new iterator from the subset of ids.
protected abstract  Resolver getResolver()
          Used to turn generic values into Domain objects
 boolean isEmpty()
           
 CloseableIterator iterator()
           
 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 ids)
Use where the order of the result is not important.

Parameters:
ids - a List must not be null

PagedDatabaseIterable

public PagedDatabaseIterable(List ids,
                             Resolver 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 ids,
                             Resolver 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

iterator

public CloseableIterator iterator()
Specified by:
iterator in interface CloseableIterable
Returns:
a CloseableIterator that can be closed once finished with

createListIterator

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

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

getResolver

protected abstract Resolver getResolver()
Used to turn generic values into Domain objects

Returns:
a resolver

size

public final int size()
Specified by:
size in interface CloseableIterable
Specified by:
size in interface Sized
Returns:
the likely size of the objects returned by the CloseableIterable.iterator(). Be careful depending on this size being exact, as in many cases its best efforts value or may be stable due to concurrent changes.

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface CloseableIterable
Returns:
true if the there is no data behind it. In this case the CloseableIterable.iterator().hasNext() will return false;


Copyright © 2002-2008 Atlassian. All Rights Reserved.