当前位置: 首页>>代码示例>>Java>>正文


Java UpdateItemRequest类代码示例

本文整理汇总了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);
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:20,代码来源:GenericDynamoDBTest.java

示例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);
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:23,代码来源:GenericDynamoDBTest.java

示例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;
}
 
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:26,代码来源:DynamoDbDelegate.java

示例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);
}
 
开发者ID:gnethercutt,项目名称:dynamodb-streams-kafka,代码行数:17,代码来源:StreamAdapterDemoHelper.java

示例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;
}
 
开发者ID:awslabs,项目名称:dynamodb-online-index-violation-detector,代码行数:22,代码来源:TableWriter.java

示例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);
	}
}
 
开发者ID:Erudika,项目名称:para,代码行数:17,代码来源:AWSDynamoDAO.java

示例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;
}
 
开发者ID:awslabs,项目名称:dynamodb-geo,代码行数:21,代码来源:DynamoDBManager.java

示例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);
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:10,代码来源:GenericDynamoDB.java

示例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);
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:9,代码来源:GenericDynamoDBTest.java

示例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);
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:11,代码来源:GenericDynamoDBTest.java

示例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);
        }
    });
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:9,代码来源:AsyncDynamoDBExecutor.java

示例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());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:UpdateItemCommand.java

示例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;
}
 
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:18,代码来源:DynamoDbDelegate.java

示例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;
}
 
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:39,代码来源:DynamoDbSingleRowStore.java

示例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'}";
}
 
开发者ID:markusklems,项目名称:aws-lambda-java-example,代码行数:29,代码来源:LambdaApprovalFunctionHandler.java


注:本文中的com.amazonaws.services.dynamodbv2.model.UpdateItemRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。