use of software.amazon.awssdk.enhanced.dynamodb.model.ScanEnhancedRequest in project aws-doc-sdk-examples by awsdocs.
the class EnhancedScanRecordsWithExpression method scanIndex.
// snippet-start:[dynamodb.java2.mapping.scanEx.main]
// Scan the table and retrieve only items where createDate is 2013-11-15.
public static void scanIndex(DynamoDbClient ddb, String tableName, String indexName) {
System.out.println("\n***********************************************************\n");
System.out.print("Select items for " + tableName + " where createDate is 2013-11-15!");
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));
// Setup the scan based on the index.
if (indexName == "CreateDateIndex") {
System.out.println("Issues filed on 2013-11-15");
AttributeValue attVal = AttributeValue.builder().s("2013-11-15").build();
// Get only items in the Issues table for 2013-11-15.
Map<String, AttributeValue> myMap = new HashMap<>();
myMap.put(":val1", attVal);
Map<String, String> myExMap = new HashMap<>();
myExMap.put("#createDate", "createDate");
Expression expression = Expression.builder().expressionValues(myMap).expressionNames(myExMap).expression("#createDate = :val1").build();
ScanEnhancedRequest enhancedRequest = ScanEnhancedRequest.builder().filterExpression(expression).limit(15).build();
// Get items in the Issues table.
Iterator<Issues> results = table.scan(enhancedRequest).items().iterator();
while (results.hasNext()) {
Issues issue = results.next();
System.out.println("The record description is " + issue.getDescription());
System.out.println("The record title is " + issue.getTitle());
}
}
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.enhanced.dynamodb.model.ScanEnhancedRequest in project aws-doc-sdk-examples by awsdocs.
the class EnhancedScanRecordsWithExpression method scanUsingContains.
// snippet-end:[dynamodb.java2.mapping.scanEx.main]
// Scan table for records where title contains the word issues using the contains function
public static void scanUsingContains(DynamoDbClient ddb, String tableName, String indexName) {
System.out.println("\n***********************************************************\n");
System.out.print("Select items for " + tableName + " where title contains the word issues");
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));
AttributeValue attVal = AttributeValue.builder().s("issue").build();
Map<String, AttributeValue> myMap = new HashMap<>();
myMap.put(":val1", attVal);
Map<String, String> myExMap = new HashMap<>();
myExMap.put("#title", "title");
Expression expression = Expression.builder().expressionValues(myMap).expressionNames(myExMap).expression("contains(#title, :val1)").build();
ScanEnhancedRequest enhancedRequest = ScanEnhancedRequest.builder().filterExpression(expression).limit(15).build();
// Get items in the Issues table.
Iterator<Issues> results = table.scan(enhancedRequest).items().iterator();
while (results.hasNext()) {
Issues issue = results.next();
System.out.println("The record description is " + issue.getDescription());
System.out.println("The record title is " + issue.getTitle());
}
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.enhanced.dynamodb.model.ScanEnhancedRequest in project aws-doc-sdk-examples by awsdocs.
the class ScanEmployees method sendEmployeMessage.
public Boolean sendEmployeMessage() {
Boolean send = false;
String myDate = getDate();
Region region = Region.US_WEST_2;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
// Create a DynamoDbEnhancedClient and use the DynamoDbClient object.
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
// Create a DynamoDbTable object based on Employee.
DynamoDbTable<Employee> table = enhancedClient.table("Employee", TableSchema.fromBean(Employee.class));
try {
AttributeValue attVal = AttributeValue.builder().s(myDate).build();
// Get only items in the Employee table that match the date.
Map<String, AttributeValue> myMap = new HashMap<>();
myMap.put(":val1", attVal);
Map<String, String> myExMap = new HashMap<>();
myExMap.put("#startDate", "startDate");
Expression expression = Expression.builder().expressionValues(myMap).expressionNames(myExMap).expression("#startDate = :val1").build();
ScanEnhancedRequest enhancedRequest = ScanEnhancedRequest.builder().filterExpression(expression).limit(// you can increase this value.
15).build();
// Get items in the Employee table.
Iterator<Employee> employees = table.scan(enhancedRequest).items().iterator();
while (employees.hasNext()) {
Employee employee = employees.next();
String first = employee.getFirst();
String phone = employee.getPhone();
// Send an anniversary message.
sentTextMessage(first, phone);
send = true;
}
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return send;
}
use of software.amazon.awssdk.enhanced.dynamodb.model.ScanEnhancedRequest in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBService method getClosedItems.
// Get Closed Items from the DynamoDB table.
public String getClosedItems() {
// Create a DynamoDbEnhancedClient.
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(getClient()).build();
try {
// Create a DynamoDbTable object.
DynamoDbTable<Work> table = enhancedClient.table("Work", TableSchema.fromBean(Work.class));
AttributeValue attr = AttributeValue.builder().s("Closed").build();
Map<String, AttributeValue> myMap = new HashMap<>();
myMap.put(":val1", attr);
Map<String, String> myExMap = new HashMap<>();
myExMap.put("#archive", "archive");
// Set the Expression so only Closed items are queried from the Work table.
Expression expression = Expression.builder().expressionValues(myMap).expressionNames(myExMap).expression("#archive = :val1").build();
ScanEnhancedRequest enhancedRequest = ScanEnhancedRequest.builder().filterExpression(expression).limit(15).build();
// Get items.
Iterator<Work> results = table.scan(enhancedRequest).items().iterator();
WorkItem workItem;
ArrayList<WorkItem> itemList = new ArrayList();
while (results.hasNext()) {
// Populate a WorkItem.
workItem = new WorkItem();
Work work = results.next();
workItem.setName(work.getName());
workItem.setGuide(work.getGuide());
workItem.setDescription(work.getDescription());
workItem.setStatus(work.getStatus());
workItem.setDate(work.getDate());
workItem.setId(work.getId());
// Push the workItem to the list.
itemList.add(workItem);
}
return convertToString(toXml(itemList));
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Done");
return "";
}
use of software.amazon.awssdk.enhanced.dynamodb.model.ScanEnhancedRequest in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBService method getOpenItems.
// Get Open items from the DynamoDB table.
public String getOpenItems() {
// Create a DynamoDbEnhancedClient.
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(getClient()).build();
try {
// Create a DynamoDbTable object.
DynamoDbTable<Work> table = enhancedClient.table("Work", TableSchema.fromBean(Work.class));
AttributeValue attr = AttributeValue.builder().s("Open").build();
Map<String, AttributeValue> myMap = new HashMap<>();
myMap.put(":val1", attr);
Map<String, String> myExMap = new HashMap<>();
myExMap.put("#archive", "archive");
// Set the Expression so only Closed items are queried from the Work table.
Expression expression = Expression.builder().expressionValues(myMap).expressionNames(myExMap).expression("#archive = :val1").build();
ScanEnhancedRequest enhancedRequest = ScanEnhancedRequest.builder().filterExpression(expression).limit(15).build();
// Scan items.
Iterator<Work> results = table.scan(enhancedRequest).items().iterator();
WorkItem workItem;
ArrayList<WorkItem> itemList = new ArrayList();
while (results.hasNext()) {
// Populate a WorkItem.
workItem = new WorkItem();
Work work = results.next();
workItem.setName(work.getName());
workItem.setGuide(work.getGuide());
workItem.setDescription(work.getDescription());
workItem.setStatus(work.getStatus());
workItem.setDate(work.getDate());
workItem.setId(work.getId());
// Push the workItem to the list.
itemList.add(workItem);
}
return convertToString(toXml(itemList));
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Done");
return "";
}
Aggregations