java - Conditional write item if attribute not equals with DynamoDBMapper -
is possible conditional write/update using dynamodb mapper when want have condition like: write if attribute not equal x? want conditional write this:
dynamorecord record = mapper.load(dynamorecord.class, hashkey); if (record.getsomeattr() != terminationvalue) { mapper.save(newrecord); }
the attribute exists. can have multiple values , represents condition after updates record should stop.
i read this article , aws documentation , bunch of other posts seems ==
operator supported along exists check. possible !=
conditional write using mapper? if so, pointers appreciated.
thanks.
summary @notionquest's answer
- use
comparisonoperator.ne
- if attribute boolean, annotate using
@dynamodbnativeboolean
correct results while usingexpectedattributevalue(new attributevalue().withbool(true))
. see here details.
please use "withcomparisonoperator(comparisonoperator.ne)" notequals condition. refer below example.
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);
Comments
Post a Comment