本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.UpdateItemRequest.setTableName方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateItemRequest.setTableName方法的具体用法?Java UpdateItemRequest.setTableName怎么用?Java UpdateItemRequest.setTableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.dynamodbv2.model.UpdateItemRequest
的用法示例。
在下文中一共展示了UpdateItemRequest.setTableName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updatePoint
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入方法依赖的package包/类
public UpdatePointResult updatePoint(UpdatePointRequest updatePointRequest) {
long geohash = S2Manager.generateGeohash(updatePointRequest.getGeoPoint());
long hashKey = S2Manager.generateHashKey(geohash, config.getHashKeyLength());
UpdateItemRequest updateItemRequest = updatePointRequest.getUpdateItemRequest();
updateItemRequest.setTableName(config.getTableName());
AttributeValue hashKeyValue = new AttributeValue().withN(String.valueOf(hashKey));
updateItemRequest.getKey().put(config.getHashKeyAttributeName(), hashKeyValue);
updateItemRequest.getKey().put(config.getRangeKeyAttributeName(), updatePointRequest.getRangeKeyValue());
// Geohash and geoJson cannot be updated.
updateItemRequest.getAttributeUpdates().remove(config.getGeohashAttributeName());
updateItemRequest.getAttributeUpdates().remove(config.getGeoJsonAttributeName());
UpdateItemResult updateItemResult = config.getDynamoDBClient().updateItem(updateItemRequest);
UpdatePointResult updatePointResult = new UpdatePointResult(updateItemResult);
return updatePointResult;
}
示例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;
}
}