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


Java UpdateItemResult类代码示例

本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.UpdateItemResult的典型用法代码示例。如果您正苦于以下问题:Java UpdateItemResult类的具体用法?Java UpdateItemResult怎么用?Java UpdateItemResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UpdateItemResult类属于com.amazonaws.services.dynamodbv2.model包,在下文中一共展示了UpdateItemResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateItem

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例2: call

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的package包/类
@Override
public Void call() throws BackendException {

    final UpdateItem updateBackoff = new UpdateItem(updateItemRequest, dynamoDbDelegate);
    final UpdateItemResult result = updateBackoff.runWithBackoff();


    final Map<String, AttributeValue> item = result.getAttributes();

    if (item == null) {
        // bail
        return null;
    }

    // If the record has no Titan columns left after deletions occur, then just delete the record
    if (item.containsKey(Constants.JANUSGRAPH_HASH_KEY) && item.size() == ATTRIBUTES_IN_EMPTY_SINGLE_ITEM) {
        final DeleteItem deleteBackoff = new DeleteItem(new DeleteItemRequest().withTableName(updateItemRequest.getTableName())
                                                                         .withKey(updateItemRequest.getKey()), dynamoDbDelegate);
        deleteBackoff.runWithBackoff();
    }

    // void
    return null;
}
 
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:25,代码来源:SingleUpdateWithCleanupWorker.java

示例3: sendUpdateRequest

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例4: test_updateItem_WithAllParameters

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的package包/类
@Test
public void test_updateItem_WithAllParameters() throws Exception {
  createTable();
  putItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);

  String UPDATE_ATTRIBUTE_VALUE = "UpdateAttributeValue1";

  Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
  key.put(TEST_ATTRIBUTE, new AttributeValue()
    .withS(TEST_ATTRIBUTE_VALUE));
  Map<String, AttributeValueUpdate> attributeUpdates = new HashMap<String, AttributeValueUpdate>();
  attributeUpdates.put(TEST_ATTRIBUTE, new AttributeValueUpdate()
    .withAction(AttributeAction.PUT)
    .withValue(new AttributeValue()
      .withS(UPDATE_ATTRIBUTE_VALUE)));
  String returnValues = "";

  UpdateItemResult result = dynamoDb.updateItem(TEST_TABLE_NAME, key, attributeUpdates, returnValues);
  Double units = result.getConsumedCapacity().getCapacityUnits();

  GetItemResult getItemResult = getItem(TEST_ATTRIBUTE, UPDATE_ATTRIBUTE_VALUE);
  String updatedValue = getItemResult.getItem().get(TEST_ATTRIBUTE).getS();

  assertThat(units.doubleValue(), equalTo(1.0));
  assertThat(updatedValue, equalTo(UPDATE_ATTRIBUTE_VALUE));
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:27,代码来源:AmazonDynamoDBStubTest.java

示例5: updateEntityByUniqueId

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的package包/类
/**
 * Move or rename entity to other folder
 * 
 * @param entity
 * 				- current entity want to move or rename
 * @param newParent
 * 				- parent of entity
 * @param newEntityName
 * 				- new name of entity
 * @param isRenamingAction
 * 				- TRUE is renaming file, otherwise FALSE
 * @return TRUE/FALSE
 */
@Override
public boolean updateEntityByUniqueId(String tableName, Entity entity, Folder newParent, 
        String newEntityName, boolean isRenamingAction) {
	HashMap<String, AttributeValue> primaryKey = new HashMap<String, AttributeValue>();
       primaryKey.put(AttributeKey.UUID, new AttributeValue().withS(entity.getId().toString()));
       
       Map<String, AttributeValueUpdate> updateItems = new HashMap<String, AttributeValueUpdate>();
       updateItems.put(AttributeKey.ENTITY_NAME, new AttributeValueUpdate()
       	.withAction(AttributeAction.PUT).withValue(new AttributeValue().withS(newEntityName)));
       updateItems.put(AttributeKey.MODIFIED_DATE, new AttributeValueUpdate()
   		.withAction(AttributeAction.PUT).withValue(new AttributeValue().withS(DateUtils.dateToString(new Date()))));
       
       if (!isRenamingAction) {
       	updateItems.put(AttributeKey.PARENT_UUID, new AttributeValueUpdate()
   			.withAction(AttributeAction.PUT).withValue(new AttributeValue()
   			.withS(newParent.getId().toString())));
       }
       
       UpdateItemResult updateStatus = dynamoDBService.updateItem(tableName, primaryKey, updateItems);
       if (updateStatus != null) {
           return true;
       }
       
	return false;
}
 
开发者ID:dgks0n,项目名称:milton-aws,代码行数:39,代码来源:DynamoDBManagerImpl.java

示例6: updatePoint

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例7: updateItem

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的package包/类
public CompletableFuture<UpdateItemResult> updateItem(final String tableName, final Map<String, AttributeValue> key,
        final Map<String, AttributeValueUpdate> attributeUpdates) {
    return asyncExecutor.execute(new Callable<UpdateItemResult>() {
        @Override
        public UpdateItemResult call() throws Exception {
            return dbExecutor.updateItem(tableName, key, attributeUpdates);
        }
    });
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:10,代码来源:AsyncDynamoDBExecutor.java

示例8: execute

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例9: handleRequest

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例10: updateItem

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例11: updateAddNewAttribute

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例12: updateMultipleAttributes

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例13: updateExistingAttributeConditionally

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例14: put

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的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

示例15: updateItem

import com.amazonaws.services.dynamodbv2.model.UpdateItemResult; //导入依赖的package包/类
public UpdateItemResult updateItem(final String tableName, final Map<String, AttributeValue> key,
        final Map<String, AttributeValueUpdate> attributeUpdates) {
    return dynamoDB.updateItem(tableName, key, attributeUpdates);
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:5,代码来源:DynamoDBExecutor.java


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