本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.PutItemRequest.setItem方法的典型用法代码示例。如果您正苦于以下问题:Java PutItemRequest.setItem方法的具体用法?Java PutItemRequest.setItem怎么用?Java PutItemRequest.setItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.dynamodbv2.model.PutItemRequest
的用法示例。
在下文中一共展示了PutItemRequest.setItem方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putItemResultMono
import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入方法依赖的package包/类
private Mono<Map<String, AttributeValue>> putItemResultMono(
String seedUrl,
EStatus status,
String title,
WebsiteModel websiteModel
) {
PutItemRequest putItemRequest = new PutItemRequest();
putItemRequest.setTableName(Utils.table.websites);
Map<String, AttributeValue> newWebsite = new HashMap<>();
if (Objects.nonNull(websiteModel)) newWebsite = crawlerBatchService.getNodes(websiteModel);
newWebsite.put(Utils.params.url, new AttributeValue(seedUrl));
newWebsite.put(Utils.params.status, new AttributeValue(status.name()));
if (StringUtils.isNotEmpty(title)) newWebsite.put(Utils.params.title, new AttributeValue(title));
putItemRequest.setItem(newWebsite);
return Mono.fromFuture(
Utils.makeCompletableFuture(
dynamoDBAsync.putItemAsync(putItemRequest)))
.doOnError((throwable -> LOG.error(Utils.error.failed_dynamo_put, seedUrl)))
.doOnSuccess((a) -> LOG.info(Utils.success.saved_dynamo, String.format("%s [%s]", seedUrl, status)))
.map(((result) -> putItemRequest.getItem()));
}
示例2: putItemResultMono
import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入方法依赖的package包/类
private Mono<Map<String, AttributeValue>> putItemResultMono(String url) {
PutItemRequest putItemRequest = new PutItemRequest();
putItemRequest.setTableName(Utils.table.websites);
HashMap<String, AttributeValue> newWebsite = new HashMap<>();
newWebsite.put(Utils.params.url, new AttributeValue(url));
newWebsite.put(Utils.params.status, new AttributeValue(EStatus.NEW.name()));
putItemRequest.setItem(newWebsite);
return Mono.fromFuture(
Utils.makeCompletableFuture(
dynamoDBAsync.putItemAsync(putItemRequest)))
.doOnError((throwable -> LOG.error(Utils.error.failed_dynamo_put, url)))
.flatMap((created) -> this.sendMessage(url))
.map(((result) -> putItemRequest.getItem()));
}
示例3: put
import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入方法依赖的package包/类
@Override
public Item put(final Map<String, AttributeValue> attributes)
throws IOException {
final AmazonDynamoDB aws = this.credentials.aws();
try {
final PutItemRequest request = new PutItemRequest();
request.setTableName(this.self);
request.setItem(attributes);
request.setReturnValues(ReturnValue.NONE);
request.setReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
final PutItemResult result = aws.putItem(request);
final long start = System.currentTimeMillis();
Logger.info(
this, "#put('%[text]s'): created item in '%s', %s, in %[ms]s",
attributes, this.self,
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return new AwsItem(
this.credentials,
this.frame(),
this.self,
new Attributes(attributes).only(this.keys()),
new Array<String>(this.keys())
);
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to put into \"%s\" with %s",
this.self, attributes
),
ex
);
} finally {
aws.shutdown();
}
}
示例4: insert
import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入方法依赖的package包/类
@Override
public <T extends Message> void insert(T item, Modifier... modifiers) throws DataStoreException {
DynamoClassMapping<T> tableInfo = getClassMapping(item);
log.debug("Insert {} {}", item.getClass().getSimpleName(), item);
for (Modifier modifier : modifiers) {
throw new UnsupportedOperationException();
}
PutItemRequest request = new PutItemRequest();
request.setTableName(tableInfo.getDynamoTableName());
Map<String, AttributeValue> itemData = tableInfo.mapToDb(item);
request.setItem(itemData);
Map<String, ExpectedAttributeValue> expected = Maps.newHashMap();
expected.put(FIELD_HASH_KEY, new ExpectedAttributeValue().withComparisonOperator(ComparisonOperator.NULL));
request.setExpected(expected);
if (expected.size() > 1) {
request.setConditionalOperator(ConditionalOperator.AND);
}
try {
dynamoDB.putItem(request);
} catch (ConditionalCheckFailedException e) {
log.debug("Insert failed {}", item, e);
throw new UniqueIndexViolation(null);
}
}
示例5: PutPointRequest
import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入方法依赖的package包/类
public PutPointRequest(GeoPoint geoPoint, AttributeValue rangeKeyValue) {
putItemRequest = new PutItemRequest();
putItemRequest.setItem(new HashMap<String, AttributeValue>());
putRequest = new PutRequest();
putRequest.setItem(new HashMap<String, AttributeValue>());
this.geoPoint = geoPoint;
this.rangeKeyValue = rangeKeyValue;
}
示例6: reindex
import com.amazonaws.services.dynamodbv2.model.PutItemRequest; //导入方法依赖的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;
}