com.amazonaws.services.dynamodbv2.datamodeling
Class PaginatedList<T>

java.lang.Object
  extended by com.amazonaws.services.dynamodbv2.datamodeling.PaginatedList<T>
Type Parameters:
T - The domain object type stored in this list.
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>
Direct Known Subclasses:
PaginatedParallelScanList, PaginatedQueryList, PaginatedScanList

public abstract class PaginatedList<T>
extends Object
implements List<T>

Unmodifiable list supporting paginated result sets from Amazon DynamoDB.

Pages of results are fetched lazily from DynamoDB as they are needed. Some methods, such as size() and toArray(), require fetching the entire result set eagerly. See the javadoc of individual methods for details on which are lazy.


Field Summary
protected  List<T> allResults
          All currently loaded results for this list.
protected  boolean allResultsLoaded
          Tracks if all results have been loaded yet or not
protected  Class<T> clazz
          The class annotated with DynamoDB tags declaring how to load/store objects into DynamoDB
protected  AmazonDynamoDB dynamo
          The client for working with DynamoDB
protected  DynamoDBMapper mapper
          Reference to the DynamoDB mapper for marshalling DynamoDB attributes back into objects
protected  List<T> nextResults
          Lazily loaded next results waiting to be added into allResults
 
Constructor Summary
PaginatedList(DynamoDBMapper mapper, Class<T> clazz, AmazonDynamoDB dynamo)
          Constructs a PaginatedList instance using the default PaginationLoadingStrategy
PaginatedList(DynamoDBMapper mapper, Class<T> clazz, AmazonDynamoDB dynamo, DynamoDBMapperConfig.PaginationLoadingStrategy paginationLoadingStrategy)
          Constructs a PaginatedList instance.
 
Method Summary
 void add(int arg0, T arg1)
           
 boolean add(T arg0)
           
 boolean addAll(Collection<? extends T> arg0)
           
 boolean addAll(int arg0, Collection<? extends T> arg1)
           
protected abstract  boolean atEndOfResults()
          Returns whether we have reached the end of the result set.
 void clear()
           
 boolean contains(Object arg0)
          Returns whether the collection contains the given element.
 boolean containsAll(Collection<?> arg0)
           
protected abstract  List<T> fetchNextPage()
          Fetches the next page of results (which may be empty) and returns any items found.
 T get(int n)
          Returns the Nth element of the list.
 int indexOf(Object arg0)
          Returns the first index of the object given in the list.
 boolean isEmpty()
          Returns whether the collection is empty.
 Iterator<T> iterator()
          Returns an iterator over this list that lazily initializes results as necessary.
 int lastIndexOf(Object arg0)
           
 ListIterator<T> listIterator()
           
 ListIterator<T> listIterator(int arg0)
           
 void loadAllResults()
          Eagerly loads all results for this list.
 T remove(int arg0)
           
 boolean remove(Object arg0)
           
 boolean removeAll(Collection<?> arg0)
           
 boolean retainAll(Collection<?> arg0)
           
 T set(int arg0, T arg1)
           
 int size()
           
 List<T> subList(int arg0, int arg1)
          Returns a sub-list in the range specified, loading more results as necessary.
 Object[] toArray()
           
<X> X[]
toArray(X[] a)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 

Field Detail

mapper

protected final DynamoDBMapper mapper
Reference to the DynamoDB mapper for marshalling DynamoDB attributes back into objects


clazz

protected final Class<T> clazz
The class annotated with DynamoDB tags declaring how to load/store objects into DynamoDB


dynamo

protected final AmazonDynamoDB dynamo
The client for working with DynamoDB


allResultsLoaded

protected boolean allResultsLoaded
Tracks if all results have been loaded yet or not


allResults

protected final List<T> allResults
All currently loaded results for this list. In ITERATION_ONLY mode, this list will at most keep one page of the loaded results, and all previous results will be cleared from the memory.


nextResults

protected final List<T> nextResults
Lazily loaded next results waiting to be added into allResults

Constructor Detail

PaginatedList

public PaginatedList(DynamoDBMapper mapper,
                     Class<T> clazz,
                     AmazonDynamoDB dynamo)
Constructs a PaginatedList instance using the default PaginationLoadingStrategy


PaginatedList

public PaginatedList(DynamoDBMapper mapper,
                     Class<T> clazz,
                     AmazonDynamoDB dynamo,
                     DynamoDBMapperConfig.PaginationLoadingStrategy paginationLoadingStrategy)
