List of usage examples for com.amazonaws.services.dynamodbv2.document.spec ScanSpec withMaxPageSize
@Override public ScanSpec withMaxPageSize(int maxPageSize)
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 w w .ja v a 2s . c o 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); }