Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果值不为';不存在或检查DynamoDBMapper中的状态_Java_Amazon Web Services_Amazon Dynamodb - Fatal编程技术网

Java 如果值不为';不存在或检查DynamoDBMapper中的状态

Java 如果值不为';不存在或检查DynamoDBMapper中的状态,java,amazon-web-services,amazon-dynamodb,Java,Amazon Web Services,Amazon Dynamodb,我正在研究一种保存到DynamoDB的方法。如果表中不存在该值,我希望保存该方法。如果它确实存在,我想应用一个条件更新。我正在使用DynamoDBMapper的保存方法 我目前拥有的代码成功地执行了条件保存,但如果该列在数据库中不存在,则抛出异常 有没有办法找到一个条件更新表达式来检查值是否不存在,或者检查我需要的条件 我目前拥有的Java代码如下所示: DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression(); A

我正在研究一种保存到DynamoDB的方法。如果表中不存在该值,我希望保存该方法。如果它确实存在,我想应用一个条件更新。我正在使用DynamoDBMapper的保存方法

我目前拥有的代码成功地执行了条件保存,但如果该列在数据库中不存在,则抛出异常

有没有办法找到一个条件更新表达式来检查值是否不存在,或者检查我需要的条件

我目前拥有的Java代码如下所示:

DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression();
AttributeValue attributeValue = new AttributeValue(valueToSave);
ExpectedAttributeValue expectedAttributeValue = new ExpectedAttributeValue(attributeValue).withComparisonOperator(ComparisonOperator.LT);
Map<String, ExpectedAttributeValue> expected = new HashMap<>();
expected.put("key", expectedAttributeValue);
saveExpression.setExpected(expected);
dynamoDbMapper.save(objectToSave);
DynamoDBSaveExpression saveExpression=new DynamoDBSaveExpression();
AttributeValue AttributeValue=新的AttributeValue(valueToSave);
ExpectedAttributeValue ExpectedAttributeValue=新的ExpectedAttributeValue(attributeValue)。带有ComparisonOperator(ComparisonOperator.LT);
Map expected=新的HashMap();
expected.put(“key”,expectedAttributeValue);
saveExpression.setExpected(预期);
dynamoDbMapper.save(objectToSave);

谢谢

传统应用程序()中存在预期的属性内容

建议您改用较新的ConditionExpression

这是我完成这项工作的一种方法,尽管下面的代码片段是从Scala代码转换而来的,未经测试

Map attrVals = new HashMap() {{
  put(":revision", new AttributeValue().withN(revision.toString)));   
}};

PutItemRequest request = new PutItemRequest().withTableName(myTableName)
.withItem(myItem)
.withConditionExpression(attribute_not_exists(primaryKey) OR revision <= :revision)
.withExpressionAttributeValues(attrVals);

dynamoClient.putItem(request);
Map attrVals=new HashMap(){{
put(“:revision”,新的AttributeValue().withN(revision.toString));
}};
PutItemRequest=new PutItemRequest()。withTableName(myTableName)
.withItem(myItem)
.withConditionExpression(属性不存在)(primaryKey)或revision