use of software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional 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");
}
use of software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional 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);
}
}
use of software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional in project aws-doc-sdk-examples by awsdocs.
the class EnhancedQueryRecords method queryTable.
// snippet-start:[dynamodb.java2.mapping.query.main]
public static String queryTable(DynamoDbEnhancedClient enhancedClient) {
try {
DynamoDbTable<Customer> mappedTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class));
QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue("id120").build());
// Get items in the table and write out the ID value
Iterator<Customer> results = mappedTable.query(queryConditional).items().iterator();
String result = "";
while (results.hasNext()) {
Customer rec = results.next();
result = rec.getId();
System.out.println("The record id is " + result);
}
return result;
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional in project aws-doc-sdk-examples by awsdocs.
the class EnhancedQueryRecordsWithFilter method queryTableFilter.
// snippet-start:[dynamodb.java2.mapping.queryfilter.main]
public static void queryTableFilter(DynamoDbEnhancedClient enhancedClient) {
try {
DynamoDbTable<Customer> mappedTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class));
AttributeValue att = AttributeValue.builder().s("sblue@noserver.com").build();
Map<String, AttributeValue> expressionValues = new HashMap<>();
expressionValues.put(":value", att);
Expression expression = Expression.builder().expression("email = :value").expressionValues(expressionValues).build();
// Create a QueryConditional object that is used in the query operation.
QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue("id103").build());
// Get items in the Customer table and write out the ID value.
Iterator<Customer> results = mappedTable.query(r -> r.queryConditional(queryConditional).filterExpression(expression)).items().iterator();
while (results.hasNext()) {
Customer rec = results.next();
System.out.println("The record id is " + rec.getId());
}
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Done");
}
use of software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional in project aws-doc-sdk-examples by awsdocs.
the class Scenario method queryTable.
// snippet-end:[dynamodb.java2.scenario.create_table.main]
// snippet-start:[dynamodb.java2.scenario.query.main]
// Query the table.
public static void queryTable(DynamoDbClient ddb) {
try {
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
DynamoDbTable<Movies> custTable = enhancedClient.table("Movies", TableSchema.fromBean(Movies.class));
QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue(2013).build());
// Get items in the table and write out the ID value
Iterator<Movies> results = custTable.query(queryConditional).items().iterator();
String result = "";
while (results.hasNext()) {
Movies rec = results.next();
System.out.println("The title of the movie is " + rec.getTitle());
System.out.println("The movie information is " + rec.getInfo());
}
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations