Examples of UpdateItemResult


Examples of com.amazonaws.services.dynamodb.model.UpdateItemResult

    }

    @Override
    public UpdateItemResult updateItem(UpdateItemRequest updateItemRequest) {
        this.updateItemRequest = updateItemRequest;
        return new UpdateItemResult().withAttributes(getAttributes());
    }
View Full Code Here

Examples of com.amazonaws.services.dynamodb.model.UpdateItemResult

        super(ddbClient, configuration, exchange);
    }

    @Override
    public void execute() {
        UpdateItemResult result = ddbClient.updateItem(new UpdateItemRequest()
                .withTableName(determineTableName())
                .withKey(determineKey())
                .withAttributeUpdates(determineUpdateValues())
                .withExpected(determineUpdateCondition())
                .withReturnValues(determineReturnValues()));

        addAttributesToResult(result.getAttributes());
    }
View Full Code Here

Examples of com.amazonaws.services.dynamodb.model.UpdateItemResult

    Map<String, ExpectedAttributeValue> expected = request.getExpected();
    Map<String, AttributeValueUpdate> attributesToUpdate = request.getAttributeUpdates();
    String returnValues = request.getReturnValues();


    UpdateItemResult result = new UpdateItemResult();
    result.setConsumedCapacityUnits(0.5);

    // Check to make sure table exists
    if (!this.tables.containsKey(tableName)) {
      throw new ResourceNotFoundException("The table you're currently trying to access (" + tableName + ") doesn't exists.");
    }
    // Check to make sure Key is valid
        String hashKeyValue = getKeyValue(key.getHashKeyElement());
        String rangeKeyValue = getKeyValue(key.getRangeKeyElement());
        Map<String, AttributeValue> item = this.tables.get(tableName).getItem(hashKeyValue, rangeKeyValue);
      
    // Check conditional put
        validateExpected(request.getExpected(), item);
       
    if (item == null) {
      item = new HashMap<String, AttributeValue>();
      item.put(this.tables.get(tableName).getHashKeyName(), key.getHashKeyElement());
      if (key.getRangeKeyElement() != null) {
        item.put(this.tables.get(tableName).getRangeKeyName(), key.getRangeKeyElement());
      }
      for (String sKey : attributesToUpdate.keySet()) {
        if (attributesToUpdate.get(sKey).getValue() != null) {
          item.put(sKey, attributesToUpdate.get(sKey).getValue());
        }
      }
      this.tables.get(tableName).putItem(item);
      result.setAttributes(item);
    } else {
      Set<String> sKeyz = new HashSet<String>(item.keySet());
      sKeyz.addAll(attributesToUpdate.keySet());
      for (String sKey : sKeyz) {
        if (attributesToUpdate.containsKey(sKey)) {
          if (attributesToUpdate.get(sKey).getAction().equalsIgnoreCase(AttributeAction.PUT.name())) {
            item.remove(sKey);
            item.put(sKey, attributesToUpdate.get(sKey).getValue());
            attributesToUpdate.remove(sKey);
          } else if (attributesToUpdate.get(sKey).getAction().equalsIgnoreCase(AttributeAction.DELETE.name())) {
            if (attributesToUpdate.get(sKey).getValue() != null) {
              deleteAttributeValue(item, sKey, attributesToUpdate.get(sKey));
            } else {
              item.remove(sKey);
            }
            attributesToUpdate.remove(sKey);
          } else if (attributesToUpdate.get(sKey).getAction().equalsIgnoreCase(AttributeAction.ADD.name())) {
            if (attributesToUpdate.get(sKey).getValue() != null) {
              addAttributeValue(item, sKey, attributesToUpdate.get(sKey));
            } else {
              throw new ResourceNotFoundException("the provided update item with attribute (" + sKey + ") doesn't have an AttributeValue to perform the ADD");
            }
          }
        }
      }
      result.setAttributes(item);
    }
    return result;
  }
View Full Code Here

Examples of com.amazonaws.services.dynamodb.model.UpdateItemResult

  public com.amazonaws.services.dynamodbv2.model.UpdateItemResult updateItemV2(com.amazonaws.services.dynamodbv2.model.UpdateItemRequest v2Request) {
        Table table = this.tables.get(v2Request.getTableName());
        UpdateItemRequest request = AlternatorDBApiVersion2Mapper.MapV2UpdateItemRequestToV1(v2Request, table);
    try {
      UpdateItemResult result = updateItem(request);
      return AlternatorDBApiVersion2Mapper.MapV1UpdateItemResultToV2(result, v2Request.getTableName());
    } catch (ConditionalCheckFailedException ccfev1) {
      throw new com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException(ccfev1.getMessage());
    }
  }
