in src/main/java/com/amazonaws/services/dynamodbv2/transactions/TransactionItem.java [272:317]
public synchronized boolean addRequest(Request callerRequest) throws ConditionalCheckFailedException, DuplicateRequestException {
// 1. Ensure the request is unique (modifies the internal data structure if it is unique)
// However, do not not short circuit. If we're doing a read in a resumed transaction, it's important to ensure we're returning
// any writes that happened before.
addRequestToMap(callerRequest);
callerRequest.setRid(version);
// 2. Write request to transaction item
ByteBuffer requestBytes = Request.serialize(txId, callerRequest);
AttributeValueUpdate txItemUpdate = new AttributeValueUpdate()
.withAction(AttributeAction.ADD)
.withValue(new AttributeValue().withBS(Arrays.asList(requestBytes)));
Map<String, AttributeValueUpdate> txItemUpdates = new HashMap<String, AttributeValueUpdate>();
txItemUpdates.put(AttributeName.REQUESTS.toString(), txItemUpdate);
txItemUpdates.put(AttributeName.VERSION.toString(), new AttributeValueUpdate().withAction(AttributeAction.ADD).withValue(new AttributeValue().withN("1")));
txItemUpdates.put(AttributeName.DATE.toString(), new AttributeValueUpdate().withAction(AttributeAction.PUT).withValue(txManager.getCurrentTimeAttribute()));
Map<String, ExpectedAttributeValue> expected = new HashMap<String, ExpectedAttributeValue>();
expected.put(AttributeName.STATE.toString(), new ExpectedAttributeValue(new AttributeValue(STATE_PENDING)));
expected.put(AttributeName.VERSION.toString(), new ExpectedAttributeValue(new AttributeValue().withN(Integer.toString(version))));
UpdateItemRequest txItemUpdateRequest = new UpdateItemRequest()
.withTableName(txManager.getTransactionTableName())
.withKey(txKey)
.withExpected(expected)
.withReturnValues(ReturnValue.ALL_NEW)
.withAttributeUpdates(txItemUpdates);
try {
txItem = txManager.getClient().updateItem(txItemUpdateRequest).getAttributes();
int newVersion = Integer.parseInt(txItem.get(AttributeName.VERSION.toString()).getN());
txAssert(newVersion == version + 1, txId, "Unexpected version number from update result");
version = newVersion;
} catch (AmazonServiceException e) {
if("ValidationException".equals(e.getErrorCode())) {
removeRequestFromMap(callerRequest);
throw new InvalidRequestException("The amount of data in the transaction cannot exceed the DynamoDB item size limit",
txId, callerRequest.getTableName(), callerRequest.getKey(txManager), callerRequest);
} else {
throw e;
}
}
return true;
}