The save() method will execute putItem or updateItem based on the value set in SaveBehavior . Please refer to the description below. For this reason, the DynamoDBMapper class does not have an update method. However, there is a separate removal method.
Saves an item in DynamoDB. The service method used is determined by the value DynamoDBMapperConfig.getSaveBehavior () to use either AmazonDynamoDB.putItem (PutItemRequest) or AmazonDynamoDB.updateItem (UpdateItemRequest):
UPDATE (default): UPDATE will not affect the unmodeled attributes of the save operation, and a null value for the modeled attribute will remove it from this element in DynamoDB. Due to the restriction of the updateItem request, the UPDATE implementation will send a putItem request when saving the object for the key only and send another updateItem request if the given key already exists in the table.
UPDATE_SKIP_NULL_ATTRIBUTES: similar to UPDATE except that it ignores any attributes with a null value and does NOT remove them from this element in DynamoDB. It also ensures that only one updateItem request is sent, regardless of whether the object is just a key or not.
CLOBBER: CLOBBER will clear and replace all attributes, including unmodeled ones (deletion and re- creation) when saved. Limitations of versioned fields will also be ignored. Any parameters specified in the saveExpression parameter will be imposed on any restrictions due to versioned attributes.
Usage example: -
DynamoDBMapperConfig dynamoDBMapperConfig = new DynamoDBMapperConfig(SaveBehavior.UPDATE);
UPDATE The DynamoDBMapperConfig constructor (aws sdk 1.11.473) seems deprecated, and the constructor should be used instead:
DynamoDBMapperConfig dynamoDBMapperConfig = new DynamoDBMapperConfig.Builder() .withConsistentReads(DynamoDBMapperConfig.ConsistentReads.CONSISTENT) .withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.UPDATE) .build(); dynamoDBMapper.save(yourObject, dynamoDBMapperConfig);
source share