Constructs a PaginatedList instance.

Parameters:
mapper - The mapper for marshalling DynamoDB attributes into objects.
clazz - The class of the annotated model.
dynamo - The DynamoDB client for making low-level request calls.
paginationLoadingStrategy - The strategy used for loading paginated results. Caller has to explicitly set this parameter, since the DynamoDBMapperConfig set in the mapper is not accessible here. If null value is provided, LAZY_LOADING will be set by default.
Method Detail

loadAllResults

public void loadAllResults()
Eagerly loads all results for this list.

Not supported in ITERATION_ONLY mode.


fetchNextPage

protected abstract List<T> fetchNextPage()
Fetches the next page of results (which may be empty) and returns any items found.


atEndOfResults

protected abstract boolean atEndOfResults()
Returns whether we have reached the end of the result set.


iterator

public Iterator<T> iterator()
Returns an iterator over this list that lazily initializes results as necessary.

If it configured with ITERARTION_ONLY mode, then the iterator could be only retrieved once, and any previously loaded results will be cleared in the memory during the iteration.

Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>
Specified by:
iterator in interface List<T>

isEmpty

public boolean isEmpty()
Returns whether the collection is empty. At most one (non-empty) page of results is loaded to make the check.

Not supported in ITERATION_ONLY mode.

Specified by:
isEmpty in interface Collection<T>
Specified by:
isEmpty in interface List<T>

get

public T get(int n)
Returns the Nth element of the list. Results are loaded until N elements are present, if necessary.

Not supported in ITERATION_ONLY mode.

Specified by:
get in interface List<T>

contains

public boolean contains(Object arg0)
Returns whether the collection contains the given element. Results are loaded and checked incrementally until a match is found or the end of the result set is reached.

Not supported in ITERATION_ONLY mode.

Specified by:
contains in interface Collection<T>
Specified by:
contains in interface List<T>

subList

public List<T> subList(int arg0,
                       int arg1)
Returns a sub-list in the range specified, loading more results as necessary.

Not supported in ITERATION_ONLY mode.

Specified by:
subList in interface List<T>

indexOf

public int indexOf(Object arg0)
Returns the first index of the object given in the list. Additional results are loaded incrementally as necessary.

Not supported in ITERATION_ONLY mode.

Specified by:
indexOf in interface List<T>

size

public int size()
Specified by:
size in interface Collection<T>
Specified by:
size in interface List<T>

containsAll

public boolean containsAll(Collection<?> arg0)
Specified by:
containsAll in interface Collection<T>
Specified by:
containsAll in interface List<T>

lastIndexOf

public int lastIndexOf(Object arg0)
Specified by:
lastIndexOf in interface List<T>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<T>
Specified by:
toArray in interface List<T>

toArray

public <X> X[] toArray(X[] a)
Specified by:
toArray in interface Collection<T>
Specified by:
toArray in interface List<T>

listIterator

public ListIterator<T> listIterator()
Specified by:
listIterator in interface List<T>

listIterator

public ListIterator<T> listIterator(int arg0)
Specified by:
listIterator in interface List<T>

remove

public boolean remove(Object arg0)
Specified by:
remove in interface Collection<T>
Specified by:
remove in interface List<T>

remove

public T remove(int arg0)
Specified by:
remove in interface List<T>

removeAll

public boolean removeAll(Collection<?> arg0)
Specified by:
removeAll in interface Collection<T>
Specified by:
removeAll in interface List<T>

retainAll

public boolean retainAll(Collection<?> arg0)
Specified by:
retainAll in interface Collection<T>
Specified by:
retainAll in interface List<T>

set

public T set(int arg0,
             T arg1)
Specified by:
set in interface List<T>

add

public boolean add(T arg0)
Specified by:
add in interface Collection<T>
Specified by:
add in interface List<T>

add

public void add(int arg0,
                T arg1)
Specified by:
add in interface List<T>

addAll

public boolean addAll(Collection<? extends T> arg0)
Specified by:
addAll in interface Collection<T>
Specified by:
addAll in interface List<T>

addAll

public boolean addAll(int arg0,
                      Collection<? extends T> arg1)
Specified by:
addAll in interface List<T>

clear

public void clear()
Specified by:
clear in interface Collection<T>
Specified by:
clear in interface List<T>


Copyright © 2016. All rights reserved.