使用Java中的DynamoDBMapper更新DynamoDB项 [英] Update DynamoDB item using DynamoDBMapper in Java

查看:320
本文介绍了使用Java中的DynamoDBMapper更新DynamoDB项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用DynamoDBMapper更新DynamoDB项目?

How can I update DynamoDB item using DynamoDBMapper?

我有多个进程,使用DynamoDB表,因此,get + save会产生不一致。我找不到使用DynamoDBMapper更新项目的方法。

I have multiple processes, using the DynamoDB table, thus, get + save will create inconsistency. I can not find the method to update the item using DynamoDBMapper.

推荐答案

save( ) 方法将根据值设置执行 putItem updateItem SaveBehavior 中。请参阅以下说明。由于这个原因,DynamoDBMapper类中没有更新方法。但是,有一个单独的删除方法。

The save() method will perform the putItem or updateItem based on the value set in SaveBehavior. Please refer the below description. There is no update method in DynamoDBMapper class because of this reason. However, there is a separate delete method available.


在DynamoDB中保存一个项目。使用的服务方法由
DynamoDBMapperConfig.getSaveBehavior()值决定,使用
AmazonDynamoDB.putItem(PutItemRequest)或
AmazonDynamoDB.updateItem(UpdateItemRequest):

Saves an item in DynamoDB. The service method used is determined by the DynamoDBMapperConfig.getSaveBehavior() value, to use either AmazonDynamoDB.putItem(PutItemRequest) or AmazonDynamoDB.updateItem(UpdateItemRequest):

UPDATE(默认值):
UPDATE不会影响保存操作的未建模属性,而建模属性的
null值会将其删除来自
DynamoDB中的该项目。由于updateItem请求的限制,UPDATE的
实现将在保存仅密钥
对象时发送putItem请求,如果
给定密钥,它将发送另一个updateItem请求(s)已存在于表中。

UPDATE (default) : UPDATE will not affect unmodeled attributes on a save operation and a null value for the modeled attribute will remove it from that item in DynamoDB. Because of the limitation of updateItem request, the implementation of UPDATE will send a putItem request when a key-only object is being saved, and it will send another updateItem request if the given key(s) already exists in the table.

UPDATE_SKIP_NULL_ATTRIBUTES:与UPDATE类似,只是它忽略
任何空值属性(s )并且不会从
DynamoDB中的项目中删除它们。它还保证只发送一个updateItem
请求,无论该对象是否为key-only。

UPDATE_SKIP_NULL_ATTRIBUTES : Similar to UPDATE except that it ignores any null value attribute(s) and will NOT remove them from that item in DynamoDB. It also guarantees to send only one single updateItem request, no matter the object is key-only or not.

CLOBBER: CLOBBER
将清除并替换所有属性,包括未建模的属性,
(删除并重新创建)保存。版本化字段约束也将被忽略
。由于版本化属性,saveExpression参数
中指定的任何选项都将覆盖任何约束。

CLOBBER : CLOBBER will clear and replace all attributes, included unmodeled ones, (delete and recreate) on save. Versioned field constraints will also be disregarded. Any options specified in the saveExpression parameter will be overlaid on any constraints due to versioned attributes.

示例用法: -

DynamoDBMapperConfig dynamoDBMapperConfig = new DynamoDBMapperConfig(SaveBehavior.UPDATE);
dynamoDBMapper.save(yourObject, dynamoDBMapperConfig);

这篇关于使用Java中的DynamoDBMapper更新DynamoDB项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