Database Reference
In-Depth Information
// finally create UpdateItemRequest and invoke updateItem
method with this request
UpdateItemRequest updateItemRequest = new
UpdateItemRequest()
.withKey(primaryKey)
.withAttributeUpdates(updateItems);
UpdateItemResult updateItemResult =
dynamoDBClient.updateItem(updateItemRequest);
Delete item
Deleting an item from a table is quite easy; you can simply mention the primary key of the
item to be deleted and the table name, as shown in the following code:
// Hash map of key
HashMap<String, AttributeValue> primaryKey = new
HashMap<String, AttributeValue>();
primaryKey.put("bookId", new
AttributeValue().withN("2001"));
// Create delete item request with primary key and table
name
DeleteItemRequest deleteItemRequest = new
DeleteItemRequest()
.withKey(primaryKey)
.withTableName("Book");
// Invoke delete item method with prepared request
DeleteItemResult deleteItemResult =
dynamoDBClient.deleteItem(deleteItemRequest);
Batch get items
DynamoDB allows us to also get 100 items in one go. You can retrieve multiple items
from multiple tables at a time. But, it is also important not to allow the size of the data re-
trieved to more than 1 MB, as shown in the following code:
// Create map of items to be fetched
HashMap<String, KeysAndAttributes> requestItems = new
Search WWH ::




Custom Search