List of usage examples for com.amazonaws.services.dynamodbv2.document ItemCollection getLastLowLevelResult
@Override
public R getLastLowLevelResult()
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
License:Open Source License
private Chunk<Item> getItemListForGsi(String indexName, QuerySpec spec) { Preconditions.checkNotNull(spec, "spec must not be null"); final ItemCollection<QueryOutcome> outcome = table.getIndex(indexName).query(spec); List<Item> results = new ArrayList<>(); try {/*from w w w . j av a 2 s . c om*/ outcome.pages().forEach(p -> { p.iterator().forEachRemaining(o -> results.add(o)); }); } catch (AmazonServiceException e) { throw convertDynamoDBException(e, "getting by spec: " + spec.toString(), null /*no write condition exception*/); } Map<String, AttributeValue> lastEvaluatedKey = outcome.getLastLowLevelResult().getQueryResult() .getLastEvaluatedKey(); String lastEvaluatedItemJson = lastEvaluatedKey == null ? null : Item.fromMap(InternalUtils.toSimpleMapValue(lastEvaluatedKey)).toJSON(); return new ChunkImpl<>(results, lastEvaluatedItemJson, null /*chunkable*/); }
From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
License:Open Source License
@Override public Chunk<E> findAll(Chunkable chunkable) { Preconditions.checkNotNull(chunkable); Preconditions.checkArgument(Sort.Direction.DESC != chunkable.getDirection(), "DynamoDB only supports scanning forwards"); ScanSpec spec = new ScanSpec(); if (false == Strings.isNullOrEmpty(chunkable.getPaginationToken())) { spec.withExclusiveStartKey(new PrimaryKey(hashKeyName, chunkable.getPaginationToken())); }/*from w ww . ja va2 s. co m*/ spec.withMaxPageSize(chunkable.getMaxPageSize()).withMaxResultSize(chunkable.getMaxPageSize()); final ItemCollection<ScanOutcome> results = table.scan(spec); final List<Item> itemList; try { itemList = Lists.newArrayList(results.iterator()); } catch (AmazonClientException e) { throw convertDynamoDBException(e, "scan", null /* conditionMessage */); } final List<E> entities = itemList.stream().map(this::convertItemToDomain) //O(n) .collect(Collectors.toList()); //O(n) final Map<String, AttributeValue> lastEvaluatedKey = results.getLastLowLevelResult() == null ? null : results.getLastLowLevelResult().getScanResult().getLastEvaluatedKey(); final String paginationToken = lastEvaluatedKey == null ? null : lastEvaluatedKey.get(hashKeyName).getS(); return new ChunkImpl<>(entities, paginationToken, chunkable); }