in src/main/java/com/amazonaws/services/dynamodbv2/transactions/Transaction.java [627:661]
protected void unlockItemAfterCommit(Request request) {
try {
Map<String, ExpectedAttributeValue> expected = new HashMap<String, ExpectedAttributeValue>();
expected.put(AttributeName.TXID.toString(), new ExpectedAttributeValue().withValue(new AttributeValue(txId)));
if(request instanceof PutItem || request instanceof UpdateItem) {
Map<String, AttributeValueUpdate> updates = new HashMap<String, AttributeValueUpdate>();
updates.put(AttributeName.TXID.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE));
updates.put(AttributeName.TRANSIENT.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE));
updates.put(AttributeName.APPLIED.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE));
updates.put(AttributeName.DATE.toString(), new AttributeValueUpdate().withAction(AttributeAction.DELETE));
UpdateItemRequest update = new UpdateItemRequest()
.withTableName(request.getTableName())
.withKey(request.getKey(txManager))
.withAttributeUpdates(updates)
.withExpected(expected);
txManager.getClient().updateItem(update);
} else if(request instanceof DeleteItem) {
DeleteItemRequest delete = new DeleteItemRequest()
.withTableName(request.getTableName())
.withKey(request.getKey(txManager))
.withExpected(expected);
txManager.getClient().deleteItem(delete);
} else if(request instanceof GetItem) {
releaseReadLock(request.getTableName(), request.getKey(txManager));
} else {
throw new TransactionAssertionException(txId, "Unknown request type: " + request.getClass());
}
} catch (ConditionalCheckFailedException e) {
// ignore, unlock already happened
// TODO if we really want to be paranoid we could condition on applied = 1, and then here
// we would have to read the item again and make sure that applied was 1 if we owned the lock (and assert otherwise)
}
}