本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.UpdateItemRequest类的典型用法代码示例。如果您正苦于以下问题:Java UpdateItemRequest类的具体用法?Java UpdateItemRequest怎么用?Java UpdateItemRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UpdateItemRequest类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了UpdateItemRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateEntryAlreadyExists
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
@Test
public void testCreateEntryAlreadyExists() throws Exception {
RawSecretEntry rawSecretEntry = constructRawEntry(SECRET_NAME);
UpdateItemRequest expectedUpdateRequest = constructUpdateItemRequest(rawSecretEntry, false, Optional.empty());
// Already exists will cause a check failed exception.
when(mockDynamoDBClient.updateItem(expectedUpdateRequest)).thenThrow(
new ConditionalCheckFailedException(""));
boolean exceptionThrown = false;
try {
dynamoDB.create(rawSecretEntry);
} catch (AlreadyExistsException e) {
assertEquals(e.getMessage(), "DynamoDB store entry already exists:{1={S: secret1,}, 2={N: 1,}}");
exceptionThrown = true;
}
assertTrue(exceptionThrown);
verify(mockDynamoDBClient, times(1)).updateItem(expectedUpdateRequest);
}
示例2: testUpdateEntryDoesNotExist
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
@Test
public void testUpdateEntryDoesNotExist() throws Exception {
RawSecretEntry rawSecretEntry = constructRawEntry(SECRET_NAME);
RawSecretEntry alternativeRawSecretEntry = constructAlternativeRawSecretEntry(SECRET_NAME);
UpdateItemRequest expectedUpdateRequest = constructUpdateItemRequest(rawSecretEntry, true, Optional.of(alternativeRawSecretEntry));
when(mockDynamoDBClient.updateItem(expectedUpdateRequest)).thenThrow(
new ConditionalCheckFailedException(""));
boolean exceptionThrown = false;
try {
dynamoDB.update(rawSecretEntry, alternativeRawSecretEntry);
} catch (DoesNotExistException e) {
assertEquals(e.getMessage(), "Precondition to update entry in DynamoDB failed:{1={S: secret1,}, 2={N: 1,}}");
exceptionThrown = true;
}
assertTrue(exceptionThrown);
// Check all the expected calls to AWS were made.
verify(mockDynamoDBClient, times(1)).updateItem(expectedUpdateRequest);
}
示例3: updateItem
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
UpdateItemResult updateItem(final UpdateItemRequest request) throws BackendException {
setUserAgent(request);
UpdateItemResult result;
final int bytes;
if (request.getUpdateExpression() != null) {
bytes = calculateExpressionBasedUpdateSize(request);
} else {
bytes = calculateItemUpdateSizeInBytes(request.getAttributeUpdates());
}
getBytesHistogram(UPDATE_ITEM, request.getTableName()).update(bytes);
final int wcu = computeWcu(bytes);
timedWriteThrottle(UPDATE_ITEM, request.getTableName(), wcu);
final Timer.Context apiTimerContext = getTimerContext(UPDATE_ITEM, request.getTableName());
try {
result = client.updateItem(request);
} catch (Exception e) {
throw processDynamoDbApiException(e, UPDATE_ITEM, request.getTableName());
} finally {
apiTimerContext.stop();
}
meterConsumedCapacity(UPDATE_ITEM, result.getConsumedCapacity());
return result;
}
示例4: updateItem
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
public static void updateItem(AmazonDynamoDBClient client, String tableName, String id, String val) {
java.util.Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
key.put("Id", new AttributeValue().withN(id));
Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<String, AttributeValueUpdate>();
AttributeValueUpdate update = new AttributeValueUpdate()
.withAction(AttributeAction.PUT)
.withValue(new AttributeValue().withS(val));
attributeUpdates.put("attribute-2", update);
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
.withTableName(tableName)
.withKey(key)
.withAttributeUpdates(attributeUpdates);
client.updateItem(updateItemRequest);
}
示例5: sendUpdateRequest
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的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;
}
示例6: updateRow
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
private void updateRow(String key, String appid, Map<String, AttributeValue> row) {
if (StringUtils.isBlank(key) || StringUtils.isBlank(appid) || row == null || row.isEmpty()) {
return;
}
Map<String, AttributeValueUpdate> rou = new HashMap<>();
try {
for (Entry<String, AttributeValue> attr : row.entrySet()) {
rou.put(attr.getKey(), new AttributeValueUpdate(attr.getValue(), AttributeAction.PUT));
}
UpdateItemRequest updateItemRequest = new UpdateItemRequest(getTableNameForAppid(appid),
Collections.singletonMap(Config._KEY, new AttributeValue(getKeyForAppid(key, appid))), rou);
client().updateItem(updateItemRequest);
} catch (Exception e) {
logger.error("Could not update row in DB - appid={}, key={}", appid, key, e);
}
}
示例7: 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;
}
示例8: executeUpdate
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
private void executeUpdate(Map<String, AttributeValue> keys, Map<String, AttributeValueUpdate> attributes, Map<String, ExpectedAttributeValue> expected) {
UpdateItemRequest updateEntry = new UpdateItemRequest()
.withTableName(tableName)
.withKey(keys)
.withAttributeUpdates(attributes)
.withExpected(expected);
client.updateItem(updateEntry);
}
示例9: testCreateEntry
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
@Test
public void testCreateEntry() throws Exception {
RawSecretEntry rawSecretEntry = constructRawEntry(SECRET_NAME);
UpdateItemRequest expectedUpdateRequest = constructUpdateItemRequest(rawSecretEntry, false, Optional.empty());
dynamoDB.create(rawSecretEntry);
verify(mockDynamoDBClient, times(1)).updateItem(expectedUpdateRequest);
}
示例10: testUpdateEntry
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
@Test
public void testUpdateEntry() throws Exception {
RawSecretEntry rawSecretEntry = constructRawEntry(SECRET_NAME);
RawSecretEntry alternativeRawSecretEntry = constructAlternativeRawSecretEntry(SECRET_NAME);
UpdateItemRequest expectedUpdateRequest = constructUpdateItemRequest(rawSecretEntry, true, Optional.of(alternativeRawSecretEntry));
dynamoDB.update(rawSecretEntry, alternativeRawSecretEntry);
verify(mockDynamoDBClient, times(1)).updateItem(expectedUpdateRequest);
}
示例11: updateItem
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
public CompletableFuture<UpdateItemResult> updateItem(final UpdateItemRequest updateItemRequest) {
return asyncExecutor.execute(new Callable<UpdateItemResult>() {
@Override
public UpdateItemResult call() throws Exception {
return dbExecutor.updateItem(updateItemRequest);
}
});
}
示例12: execute
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
@Override
public void execute() {
UpdateItemResult result = ddbClient.updateItem(new UpdateItemRequest()
.withTableName(determineTableName())
.withKey(determineKey())
.withAttributeUpdates(determineUpdateValues())
.withExpected(determineUpdateCondition())
.withReturnValues(determineReturnValues()));
addAttributesToResult(result.getAttributes());
}
示例13: calculateExpressionBasedUpdateSize
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
/**
* This method calculates a lower bound of the size of a new item created with UpdateItem UpdateExpression. It does not
* account for the size of the attribute names of the document paths in the attribute names map and it assumes that the
* UpdateExpression only uses the SET action to assign to top-level attributes.
* @param request UpdateItem request that uses update expressions
* @return the size of the post-update image of the item
*/
private int calculateExpressionBasedUpdateSize(final UpdateItemRequest request) {
if (request == null || request.getUpdateExpression() == null) {
throw new IllegalArgumentException("request did not use update expression");
}
int size = calculateItemSizeInBytes(request.getKey());
for (AttributeValue value : request.getExpressionAttributeValues().values()) {
size += calculateAttributeSizeInBytes(value);
}
return size;
}
示例14: createMutationWorkers
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的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;
}
示例15: handleRequest
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; //导入依赖的package包/类
@Override
public Object handleRequest(Object input, Context context) {
context.getLogger().log("input: " + input);
if (input.toString().equals("{}") || input.toString().equals("")) {
context.getLogger().log("input is empty: abort");
return "{\"status\":\"error\",\"message\":\"input at lambda function is empty\"}";
}
dynamoDB = new AmazonDynamoDBClient().withRegion(Region
.getRegion(Regions.EU_WEST_1));
HashMap<String, String> mapInput = (HashMap<String, String>) input;
Map<String, AttributeValue> employeeKey = new HashMap<String, AttributeValue>();
String employeeId = mapInput.get("employee_id");
context.getLogger().log("employee_id: " + employeeId);
employeeKey.put("employee_id", new AttributeValue().withS(employeeId));
Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<String, AttributeValueUpdate>();
attributeUpdates.put("approval", new AttributeValueUpdate()
.withValue(new AttributeValue().withS("approved")));
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
.withKey(employeeKey).withAttributeUpdates(attributeUpdates)
.withTableName("lambda-reimbursment");
UpdateItemResult updateItemResult = dynamoDB
.updateItem(updateItemRequest);
context.getLogger().log("Result: " + updateItemResult);
return "{'status':'done'}";
}