Home Articles

DynamoDB - JAVA - 具有低级API的BatchWrite

Asked
Viewed 1105 times
0

我想知道我们是否可以使用适用于Java的DynamoDB的低级API执行批量写入/更新 .

提前致谢!

2 Answers

  • 1

    是 . 像这样的东西:

    Map<String, List<WriteRequest>> writeRequestItems = new HashMap<String, List<WriteRequest>>();
    Map<String, AttributeValue> userItem1 = new HashMap<String, AttributeValue>();
    userItem1.put("userId", new AttributeValue().withS("1"));
    userItem1.put("name", new AttributeValue().withS("Alex"));
    Map<String, AttributeValue> userItem2 = new HashMap<String,AttributeValue>();
    userItem2.put("userId", new AttributeValue().withS("2"));
    userItem2.put("name", new AttributeValue().withS("Jonh"));
    List<WriteRequest> userList = new ArrayList<WriteRequest>();
    userList.add(new WriteRequest().withPutRequest(new PutRequest().withItem(userItem1)));
    userList.add(new WriteRequest().withPutRequest(new PutRequest().withItem(userItem2)));
    writeRequestItems.put("User", userList);
    BatchWriteItemRequest batchWriteItemRequest = new BatchWriteItemRequest(writeRequestItems);
    BatchWriteItemResult batchWriteItemResult = dynamoDBClient.batchWriteItem(batchWriteItemRequest);
    

Related