Example usage for com.amazonaws.services.simpledb.model SelectRequest getNextToken

List of usage examples for com.amazonaws.services.simpledb.model SelectRequest getNextToken

Introduction

In this page you can find the example usage for com.amazonaws.services.simpledb.model SelectRequest getNextToken.

Prototype


public String getNextToken() 

Source Link

Document

A string informing Amazon SimpleDB where to start the next list of ItemNames.

Usage

From source file:wwutil.jsoda.SimpleDBService.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
public <T> List<T> queryRun(Class<T> modelClass, Query<T> query, boolean continueFromLastRun)
        throws JsodaException {
    List<T> resultObjs = new ArrayList<T>();

    if (continueFromLastRun && !queryHasNext(query))
        return resultObjs;

    String queryStr = toQueryStr(query, false);
    log.info("Query: " + queryStr);
    SelectRequest request = new SelectRequest(queryStr, query.consistentRead);

    if (continueFromLastRun)
        request.setNextToken((String) query.nextKey);

    try {/*from   ww w  . j a va  2  s . c o  m*/
        SelectResult result = sdbClient.select(request);
        query.nextKey = request.getNextToken();
        for (Item item : result.getItems()) {
            String idValue = item.getName(); // get the id from the item's name()
            T obj = buildLoadObj(modelClass, query.modelName, idValue, item.getAttributes(), query);
            resultObjs.add(obj);
        }
        return resultObjs;
    } catch (Exception e) {
        throw new JsodaException(
                "Query failed.  Query: " + request.getSelectExpression() + "  Error: " + e.getMessage(), e);
    }
}