View Full Code Here

Examples of com.amazonaws.services.dynamodb.model.UpdateItemResult

        update.setAction("PUT");
        update.setValue(hash);
        attrToUp.put("updated", update);
        Key key = new Key(hash);
        UpdateItemRequest request = new UpdateItemRequest(tableName, key, attrToUp);
        UpdateItemResult res = getClient().updateItem(request);
        Assert.assertNotNull(res);
        Assert.assertNotNull(res.getAttributes());
    }
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.model.UpdateItemResult

                    }
                }

                @Override
                protected void executeLowLevelRequest() {
                    UpdateItemResult updateItemResult = doUpdateItem();

                    // The UpdateItem request is specified to return ALL_NEW
                    // attributes of the affected item. So if the returned
                    // UpdateItemResult does not include any ReturnedAttributes,
                    // it indicates the UpdateItem failed silently (e.g. the
                    // key-only-put nightmare -
                    // https://forums.aws.amazon.com/thread.jspa?threadID=86798&tstart=25),
                    // in which case we should re-send a PutItem
                    // request instead.
                    if (updateItemResult.getAttributes() == null
                            || updateItemResult.getAttributes().isEmpty()) {
                        // Before we proceed with PutItem, we need to put all
                        // the key attributes (prepared for the
                        // UpdateItemRequest) into the AttributeValueUpdates
                        // collection.
                        for (String keyAttributeName : getKeyAttributeValues().keySet()) {
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.model.UpdateItemResult

                    }
                }

                @Override
                protected void executeLowLevelRequest() {
                    UpdateItemResult updateItemResult = doUpdateItem();

                    // The UpdateItem request is specified to return ALL_NEW
                    // attributes of the affected item. So if the returned
                    // UpdateItemResult does not include any ReturnedAttributes,
                    // it indicates the UpdateItem failed silently (e.g. the
                    // key-only-put nightmare -
                    // https://forums.aws.amazon.com/thread.jspa?threadID=86798&tstart=25),
                    // in which case we should re-send a PutItem
                    // request instead.
                    if (updateItemResult.getAttributes() == null
                            || updateItemResult.getAttributes().isEmpty()) {
                        // Before we proceed with PutItem, we need to put all
                        // the key attributes (prepared for the
                        // UpdateItemRequest) into the AttributeValueUpdates
                        // collection.
                        for (String keyAttributeName : getKeyAttributeValues().keySet()) {
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.model.UpdateItemResult

    // 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;
  }
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.model.UpdateItemResult

                    }
                }

                @Override
                protected void executeLowLevelRequest() {
                    UpdateItemResult updateItemResult = doUpdateItem();

                    // The UpdateItem request is specified to return ALL_NEW
                    // attributes of the affected item. So if the returned
                    // UpdateItemResult does not include any ReturnedAttributes,
                    // it indicates the UpdateItem failed silently (e.g. the
                    // key-only-put nightmare -
                    // https://forums.aws.amazon.com/thread.jspa?threadID=86798&tstart=25),
                    // in which case we should re-send a PutItem
                    // request instead.
                    if (updateItemResult.getAttributes() == null
                            || updateItemResult.getAttributes().isEmpty()) {
                        // Before we proceed with PutItem, we need to put all
                        // the key attributes (prepared for the
                        // UpdateItemRequest) into the AttributeValueUpdates
                        // collection.
                        for (String keyAttributeName : getKeyAttributeValues().keySet()) {
View Full Code Here

Examples of com.amazonaws.services.dynamodbv2.model.UpdateItemResult

                    }
                }

                @Override
                protected void executeLowLevelRequest() {
                    UpdateItemResult updateItemResult = doUpdateItem();

                    // The UpdateItem request is specified to return ALL_NEW
                    // attributes of the affected item. So if the returned
                    // UpdateItemResult does not include any ReturnedAttributes,
                    // it indicates the UpdateItem failed silently (e.g. the
                    // key-only-put nightmare -
                    // https://forums.aws.amazon.com/thread.jspa?threadID=86798&tstart=25),
                    // in which case we should re-send a PutItem
                    // request instead.
                    if (updateItemResult.getAttributes() == null
                            || updateItemResult.getAttributes().isEmpty()) {
                        // Before we proceed with PutItem, we need to put all
                        // the key attributes (prepared for the
                        // UpdateItemRequest) into the AttributeValueUpdates
                        // collection.
                        for (String keyAttributeName : getKeyAttributeValues().keySet()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.