com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractDAO.java    From nfscan with MIT License 6 votes vote down vote up
/**
 * Find all rows in table given the entity object
 *
 * @return a list of entities found
 * @throws DataAccessException
 */
public List<T> findAll() throws DataAccessException {
    DynamoDBScanExpression dynamoDBScanExpression = new DynamoDBScanExpression();
    DynamoDBMapperConfig config = new DynamoDBMapperConfig(DynamoDBMapperConfig.PaginationLoadingStrategy.EAGER_LOADING);
    PaginatedScanList<T> paginatedScanList = dynamoDBMapper.scan(getType(), dynamoDBScanExpression, config);
    paginatedScanList.loadAllResults();

    List<T> list = new ArrayList<T>(paginatedScanList.size());

    Iterator<T> iterator = paginatedScanList.iterator();
    while (iterator.hasNext()) {
        T element = iterator.next();
        list.add(element);
    }

    return list;
}
 
Example #2
Source File: ScanITCase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@Test(enabled = false)
public void testParallelScanPerformance() throws Exception{
    DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo);

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression().withLimit(SCAN_LIMIT);
    scanExpression.addFilterCondition("value", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));
    scanExpression.addFilterCondition("extraData", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));

    long startTime = System.currentTimeMillis();
    PaginatedScanList<SimpleClass> scanList = util.scan(SimpleClass.class, scanExpression);
    scanList.loadAllResults();
    long fullTableScanTime = System.currentTimeMillis() - startTime;
    startTime = System.currentTimeMillis();
    PaginatedParallelScanList<SimpleClass> parallelScanList = util.parallelScan(SimpleClass.class, scanExpression, PARALLEL_SCAN_SEGMENTS);
    parallelScanList.loadAllResults();
    long parallelScanTime = System.currentTimeMillis() - startTime;
    assertTrue(scanList.size() == parallelScanList.size());
    assertTrue(fullTableScanTime > parallelScanTime);
    System.out.println("fullTableScanTime : " + fullTableScanTime + "(ms), parallelScanTime : " + parallelScanTime + "(ms).");
}
 
Example #3
Source File: DynamoDBTemplate.java    From spring-data-dynamodb with Apache License 2.0 6 votes vote down vote up
@Override
public <T> PaginatedScanList<T> scan(Class<T> domainClass,
		DynamoDBScanExpression scanExpression) {
	PaginatedScanList<T> results = dynamoDBMapper.scan(domainClass, scanExpression);
	maybeEmitEvent(new AfterScanEvent<T>(results));
	return results;
}
 
Example #4
Source File: SimpleDynamoDBPagingAndSortingRepository.java    From spring-data-dynamodb with Apache License 2.0 5 votes vote down vote up
@Override
public Page<T> findAll(Pageable pageable) {

	if (pageable.getSort() != null) {
		throw new UnsupportedOperationException("Sorting not supported for find all scan operations");
	}

	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);

}
 
Example #5
Source File: AfterScanEvent.java    From spring-data-dynamodb with Apache License 2.0 4 votes vote down vote up
public AfterScanEvent(PaginatedScanList<T> source) {
	super(source);
}
 
Example #6
Source File: AbstractDAO.java    From nfscan with MIT License 3 votes vote down vote up
/**
 * Counts all rows in this specific table.
 * Use it carefully since it loads all results from DynamoDB. To be honest there are only
 * a few situations where this could be considered a wise solution.
 *
 * @return a amount of rows found
 * @throws DataAccessException
 */
public int count() throws DataAccessException {
    DynamoDBScanExpression dynamoDBScanExpression = new DynamoDBScanExpression();
    DynamoDBMapperConfig config = new DynamoDBMapperConfig(DynamoDBMapperConfig.PaginationLoadingStrategy.EAGER_LOADING);
    PaginatedScanList<T> paginatedScanList = dynamoDBMapper.scan(getType(), dynamoDBScanExpression, config);
    paginatedScanList.loadAllResults();
    return paginatedScanList.size();
}
 
Example #7
Source File: DynamoDBOperations.java    From spring-data-dynamodb with Apache License 2.0 votes vote down vote up
public <T> PaginatedScanList<T> scan(Class<T> domainClass,DynamoDBScanExpression scanExpression);