本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.DeleteItemRequest.setTableName方法的典型用法代码示例。如果您正苦于以下问题:Java DeleteItemRequest.setTableName方法的具体用法?Java DeleteItemRequest.setTableName怎么用?Java DeleteItemRequest.setTableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.dynamodbv2.model.DeleteItemRequest
的用法示例。
在下文中一共展示了DeleteItemRequest.setTableName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import com.amazonaws.services.dynamodbv2.model.DeleteItemRequest; //导入方法依赖的package包/类
@Override
public <T extends Message> boolean delete(T item, Modifier... modifiers) throws DataStoreException {
DynamoClassMapping<T> tableInfo = getClassMapping(item);
log.debug("Delete {}", item);
for (Modifier modifier : modifiers) {
throw new UnsupportedOperationException();
}
DeleteItemRequest request = new DeleteItemRequest();
request.setTableName(tableInfo.getDynamoTableName());
request.setKey(tableInfo.buildCompleteKey(item));
request.setConditionExpression("attribute_exists(hash_key)");
try {
DeleteItemResult response = dynamoDB.deleteItem(request);
return true;
} catch (ConditionalCheckFailedException e) {
return false;
}
}
示例2: deletePoint
import com.amazonaws.services.dynamodbv2.model.DeleteItemRequest; //导入方法依赖的package包/类
public DeletePointResult deletePoint(DeletePointRequest deletePointRequest) {
long geohash = S2Manager.generateGeohash(deletePointRequest.getGeoPoint());
long hashKey = S2Manager.generateHashKey(geohash, config.getHashKeyLength());
DeleteItemRequest deleteItemRequest = deletePointRequest.getDeleteItemRequest();
deleteItemRequest.setTableName(config.getTableName());
AttributeValue hashKeyValue = new AttributeValue().withN(String.valueOf(hashKey));
deleteItemRequest.getKey().put(config.getHashKeyAttributeName(), hashKeyValue);
deleteItemRequest.getKey().put(config.getRangeKeyAttributeName(), deletePointRequest.getRangeKeyValue());
DeleteItemResult deleteItemResult = config.getDynamoDBClient().deleteItem(deleteItemRequest);
DeletePointResult deletePointResult = new DeletePointResult(deleteItemResult);
return deletePointResult;
}
示例3: delete
import com.amazonaws.services.dynamodbv2.model.DeleteItemRequest; //导入方法依赖的package包/类
@Override
public void delete(final Map<String, AttributeValue> attributes)
throws IOException {
final AmazonDynamoDB aws = this.credentials.aws();
try {
final DeleteItemRequest request = new DeleteItemRequest();
request.setTableName(this.self);
request.setKey(attributes);
request.setReturnValues(ReturnValue.NONE);
request.setReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
final DeleteItemResult result = aws.deleteItem(request);
final long start = System.currentTimeMillis();
Logger.info(
this,
"#delete('%[text]s'): deleted item in '%s', %s, in %[ms]s",
attributes, this.self,
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to delete at \"%s\" by keys %s",
this.self, attributes
),
ex
);
} finally {
aws.shutdown();
}
}
示例4: reindex
import com.amazonaws.services.dynamodbv2.model.DeleteItemRequest; //导入方法依赖的package包/类
public <T extends Message> List<T> reindex(T instance) throws DataStoreException {
DynamoClassMapping<T> tableInfo = getClassMapping(instance);
log.debug("reindex {}", instance.getClass().getSimpleName());
ScanRequest scanRequest = new ScanRequest();
scanRequest.setTableName(tableInfo.getDynamoTableName());
// TODO: Filter expressions on prefix?
ScanResult scanResponse = dynamoDB.scan(scanRequest);
Map<String, AttributeValue> lastEvaluatedKey = scanResponse.getLastEvaluatedKey();
if (lastEvaluatedKey != null) {
throw new UnsupportedOperationException("Multiple page results not implemented");
}
List<T> items = Lists.newArrayList();
List<Map<String, AttributeValue>> responseItems = scanResponse.getItems();
for (Map<String, AttributeValue> itemData : responseItems) {
if (!tableInfo.matchesType(itemData)) {
continue;
}
T item = tableInfo.mapFromDb(itemData);
Map<String, AttributeValue> newItemData = tableInfo.mapToDb(item);
if (DynamoDbHelpers.areEqual(itemData, newItemData)) {
log.debug("No change for item: {}", itemData);
continue;
}
PutItemRequest putRequest = new PutItemRequest();
putRequest.setTableName(tableInfo.getDynamoTableName());
putRequest.setItem(itemData);
dynamoDB.putItem(putRequest);
Map<String, AttributeValue> oldKey = extractKey(itemData);
Map<String, AttributeValue> newKey = extractKey(newItemData);
if (!DynamoDbHelpers.areEqual(oldKey, newKey)) {
DeleteItemRequest deleteItemRequest = new DeleteItemRequest();
deleteItemRequest.setTableName(tableInfo.getDynamoTableName());
deleteItemRequest.setKey(oldKey);
dynamoDB.deleteItem(deleteItemRequest);
}
}
return items;
}