加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

使用Java中的DynamoDBMapper更新DynamoDB项

发布时间:2020-12-15 02:57:02 所属栏目:Java 来源:网络整理
导读:如何使用DynamoDBMapper更新DynamoDB项? 我有多个进程,使用DynamoDB表,因此,get save会产生不一致.我找不到使用DynamoDBMapper更新项目的方法. 解决方法 save()方法将根据SaveBehavior中设置的值执行putItem或updateItem.请参阅以下说明.由于这个原因,Dynam
如何使用DynamoDBMapper更新DynamoDB项?

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

解决方法

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

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 (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 : 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
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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读