use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class EnhancedModifyItem method main.
public static void main(String[] args) {
String usage = "Usage:\n" + " <key> <email> \n\n" + "Where:\n" + " key - the name of the key in the table (id120).\n" + " email - the value of the modified email column.\n";
if (args.length != 2) {
System.out.println(usage);
System.exit(1);
}
String key = args[0];
String email = args[1];
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
String updatedValue = modifyItem(enhancedClient, key, email);
System.out.println("The updated name value is " + updatedValue);
ddb.close();
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class EnhancedQueryRecords method main.
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();
String result = queryTable(enhancedClient);
System.out.println(result);
ddb.close();
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class EnhancedScanRecordsWithExpression method main.
public static void main(String[] args) {
String tableName = "Issues";
System.out.format("Creating table \"%s\" with a simple primary key: \"Name\".\n", tableName);
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
createTable(ddb, tableName);
loadData(ddb, tableName);
scanIndex(ddb, tableName, "CreateDateIndex");
scanUsingContains(ddb, tableName, "CreateDateIndex");
queryIndex(ddb, tableName, "CreateDateIndex");
ddb.close();
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBService method getClient.
private DynamoDbClient getClient() {
// Create a DynamoDbClient object.
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
return ddb;
}
use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBService method getItem.
// Get a single item from the Work table based on the Key.
public String getItem(String idValue) {
DynamoDbClient ddb = getClient();
String status = "";
String description = "";
HashMap<String, AttributeValue> keyToGet = new HashMap<String, AttributeValue>();
keyToGet.put("id", AttributeValue.builder().s(idValue).build());
// Create a GetItemRequest object.
GetItemRequest request = GetItemRequest.builder().key(keyToGet).tableName("Work").build();
try {
Map<String, AttributeValue> returnedItem = ddb.getItem(request).item();
// Get keys and values and get description and status.
for (Map.Entry<String, AttributeValue> entry : returnedItem.entrySet()) {
String k = entry.getKey();
AttributeValue v = entry.getValue();
if (k.compareTo("description") == 0) {
description = v.s();
} else if (k.compareTo("status") == 0) {
status = v.s();
}
}
return convertToString(toXmlItem(idValue, description, status));
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
Aggregations