本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.UpdateItemRequest.setAttributeUpdates方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateItemRequest.setAttributeUpdates方法的具体用法?Java UpdateItemRequest.setAttributeUpdates怎么用?Java UpdateItemRequest.setAttributeUpdates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.dynamodbv2.model.UpdateItemRequest
的用法示例。
在下文中一共展示了UpdateItemRequest.setAttributeUpdates方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: UpdatePointRequest
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入方法依赖的package包/类
public UpdatePointRequest(GeoPoint geoPoint, AttributeValue rangeKeyValue) {
updateItemRequest = new UpdateItemRequest();
updateItemRequest.setKey(new HashMap<String, AttributeValue>());
updateItemRequest.setAttributeUpdates(new HashMap<String, AttributeValueUpdate>());
this.geoPoint = geoPoint;
this.rangeKeyValue = rangeKeyValue;
}
示例2: update
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入方法依赖的package包/类
@Override
public <T extends Message> boolean update(T item, Modifier... modifiers) throws DataStoreException {
DynamoClassMapping<T> tableInfo = getClassMapping(item);
log.debug("Update {} {} [{}]", item.getClass().getSimpleName(), item, modifiers);
UpdateItemRequest request = new UpdateItemRequest();
request.setTableName(tableInfo.getDynamoTableName());
request.setKey(tableInfo.buildCompleteKey(item));
Map<String, ExpectedAttributeValue> expected = Maps.newHashMap();
expected.put(FIELD_HASH_KEY, new ExpectedAttributeValue().withComparisonOperator(ComparisonOperator.NOT_NULL));
for (Modifier modifier : modifiers) {
if (modifier instanceof WhereModifier) {
WhereModifier where = (WhereModifier) modifier;
Map<FieldDescriptor, Object> matcherFields = where.getMatcher().getAllFields();
for (Map.Entry<FieldDescriptor, Object> matcherField : matcherFields.entrySet()) {
FieldDescriptor fieldDescriptor = matcherField.getKey();
Object fieldValue = matcherField.getValue();
tableInfo.addFilter(expected, fieldDescriptor, fieldValue);
}
} else {
throw new UnsupportedOperationException();
}
}
Map<String, AttributeValueUpdate> attributeUpdates = tableInfo.mapToUpdate(item);
request.setAttributeUpdates(attributeUpdates);
request.setExpected(expected);
if (expected.size() > 1) {
request.setConditionalOperator(ConditionalOperator.AND);
}
try {
UpdateItemResult response = dynamoDB.updateItem(request);
return true;
} catch (ConditionalCheckFailedException e) {
log.debug("Update failed (conditional check failed)");
return false;
}
}