List of usage examples for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBScanExpression setLimit
public void setLimit(Integer limit)
From source file:cf.funge.aworldofplants.model.plant.DDBPlantDAO.java
License:Open Source License
/** * Returns a list of plants in the DynamoDB table. * * @param limit The maximum numbers of results for the scan * @return A List of Plant objects//from w ww .ja va2 s. c om */ public List<Plant> getPlants(int limit) { if (limit <= 0 || limit > DynamoDBConfiguration.SCAN_LIMIT) limit = DynamoDBConfiguration.SCAN_LIMIT; DynamoDBScanExpression expression = new DynamoDBScanExpression(); expression.setLimit(limit); return getMapper().scan(Plant.class, expression); }
From source file:cf.funge.aworldofplants.model.plant.DDBPlantDAO.java
License:Open Source License
public List<Plant> getUserPlants(int limit, String username) { if (limit <= 0 || limit > DynamoDBConfiguration.SCAN_LIMIT) limit = DynamoDBConfiguration.SCAN_LIMIT; Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":val1", new AttributeValue().withS(username)); DynamoDBScanExpression expression = new DynamoDBScanExpression().withFilterExpression("username = :val1") .withExpressionAttributeValues(eav); expression.setLimit(limit); List<Plant> scanResult = getMapper().scan(Plant.class, expression); return scanResult; }
From source file:org.socialsignin.spring.data.dynamodb.repository.support.SimpleDynamoDBPagingAndSortingRepository.java
License:Apache License
@Override public Page<T> findAll(Pageable pageable) { if (pageable.getSort() != null) { throw new UnsupportedOperationException("Sorting not supported for find all scan operations"); }//w ww .j a v a 2 s .c o m DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); // Scan to the end of the page after the requested page int scanTo = pageable.getOffset() + (2 * pageable.getPageSize()); scanExpression.setLimit(scanTo); PaginatedScanList<T> paginatedScanList = dynamoDBOperations.scan(domainType, scanExpression); Iterator<T> iterator = paginatedScanList.iterator(); int processedCount = 0; if (pageable.getOffset() > 0) { processedCount = scanThroughResults(iterator, pageable.getOffset()); if (processedCount < pageable.getOffset()) return new PageImpl<T>(new ArrayList<T>()); } // Scan ahead to retrieve the next page count List<T> results = readPageOfResults(iterator, pageable.getPageSize()); assertScanEnabled(enableScanPermissions.isFindAllPaginatedScanEnabled(), "findAll(Pageable pageable)"); assertScanCountEnabled(enableScanPermissions.isFindAllUnpaginatedScanCountEnabled(), "findAll(Pageable pageable)"); int totalCount = dynamoDBOperations.count(domainType, scanExpression); return new PageImpl<T>(results, pageable, totalCount); }