Search in sources :

Example 1 with Page

use of software.amazon.awssdk.enhanced.dynamodb.model.Page in project aws-doc-sdk-examples by awsdocs.

the class EnhancedQueryRecordsWithSortKey method queryTableSort.

// snippet-start:[dynamodb.java2.mapping.querykey.main]
public static void queryTableSort(DynamoDbEnhancedClient enhancedClient) {
    try {
        // Create a DynamoDbTable object based on Issues.
        DynamoDbTable<Issues> table = enhancedClient.table("Issues", TableSchema.fromBean(Issues.class));
        String dateVal = "2013-11-19";
        DynamoDbIndex<Issues> secIndex = enhancedClient.table("Issues", TableSchema.fromBean(Issues.class)).index("dueDateIndex");
        AttributeValue attVal = AttributeValue.builder().s(dateVal).build();
        // Create a QueryConditional object that's used in the query operation.
        QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue(attVal).build());
        // Get items in the Issues table.
        SdkIterable<Page<Issues>> results = secIndex.query(QueryEnhancedRequest.builder().queryConditional(queryConditional).build());
        AtomicInteger atomicInteger = new AtomicInteger();
        atomicInteger.set(0);
        results.forEach(page -> {
            Issues issue = (Issues) page.items().get(atomicInteger.get());
            System.out.println("The issue title is " + issue.getTitle());
            atomicInteger.incrementAndGet();
        });
    } catch (DynamoDbException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    System.out.println("Done");
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) QueryConditional(software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) Page(software.amazon.awssdk.enhanced.dynamodb.model.Page)

Example 2 with Page

use of software.amazon.awssdk.enhanced.dynamodb.model.Page in project aws-doc-sdk-examples by awsdocs.

the class EnhancedScanRecordsWithExpression method queryIndex.

// Query the table using a secondary index.
public static void queryIndex(DynamoDbClient ddb, String tableName, String indexName) {
    try {
        // Create a DynamoDbEnhancedClient and use the DynamoDbClient object.
        DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
        // Create a DynamoDbTable object based on Issues.
        DynamoDbTable<Issues> table = enhancedClient.table("Issues", TableSchema.fromBean(Issues.class));
        String dateVal = "2013-11-19";
        DynamoDbIndex<Issues> secIndex = enhancedClient.table("Issues", TableSchema.fromBean(Issues.class)).index("dueDateIndex");
        AttributeValue attVal = AttributeValue.builder().s(dateVal).build();
        // Create a QueryConditional object that's used in the query operation.
        QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue(attVal).build());
        // Get items in the Issues table.
        SdkIterable<Page<Issues>> results = secIndex.query(QueryEnhancedRequest.builder().queryConditional(queryConditional).build());
        AtomicInteger atomicInteger = new AtomicInteger();
        atomicInteger.set(0);
        results.forEach(page -> {
            Issues issue = (Issues) page.items().get(atomicInteger.get());
            System.out.println("The issue title is " + issue.getTitle());
            atomicInteger.incrementAndGet();
        });
    } catch (DynamoDbException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : QueryConditional(software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Page(software.amazon.awssdk.enhanced.dynamodb.model.Page) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Page (software.amazon.awssdk.enhanced.dynamodb.model.Page)2 QueryConditional (software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional)2 DynamoDbEnhancedClient (software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)1 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)1 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)1