vendredi 25 septembre 2015

Pagination with DynamoDBMapper Java AWS SDK

From the API docs dynamo db does support pagination for scan and query operations. The catch here is to set the ExclusiveStartIndex of current request to the value of the LastEvaluatedIndex of previous request to get next set (logical page) of results.

I'm trying to implement the same but I'm using DynamoDBMapper, which seems to have lot more advantages like tight coupling with data models. So if I wanted to do the above, I'm assuming I would do something like below:

// Mapping of hashkey of the last item in previous query operation Map<String, AttributeValue> lastHashKey = .. DynamoDBQueryExpressoin expression = new DynamoDBQueryExpression(); ... expression.setExclusiveStartKey(); List<Table> nextPageResults = mapper.query(Table.class, expression);

I hope my above understanding is correct on paginating using DynamoDBMapper. Secondly, how would I know that I've reached the end of results. From the docs if I use the following api:

QueryResult result = dynamoDBClient.query((QueryRequest) request); boolean isEndOfResults = StringUtils.isEmpty(result.getLastEvaluatedKey());

Coming back to using DynamoDBMapper, how can I know if I've reached end of results in this case.




Aucun commentaire:

Enregistrer un commentaire