Java Code Examples for com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper#scan()
The following examples show how to use
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper#scan() .
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: DBUtil.java From chatbot with Apache License 2.0 | 7 votes |
public static StarWarsCharacter getCharacter(String name) { System.out.println("Name: " + name); DynamoDBMapper mapper = new DynamoDBMapper(getClient()); Map<String, AttributeValue> eav = new HashMap<>(); eav.put(":name", new AttributeValue().withS(name.toLowerCase())); DynamoDBScanExpression scanExpression = new DynamoDBScanExpression() .withFilterExpression("whoami = :name") .withExpressionAttributeValues(eav); List<StarWarsCharacter> list = mapper.scan(StarWarsCharacter.class, scanExpression); if (!list.isEmpty()) { return list.get(0); } return null; }
Example 2
Source File: DynamoDBMapperQueryScanExample.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
private static void FindBooksPricedLessThanSpecifiedValue(DynamoDBMapper mapper, String value) throws Exception { System.out.println("FindBooksPricedLessThanSpecifiedValue: Scan ProductCatalog."); Map<String, AttributeValue> eav = new HashMap<String, AttributeValue>(); eav.put(":val1", new AttributeValue().withN(value)); eav.put(":val2", new AttributeValue().withS("Book")); DynamoDBScanExpression scanExpression = new DynamoDBScanExpression() .withFilterExpression("Price < :val1 and ProductCategory = :val2").withExpressionAttributeValues(eav); List<Book> scanResult = mapper.scan(Book.class, scanExpression); for (Book book : scanResult) { System.out.println(book); } }
Example 3
Source File: ScanITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * Tests scanning the table with AND/OR logic operator. */ @Test public void testScanWithConditionalOperator() { DynamoDBMapper mapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); DynamoDBScanExpression scanExpression = new DynamoDBScanExpression() .withLimit(SCAN_LIMIT) .withScanFilter(ImmutableMapParameter.of( "value", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL), "non-existent-field", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL) )) .withConditionalOperator(ConditionalOperator.AND); List<SimpleClass> andConditionResult = mapper.scan(SimpleClass.class, scanExpression); assertTrue(andConditionResult.isEmpty()); List<SimpleClass> orConditionResult = mapper.scan(SimpleClass.class, scanExpression.withConditionalOperator(ConditionalOperator.OR)); assertFalse(orConditionResult.isEmpty()); }
Example 4
Source File: ScanITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@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 5
Source File: MapperLoadingStrategyConfigITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
private static PaginatedList<RangeKeyTestClass> getTestPaginatedScanList(PaginationLoadingStrategy paginationLoadingStrategy) { DynamoDBMapperConfig mapperConfig = new DynamoDBMapperConfig(ConsistentReads.CONSISTENT); DynamoDBMapper mapper = new DynamoDBMapper(dynamo, mapperConfig); // Construct the scan expression with the exact same conditions DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); scanExpression.addFilterCondition("key", new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList( new AttributeValue().withN(Long.toString(hashKey)))); scanExpression.addFilterCondition("rangeKey", new Condition().withComparisonOperator(ComparisonOperator.GT).withAttributeValueList( new AttributeValue().withN("1.0"))); scanExpression.setLimit(PAGE_SIZE); return mapper.scan(RangeKeyTestClass.class, scanExpression, new DynamoDBMapperConfig(paginationLoadingStrategy)); }
Example 6
Source File: ObjectPersistenceQueryScanExample.java From aws-dynamodb-examples with Apache License 2.0 | 6 votes |
private static void FindBooksPricedLessThanSpecifiedValue( DynamoDBMapper mapper, String value) throws Exception { System.out.println("FindBooksPricedLessThanSpecifiedValue: Scan ProductCatalog."); DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); scanExpression.addFilterCondition("Price", new Condition() .withComparisonOperator(ComparisonOperator.LT) .withAttributeValueList(new AttributeValue().withN(value))); scanExpression.addFilterCondition("ProductCategory", new Condition() .withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS("Book"))); List<Book> scanResult = mapper.scan(Book.class, scanExpression); for (Book book : scanResult) { System.out.println(book); } }
Example 7
Source File: ScanITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test public void testScan() 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())); List<SimpleClass> list = util.scan(SimpleClass.class, scanExpression); int count = 0; Iterator<SimpleClass> iterator = list.iterator(); while (iterator.hasNext()) { count++; SimpleClass next = iterator.next(); assertNotNull(next.getExtraData()); assertNotNull(next.getValue()); } int totalCount = util.count(SimpleClass.class, scanExpression); assertNotNull(list.get(totalCount / 2)); assertTrue(totalCount == count); assertTrue(totalCount == list.size()); assertTrue(list.contains(list.get(list.size() / 2))); assertTrue(count == list.toArray().length); }