use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-doc-sdk-examples by awsdocs.
the class EnhancedQueryRecordsWithFilter method main.
// Query the Customer table using a filter.
public static void main(String[] args) {
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
queryTableFilter(enhancedClient);
ddb.close();
}
use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient 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.DynamoDbEnhancedClient in project aws-doc-sdk-examples by awsdocs.
the class PersistCase method putRecord.
// Puts an item into a DynamoDB table
public void putRecord(String caseId, String employeeName, String email) {
// Create a DynamoDbClient object
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();
try {
// Create a DynamoDbTable object
DynamoDbTable<Case> caseTable = enhancedClient.table("Case", TableSchema.fromBean(Case.class));
// Create an Instant object
LocalDate localDate = LocalDate.parse("2020-04-07");
LocalDateTime localDateTime = localDate.atStartOfDay();
Instant instant = localDateTime.toInstant(ZoneOffset.UTC);
// Populate the table
Case caseRecord = new Case();
caseRecord.setName(employeeName);
caseRecord.setId(caseId);
caseRecord.setEmail(email);
caseRecord.setRegistrationDate(instant);
// Put the case data into a DynamoDB table
caseTable.putItem(caseRecord);
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("done");
}
use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-doc-sdk-examples by awsdocs.
the class Scenario method scanMovies.
// snippet-end:[dynamodb.java2.scenario.query.main]
// snippet-start:[dynamodb.java2.scenario.scan.main]
// Scan the table.
public static void scanMovies(DynamoDbClient ddb, String tableName) {
System.out.println("******* Scanning all movies.\n");
try {
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
DynamoDbTable<Movies> custTable = enhancedClient.table("Movies", TableSchema.fromBean(Movies.class));
Iterator<Movies> results = custTable.scan().items().iterator();
while (results.hasNext()) {
Movies rec = results.next();
System.out.println("The movie title is " + rec.getTitle());
System.out.println("The movie year is " + rec.getYear());
}
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBService method setItem.
public void setItem(PopData pop) {
// Create a DynamoDbEnhancedClient.
DynamoDbClient ddb = getClient();
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
try {
// Create a DynamoDbTable object.
DynamoDbTable<Population> workTable = enhancedClient.table("Country", TableSchema.fromBean(Population.class));
// Populate the table.
Population record = new Population();
String name = pop.getName();
String code = pop.getCode();
record.setId(name);
record.setCode(code);
record.set2010(pop.get2010());
record.set2011(pop.get2011());
record.set2012(pop.get2012());
record.set2013(pop.get2013());
record.set2014(pop.get2014());
record.set2015(pop.get2015());
record.set2016(pop.get2016());
record.set2017(pop.get2017());
record.set2018(pop.get2018());
record.set2019(pop.get2019());
// Put the customer data into a DynamoDB table.
workTable.putItem(record);
System.out.println("Added record " + recNum);
recNum++;
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations