Class DynamoDBMapper.SaveObjectHandler
java.lang.Object
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.SaveObjectHandler
- Enclosing class:
- DynamoDBMapper
The handler for saving object using DynamoDBMapper. Caller should
implement the abstract methods to provide the expected behavior on each
scenario, and this handler will take care of all the other basic workflow
and common operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Class<?>
protected final Object
protected final String
Condition operator on the additional expected value conditions specified by the user.protected final Map<String,
ExpectedAttributeValue> Additional expected value conditions specified by the user. -
Constructor Summary
ConstructorsConstructorDescriptionSaveObjectHandler
(Class<?> clazz, Object object, String tableName, DynamoDBMapperConfig saveConfig, ItemConverter converter, DynamoDBSaveExpression saveExpression) Constructs a handler for saving the specified model object. -
Method Summary
Modifier and TypeMethodDescriptionprotected PutItemResult
Save the item using a PutItem request.protected UpdateItemResult
Save the item using a UpdateItem request.void
execute()
The general workflow of a save operation.protected abstract void
Implement this method to send the low-level request that is necessary to complete the save operation.protected Map<String,
AttributeValueUpdate> Get the map of AttributeValueUpdate on each modeled attribute.protected List<com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.ValueUpdate>
Get the list of all the necessary in-memory update on the object.protected DynamoDBMapperConfig.SaveBehavior
Get the SaveBehavior used locally for this save operation.protected Map<String,
AttributeValue> Get the map of all the specified primamry keys of the saved object.protected String
Get the table nameprotected Map<String,
ExpectedAttributeValue> Merge and return all the expected value conditions (either user-specified or imposed by the internal implementation of DynamoDBMapper) for this save operation.protected void
onNonKeyAttribute
(String attributeName, AttributeValue currentValue) Implement this method for necessary operations when a non-key attribute is set a non-null value in the object.protected abstract void
onNullNonKeyAttribute
(String attributeName) Implement this method for necessary operations when a non-key attribute is set null in the object.protected abstract void
onPrimaryKeyAttributeValue
(String attributeName, AttributeValue keyAttributeValue) Implement this method to do the necessary operations when a primary key attribute is set with some value.
-
Field Details
-
object
-
clazz
-
userProvidedExpectedValueConditions
Additional expected value conditions specified by the user. -
userProvidedConditionOperator
Condition operator on the additional expected value conditions specified by the user.
-
-
Constructor Details
-
SaveObjectHandler
public SaveObjectHandler(Class<?> clazz, Object object, String tableName, DynamoDBMapperConfig saveConfig, ItemConverter converter, DynamoDBSaveExpression saveExpression) Constructs a handler for saving the specified model object.- Parameters:
object
- The model object to be saved.clazz
- The domain class of the object.tableName
- The table name.saveConifg
- The mapper configuration used for this save.saveExpression
- The save expression, including the user-provided conditions and an optional logic operator.
-
-
Method Details
-
execute
public void execute()The general workflow of a save operation. -
onPrimaryKeyAttributeValue
protected abstract void onPrimaryKeyAttributeValue(String attributeName, AttributeValue keyAttributeValue) Implement this method to do the necessary operations when a primary key attribute is set with some value.- Parameters:
attributeName
- The name of the primary key attribute.keyAttributeValue
- The AttributeValue of the primary key attribute as specified in the object.
-
onNonKeyAttribute
Implement this method for necessary operations when a non-key attribute is set a non-null value in the object. The default implementation simply adds a "PUT" update for the given attribute.- Parameters:
attributeName
- The name of the non-key attribute.currentValue
- The updated value of the given attribute.
-
onNullNonKeyAttribute
Implement this method for necessary operations when a non-key attribute is set null in the object.- Parameters:
attributeName
- The name of the non-key attribute.
-
executeLowLevelRequest
protected abstract void executeLowLevelRequest()Implement this method to send the low-level request that is necessary to complete the save operation. -
getLocalSaveBehavior
Get the SaveBehavior used locally for this save operation. -
getTableName
Get the table name -
getPrimaryKeyAttributeValues
Get the map of all the specified primamry keys of the saved object. -
getAttributeValueUpdates
Get the map of AttributeValueUpdate on each modeled attribute. -
mergeExpectedAttributeValueConditions
Merge and return all the expected value conditions (either user-specified or imposed by the internal implementation of DynamoDBMapper) for this save operation. -
getInMemoryUpdates
protected List<com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.ValueUpdate> getInMemoryUpdates()Get the list of all the necessary in-memory update on the object. -
doUpdateItem
Save the item using a UpdateItem request. The handler will call this method if- CLOBBER configuration is not being used;
- AND the item does not contain auto-generated key value;
The ReturnedValues parameter for the UpdateItem request is set as ALL_NEW, which means the service should return all of the attributes of the new version of the item after the update. The handler will use the returned attributes to detect silent failure on the server-side.
-
doPutItem
Save the item using a PutItem request. The handler will call this method if- CLOBBER configuration is being used;
- OR the item contains auto-generated key value;
- OR an UpdateItem request has silently failed (200 response with no affected attribute), which indicates the key-only-put scenario that we used to handle by the keyOnlyPut(...) hack.
-