本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.ReturnValue类的典型用法代码示例。如果您正苦于以下问题:Java ReturnValue类的具体用法?Java ReturnValue怎么用?Java ReturnValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReturnValue类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了ReturnValue类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: sendUpdateRequest
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
/**
* Sends an update request to the service and returns true if the request is successful.
*/
public boolean sendUpdateRequest(Map<String, AttributeValue> primaryKey, Map<String, AttributeValueUpdate> updateItems,
Map<String, ExpectedAttributeValue> expectedItems) throws Exception {
if (updateItems.isEmpty()) {
return false; // No update, return false
}
UpdateItemRequest updateItemRequest = new UpdateItemRequest().withTableName(tableName).withKey(primaryKey).withReturnValues(ReturnValue.UPDATED_NEW)
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withAttributeUpdates(updateItems);
if (expectedItems != null) {
updateItemRequest.withExpected(expectedItems);
}
UpdateItemResult result = dynamoDBClient.updateItem(updateItemRequest);
if(!isRunningOnDDBLocal) {
// DDB Local does not support rate limiting
tableWriteRateLimiter.adjustRateWithConsumedCapacity(result.getConsumedCapacity());
}
return true;
}
开发者ID:awslabs,项目名称:dynamodb-online-index-violation-detector,代码行数:22,代码来源:TableWriter.java
示例2: deleteItem
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
private static void deleteItem() {
Table table = dynamoDB.getTable(tableName);
try {
DeleteItemSpec deleteItemSpec = new DeleteItemSpec()
.withPrimaryKey("Id", 120)
.withConditionExpression("#ip = :val")
.withNameMap(new NameMap()
.with("#ip", "InPublication"))
.withValueMap(new ValueMap()
.withBoolean(":val", false))
.withReturnValues(ReturnValue.ALL_OLD);
DeleteItemOutcome outcome = table.deleteItem(deleteItemSpec);
// Check the response.
System.out.println("Printing item that was deleted...");
System.out.println(outcome.getItem().toJSONPretty());
} catch (Exception e) {
System.err.println("Error deleting item in " + tableName);
System.err.println(e.getMessage());
}
}
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:27,代码来源:DocumentAPIItemCRUDExample.java
示例3: putItem
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
@Override
public T putItem(T item) {
PutItemSpec req = new PutItemSpec()
.withItem(_encryption.encrypt(toItem(item)))
.withReturnValues(ReturnValue.ALL_OLD);
return fromItem(
_encryption.decrypt(
maybeBackoff(false, () -> _putItem.putItem(req)).getItem()),
_clazz);
}
开发者ID:Distelli,项目名称:java-persistence,代码行数:11,代码来源:DdbIndex.java
示例4: createMutationWorkers
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
@Override
public Collection<MutateWorker> createMutationWorkers(final Map<StaticBuffer, KCVMutation> mutationMap, final DynamoDbStoreTransaction txh) {
final List<MutateWorker> workers = Lists.newLinkedList();
for (Map.Entry<StaticBuffer, KCVMutation> entry : mutationMap.entrySet()) {
final StaticBuffer hashKey = entry.getKey();
final KCVMutation mutation = entry.getValue();
final Map<String, AttributeValue> key = new ItemBuilder().hashKey(hashKey)
.build();
// Using ExpectedAttributeValue map to handle large mutations in a single request
// Large mutations would require multiple requests using expressions
final Map<String, ExpectedAttributeValue> expected =
new SingleExpectedAttributeValueBuilder(this, txh, hashKey).build(mutation);
final Map<String, AttributeValueUpdate> attributeValueUpdates =
new SingleUpdateBuilder().deletions(mutation.getDeletions())
.additions(mutation.getAdditions())
.build();
final UpdateItemRequest request = super.createUpdateItemRequest()
.withKey(key)
.withReturnValues(ReturnValue.ALL_NEW)
.withAttributeUpdates(attributeValueUpdates)
.withExpected(expected);
final MutateWorker worker;
if (mutation.hasDeletions() && !mutation.hasAdditions()) {
worker = new SingleUpdateWithCleanupWorker(request, client.getDelegate());
} else {
worker = new UpdateItemWorker(request, client.getDelegate());
}
workers.add(worker);
}
return workers;
}
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:39,代码来源:DynamoDbSingleRowStore.java
示例5: updateItem
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
@Override
public UpdateItemResult updateItem(String tableName, HashMap<String, AttributeValue> primaryKey, Map<String,
AttributeValueUpdate> updateItems) {
Map<String, AttributeValueUpdate> attributeValueUpdates = new HashMap<String, AttributeValueUpdate>();
attributeValueUpdates.putAll(updateItems);
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
.withTableName(tableName)
.withKey(primaryKey).withReturnValues(ReturnValue.UPDATED_NEW)
.withAttributeUpdates(updateItems);
UpdateItemResult updateItemResult = dynamoDBClient.updateItem(updateItemRequest);
LOG.info("Successful by updating item from " + tableName + ": " + updateItemResult);
return updateItemResult;
}
开发者ID:dgks0n,项目名称:milton-aws,代码行数:16,代码来源:DynamoDBServiceImpl.java
示例6: updateAddNewAttribute
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
private static void updateAddNewAttribute() {
try {
HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("Id", new AttributeValue().withN("121"));
Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":val1", new AttributeValue().withS("Some value"));
ReturnValue returnValues = ReturnValue.ALL_NEW;
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
.withTableName(tableName)
.withKey(key)
.withUpdateExpression("set NewAttribute = :val1")
.withExpressionAttributeValues(expressionAttributeValues)
.withReturnValues(returnValues);
UpdateItemResult result = client.updateItem(updateItemRequest);
// Check the response.
System.out.println("Printing item after adding new attribute...");
printItem(result.getAttributes());
} catch (AmazonServiceException ase) {
System.err.println("Failed to add new attribute in " + tableName);
System.err.println(ase.getMessage());
}
}
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:30,代码来源:LowLevelItemCRUDExample.java
示例7: updateMultipleAttributes
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
private static void updateMultipleAttributes() {
try {
HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("Id", new AttributeValue().withN("120"));
Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":val1", new AttributeValue().withSS("Author YY", "Author ZZ"));
expressionAttributeValues.put(":val2", new AttributeValue().withS("someValue"));
ReturnValue returnValues = ReturnValue.ALL_NEW;
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
.withTableName(tableName)
.withKey(key)
.withUpdateExpression("add Authors :val1 set NewAttribute=:val2")
.withExpressionAttributeValues(expressionAttributeValues)
.withReturnValues(returnValues);
UpdateItemResult result = client.updateItem(updateItemRequest);
// Check the response.
System.out.println("Printing item after multiple attribute update...");
printItem(result.getAttributes());
} catch (AmazonServiceException ase) {
System.err.println("Failed to update multiple attributes in " + tableName);
System.out.println(ase.getMessage()); //DELETEME
System.err.println("Failed to update multiple attributes in " + tableName); //DELETEME
}
}
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:32,代码来源:LowLevelItemCRUDExample.java
示例8: updateExistingAttributeConditionally
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
private static void updateExistingAttributeConditionally() {
try {
HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("Id", new AttributeValue().withN("120"));
// Specify the desired price (25.00) and also the condition (price = 20.00)
Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":val1", new AttributeValue().withN("25.00"));
expressionAttributeValues.put(":val2", new AttributeValue().withN("20.00"));
ReturnValue returnValues = ReturnValue.ALL_NEW;
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
.withTableName(tableName)
.withKey(key)
.withUpdateExpression("set Price = :val1")
.withConditionExpression("Price = :val2")
.withExpressionAttributeValues(expressionAttributeValues)
.withReturnValues(returnValues);
UpdateItemResult result = client.updateItem(updateItemRequest);
// Check the response.
System.out.println("Printing item after conditional update to new attribute...");
printItem(result.getAttributes());
} catch (ConditionalCheckFailedException cse) {
// Reload object and retry code.
System.err.println("Conditional check failed in " + tableName);
} catch (AmazonServiceException ase) {
System.err.println("Error updating item in " + tableName);
}
}
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:36,代码来源:LowLevelItemCRUDExample.java
示例9: deleteItem
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
private static void deleteItem() {
try {
HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("Id", new AttributeValue().withN("120"));
Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":val", new AttributeValue().withBOOL(false));
ReturnValue returnValues = ReturnValue.ALL_OLD;
DeleteItemRequest deleteItemRequest = new DeleteItemRequest()
.withTableName(tableName)
.withKey(key)
.withConditionExpression("InPublication = :val")
.withExpressionAttributeValues(expressionAttributeValues)
.withReturnValues(returnValues);
DeleteItemResult result = client.deleteItem(deleteItemRequest);
// Check the response.
System.out.println("Printing item that was deleted...");
printItem(result.getAttributes());
} catch (AmazonServiceException ase) {
System.err.println("Failed to get item after deletion " + tableName);
}
}
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:31,代码来源:LowLevelItemCRUDExample.java
示例10: updateAddNewAttribute
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
private static void updateAddNewAttribute() {
Table table = dynamoDB.getTable(tableName);
try {
Map<String, String> expressionAttributeNames = new HashMap<String, String>();
expressionAttributeNames.put("#na", "NewAttribute");
UpdateItemSpec updateItemSpec = new UpdateItemSpec()
.withPrimaryKey("Id", 121)
.withUpdateExpression("set #na = :val1")
.withNameMap(new NameMap()
.with("#na", "NewAttribute"))
.withValueMap(new ValueMap()
.withString(":val1", "Some value"))
.withReturnValues(ReturnValue.ALL_NEW);
UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
// Check the response.
System.out.println("Printing item after adding new attribute...");
System.out.println(outcome.getItem().toJSONPretty());
} catch (Exception e) {
System.err.println("Failed to add new attribute in " + tableName);
System.err.println(e.getMessage());
}
}
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:29,代码来源:DocumentAPIItemCRUDExample.java
示例11: updateMultipleAttributes
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
private static void updateMultipleAttributes() {
Table table = dynamoDB.getTable(tableName);
try {
UpdateItemSpec updateItemSpec = new UpdateItemSpec()
.withPrimaryKey("Id", 120)
.withUpdateExpression("add #a :val1 set #na=:val2")
.withNameMap(new NameMap()
.with("#a", "Authors")
.with("#na", "NewAttribute"))
.withValueMap(new ValueMap()
.withStringSet(":val1", "Author YY", "Author ZZ")
.withString(":val2", "someValue"))
.withReturnValues(ReturnValue.ALL_NEW);
UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
// Check the response.
System.out
.println("Printing item after multiple attribute update...");
System.out.println(outcome.getItem().toJSONPretty());
} catch (Exception e) {
System.err.println("Failed to update multiple attributes in "
+ tableName);
System.err.println(e.getMessage());
}
}
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:32,代码来源:DocumentAPIItemCRUDExample.java
示例12: updateExistingAttributeConditionally
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
private static void updateExistingAttributeConditionally() {
Table table = dynamoDB.getTable(tableName);
try {
// Specify the desired price (25.00) and also the condition (price =
// 20.00)
UpdateItemSpec updateItemSpec = new UpdateItemSpec()
.withPrimaryKey("Id", 120)
.withReturnValues(ReturnValue.ALL_NEW)
.withUpdateExpression("set #p = :val1")
.withConditionExpression("#p = :val2")
.withNameMap(new NameMap()
.with("#p", "Price"))
.withValueMap(new ValueMap()
.withNumber(":val1", 25)
.withNumber(":val2", 20));
UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
// Check the response.
System.out
.println("Printing item after conditional update to new attribute...");
System.out.println(outcome.getItem().toJSONPretty());
} catch (Exception e) {
System.err.println("Error updating item in " + tableName);
System.err.println(e.getMessage());
}
}
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:33,代码来源:DocumentAPIItemCRUDExample.java
示例13: put
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
@Override
public Map<String, AttributeValue> put(
final Map<String, AttributeValueUpdate> attrs) throws IOException {
final AmazonDynamoDB aws = this.credentials.aws();
final Attributes expected = this.attributes.only(this.keys);
try {
final UpdateItemRequest request = new UpdateItemRequest()
.withTableName(this.name)
.withExpected(expected.asKeys())
.withKey(expected)
.withAttributeUpdates(attrs)
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL)
.withReturnValues(ReturnValue.UPDATED_NEW);
final long start = System.currentTimeMillis();
final UpdateItemResult result = aws.updateItem(request);
Logger.info(
this, "#put('%s'): updated item to DynamoDB, %s, in %[ms]s",
attrs,
new PrintableConsumedCapacity(
result.getConsumedCapacity()
).print(),
System.currentTimeMillis() - start
);
return result.getAttributes();
} catch (final AmazonClientException ex) {
throw new IOException(
String.format(
"failed to put %s into \"%s\" with %s",
attrs, this.name, this.keys
),
ex
);
} finally {
aws.shutdown();
}
}
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:37,代码来源:AwsItem.java
示例14: put
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的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();
}
}
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:40,代码来源:AwsTable.java
示例15: delete
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的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();
}
}
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:34,代码来源:AwsTable.java
示例16: returnAllNew
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
@Override
public UpdateItemBuilder<T> returnAllNew() {
_spec.withReturnValues(ReturnValue.ALL_NEW);
return this;
}
开发者ID:Distelli,项目名称:java-persistence,代码行数:6,代码来源:UpdateItemBuilderImpl.java
示例17: returnUpdatedNew
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
@Override
public UpdateItemBuilder<T> returnUpdatedNew() {
_spec.withReturnValues(ReturnValue.UPDATED_NEW);
return this;
}
开发者ID:Distelli,项目名称:java-persistence,代码行数:6,代码来源:UpdateItemBuilderImpl.java
示例18: updateConditionalValue
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
public UpdateItemResult updateConditionalValue(final AmazonDynamoDB dynamoClient,
final String tableName, final UpdateKey key, final String attribute,
final AggregateAttributeModification update) throws Exception {
Map<String, AttributeValue> updateKey = StreamAggregatorUtils.getTableKey(key);
UpdateItemResult result;
final ReturnValue returnValue = ReturnValue.UPDATED_NEW;
final String setAttribute = StreamAggregatorUtils.methodToColumn(attribute);
// create the update that we want to write
final Map<String, AttributeValueUpdate> thisCalcUpdate = new HashMap<String, AttributeValueUpdate>() {
{
put(setAttribute,
new AttributeValueUpdate().withAction(AttributeAction.PUT).withValue(
new AttributeValue().withN("" + update.getFinalValue())));
}
};
// create the request
UpdateItemRequest req = new UpdateItemRequest().withTableName(tableName).withKey(updateKey).withReturnValues(
returnValue).withAttributeUpdates(thisCalcUpdate);
Map<String, ExpectedAttributeValue> expected = new HashMap<>();
final SummaryCalculation calc = update.getCalculationApplied();
// try an update to PUT the value if NOT EXISTS, to establish if we
// are the first writer for this key
expected = new HashMap<String, ExpectedAttributeValue>() {
{
put(setAttribute, new ExpectedAttributeValue().withExists(false));
}
};
req.setExpected(expected);
try {
result = DynamoUtils.updateWithRetries(dynamoClient, req);
// yay - we were the first writer, so our value was written
return result;
} catch (ConditionalCheckFailedException e1) {
// set the expected to the comparison contained in the update
// calculation
expected.clear();
expected.put(
setAttribute,
new ExpectedAttributeValue().withComparisonOperator(
calc.getDynamoComparisonOperator()).withValue(
new AttributeValue().withN("" + update.getFinalValue())));
req.setExpected(expected);
// do the conditional update on the summary
// calculation. this may result in no update being
// applied because the new value is greater than the
// current minimum for MIN, or less than the current
// maximum for MAX.
try {
result = DynamoUtils.updateWithRetries(dynamoClient, req);
return result;
} catch (ConditionalCheckFailedException e2) {
// no worries - we just weren't the min or max!
return null;
}
}
}
开发者ID:awslabs,项目名称:amazon-kinesis-aggregators,代码行数:66,代码来源:DynamoDataStore.java
示例19: update
import com.amazonaws.services.dynamodbv2.model.ReturnValue; //导入依赖的package包/类
/**
* Update an existing memo in the database
* @param memo the memo to save
*/
public void update(Document memo) {
Document document = dbTable.updateItem(memo, new UpdateItemOperationConfig().withReturnValues(ReturnValue.ALL_NEW));
}
开发者ID:awslabs,项目名称:aws-sdk-android-samples,代码行数:8,代码来源:DatabaseAccess.java
注:本文中的com.amazonaws.services.dynamodbv2.model.ReturnValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论