/** * Saves the object given into DynamoDB with the condition that the hash * and if applicable, the range key, does not already exist. * @param object The object to create. * @throws ConditionalCheckFailedException If the object exists. * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper#save * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression * @see com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue */ public void saveIfNotExists(T object) throws ConditionalCheckFailedException { final DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression(); for (final DynamoDBMapperFieldModel<T,Object> key : model.keys()) { saveExpression.withExpectedEntry(key.name(), new ExpectedAttributeValue() .withExists(false)); } mapper.<T>save(object, saveExpression); }
/** * Sets the logical operator on the expected value conditions of this save * operation and returns a pointer to this object for method-chaining. */ public DynamoDBSaveExpression withConditionalOperator(String conditionalOperator) { setConditionalOperator(conditionalOperator); return this; }
/** * Sets the expected condition to the map of attribute names to expected * attribute values given and returns a pointer to this object for * method-chaining. * * @param expectedAttributes * The map of attribute names to expected attribute value * conditions to check on save */ public DynamoDBSaveExpression withExpected(Map<String, ExpectedAttributeValue> expectedAttributes) { setExpected(expectedAttributes); return this; }
.getExpected(); userProvidedConditionOperator = saveExpression .getConditionalOperator(); } else { userProvidedExpectedValueConditions = null;
DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression(); Map<String, ExpectedAttributeValue> expectedAttributes = ImmutableMap.<String, ExpectedAttributeValue>builder() .put("hashKey", new ExpectedAttributeValue(false)) .put("rangeKey", new ExpectedAttributeValue(false)) .build(); saveExpression.setExpected(expectedAttributes); saveExpression.setConditionalOperator(ConditionalOperator.AND); try { dynamoDBMapper.save(objectToSave, saveExpression); } catch (ConditionalCheckFailedException e) { //Handle conditional check }
DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression(); Map<String, ExpectedAttributeValue> expectedAttributes = ImmutableMap.<String, ExpectedAttributeValue>builder() .put(THREAD_ID, new ExpectedAttributeValue().withExists(false)) //The threadId doesn't exist or is empty .build(); saveExpression.setExpected(expectedAttributes);
/** * Sets the logical operator on the expected value conditions of this save * operation and returns a pointer to this object for method-chaining. */ public DynamoDBSaveExpression withConditionalOperator(ConditionalOperator conditionalOperator) { return withConditionalOperator(conditionalOperator.toString()); } }
try { DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression(); Map expected = new HashMap(); expected.put("status", new ExpectedAttributeValue(new AttributeValue("READY").withExists(true)); saveExpression.setExpected(expected); mapper.save(obj, saveExpression); } catch (ConditionalCheckFailedException e) { // This means our save wasn't recorded, since our constraint wasn't met // If this happens, the worker can simply look for a new task to work on }
.getExpected(); userProvidedConditionOperator = saveExpression .getConditionalOperator(); } else { userProvidedExpectedValueConditions = null;
/** * Sets the logical operator on the expected value conditions of this save * operation and returns a pointer to this object for method-chaining. */ public DynamoDBSaveExpression withConditionalOperator(ConditionalOperator conditionalOperator) { return withConditionalOperator(conditionalOperator.toString()); } }
private Environment updateEnvironmentToValid(@NonNull final Environment environment) throws InternalServiceException { environment.setValidEnvironment(true); try { // update succeeds if environment revision was created in this call return updateEnvironment( environment, new DynamoDBSaveExpression() .withExpectedEntry( LATEST_ENVIRONMENT_REVISION_ID, new ExpectedAttributeValue( new AttributeValue(environment.getLatestEnvironmentRevisionId())))); } catch (final ResourceNotFoundException e) { throw new InternalServiceException( String.format( "Trying to update the environment %s to valid but the environment does not exist", environment.getEnvironmentId()), e); } }
DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression(); Map expected = new HashMap(); expected.put("Status", new ExpectedAttributeValue(new AttributeValue(status)).withComparisonOperator(ComparisonOperator.NE)); saveExpression.setExpected(expected); dynamoDBMapper.save(obj, saveExpression);
/** * Sets the logical operator on the expected value conditions of this save * operation. */ public void setConditionalOperator(ConditionalOperator conditionalOperator) { setConditionalOperator(conditionalOperator.toString()); }
/** * Sets the expected condition to the map of attribute names to expected * attribute values given and returns a pointer to this object for * method-chaining. * * @param expectedAttributes * The map of attribute names to expected attribute value * conditions to check on save */ public DynamoDBSaveExpression withExpected(Map<String, ExpectedAttributeValue> expectedAttributes) { setExpected(expectedAttributes); return this; }
/** * Saves the object given into DynamoDB with the condition that the hash * and, if applicable, the range key, already exist. * @param object The object to update. * @throws ConditionalCheckFailedException If the object does not exist. * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper#save * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression * @see com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue */ public void saveIfExists(T object) throws ConditionalCheckFailedException { final DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression(); for (final DynamoDBMapperFieldModel<T,Object> key : model.keys()) { saveExpression.withExpectedEntry(key.name(), new ExpectedAttributeValue() .withExists(true).withValue(key.convert(key.get(object)))); } mapper.<T>save(object, saveExpression); }
/** * Sets the logical operator on the expected value conditions of this save * operation and returns a pointer to this object for method-chaining. */ public DynamoDBSaveExpression withConditionalOperator(String conditionalOperator) { setConditionalOperator(conditionalOperator); return this; }
/** * Saves the object given into DynamoDB with the condition that the hash * and if applicable, the range key, does not already exist. * @param object The object to create. * @throws ConditionalCheckFailedException If the object exists. * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper#save * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression * @see com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue */ public void saveIfNotExists(T object) throws ConditionalCheckFailedException { final DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression(); for (final DynamoDBMapperFieldModel<T,Object> key : model.keys()) { saveExpression.withExpectedEntry(key.name(), new ExpectedAttributeValue() .withExists(false)); } mapper.<T>save(object, saveExpression); }
/** * Sets the logical operator on the expected value conditions of this save * operation. */ public void setConditionalOperator(ConditionalOperator conditionalOperator) { setConditionalOperator(conditionalOperator.toString()); }
/** * Saves the object given into DynamoDB with the condition that the hash * and, if applicable, the range key, already exist. * @param object The object to update. * @throws ConditionalCheckFailedException If the object does not exist. * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper#save * @see com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression * @see com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue */ public void saveIfExists(T object) throws ConditionalCheckFailedException { final DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression(); for (final DynamoDBMapperFieldModel<T,Object> key : model.keys()) { saveExpression.withExpectedEntry(key.name(), new ExpectedAttributeValue() .withExists(true).withValue(key.convert(key.get(object)))); } mapper.<T>save(object, saveExpression); }