use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project aws-doc-sdk-examples by awsdocs.
the class UpdateItem method updateTableItem.
// snippet-start:[dynamodb.java2.update_item.main]
public static void updateTableItem(DynamoDbClient ddb, String tableName, String key, String keyVal, String name, String updateVal) {
HashMap<String, AttributeValue> itemKey = new HashMap<String, AttributeValue>();
itemKey.put(key, AttributeValue.builder().s(keyVal).build());
HashMap<String, AttributeValueUpdate> updatedValues = new HashMap<String, AttributeValueUpdate>();
// Update the column specified by name with updatedVal
updatedValues.put(name, AttributeValueUpdate.builder().value(AttributeValue.builder().s(updateVal).build()).action(AttributeAction.PUT).build());
UpdateItemRequest request = UpdateItemRequest.builder().tableName(tableName).key(itemKey).attributeUpdates(updatedValues).build();
try {
ddb.updateItem(request);
} catch (ResourceNotFoundException e) {
System.err.println(e.getMessage());
System.exit(1);
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Done!");
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project cas by apereo.
the class DynamoDbWebAuthnFacilitator method buildTableAttributeValuesMap.
/**
* Build table attribute values map.
*
* @param record the record
* @return the map
*/
private static Map<String, AttributeValue> buildTableAttributeValuesMap(final DynamoDbWebAuthnCredentialRegistration record) {
val values = new HashMap<String, AttributeValue>();
values.put(ColumnNames.PRINCIPAL.getColumnName(), AttributeValue.builder().s(record.getUsername().trim().toLowerCase()).build());
val records = record.getRecords().stream().map(value -> AttributeValue.builder().s(value).build()).collect(Collectors.toList());
values.put(ColumnNames.RECORDS.getColumnName(), AttributeValue.builder().l(records).build());
LOGGER.debug("Created attribute values [{}] based on [{}]", values, record);
return values;
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project aws-doc-sdk-examples by awsdocs.
the class PutItem method putItemInTable.
// snippet-start:[dynamodb.java2.put_item.main]
public static void putItemInTable(DynamoDbClient ddb, String tableName, String key, String keyVal, String albumTitle, String albumTitleValue, String awards, String awardVal, String songTitle, String songTitleVal) {
HashMap<String, AttributeValue> itemValues = new HashMap<String, AttributeValue>();
// Add all content to the table
itemValues.put(key, AttributeValue.builder().s(keyVal).build());
itemValues.put(songTitle, AttributeValue.builder().s(songTitleVal).build());
itemValues.put(albumTitle, AttributeValue.builder().s(albumTitleValue).build());
itemValues.put(awards, AttributeValue.builder().s(awardVal).build());
PutItemRequest request = PutItemRequest.builder().tableName(tableName).item(itemValues).build();
try {
ddb.putItem(request);
System.out.println(tableName + " was successfully updated");
} catch (ResourceNotFoundException e) {
System.err.format("Error: The Amazon DynamoDB table \"%s\" can't be found.\n", tableName);
System.err.println("Be sure that it exists and that you've typed its name correctly!");
System.exit(1);
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project aws-doc-sdk-examples by awsdocs.
the class Scenario method getItem.
// snippet-start:[dynamodb.java2.scenario.get_item.main]
public static void getItem(DynamoDbClient ddb) {
HashMap<String, AttributeValue> keyToGet = new HashMap<String, AttributeValue>();
keyToGet.put("year", AttributeValue.builder().n("1933").build());
keyToGet.put("title", AttributeValue.builder().s("King Kong").build());
GetItemRequest request = GetItemRequest.builder().key(keyToGet).tableName("Movies").build();
try {
Map<String, AttributeValue> returnedItem = ddb.getItem(request).item();
if (returnedItem != null) {
Set<String> keys = returnedItem.keySet();
System.out.println("Amazon DynamoDB table attributes: \n");
for (String key1 : keys) {
System.out.format("%s: %s\n", key1, returnedItem.get(key1).toString());
}
} else {
System.out.format("No item found with the key %s!\n", "year");
}
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBScanItems method scanItems.
// snippet-start:[dynamodb.java2.dynamoDB_scan.main]
public static void scanItems(DynamoDbClient ddb, String tableName) {
try {
ScanRequest scanRequest = ScanRequest.builder().tableName(tableName).build();
ScanResponse response = ddb.scan(scanRequest);
for (Map<String, AttributeValue> item : response.items()) {
Set<String> keys = item.keySet();
for (String key : keys) {
System.out.println("The key name is " + key + "\n");
System.out.println("The value is " + item.get(key).s());
}
}
} catch (DynamoDbException e) {
e.printStackTrace();
System.exit(1);
}
}
Aggregations