Database Reference
In-Depth Information
2. The Transaction library is hosted on GitHub, so you can download the maven
project from https://github.com/awslabs/dynamodb-transactions .
3. You can select the download zip option on the GitHub page, and it will download
the source code. Once you have the source code, please build it using Maven by
running the following command:
mvn clean install -Dgpg.skip=true
4. This will install the Transaction library in your .m2 repository, and now you can
start accessing its classes from Eclipse or any other IDE you are using.
So let's start with creating the DynamoDB client as we do for any other operations using
the following command:
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
You can also set other details such as region, credentials, and so on. Now, it's time to cre-
ate the DynamoDB tables we are going to use to save the transaction metadata. This can
be done by calling verifyOrCreateTransactionTable and veri-
fyOrCreateTransactionImagesTable as follows:
TransactionManager.verifyOrCreateTransactionTable(client,
"Transaction", 10, 5, 30);
TransactionManager. verifyOrCreateTransactionImagesTable
(client, "TransactionImages", 10, 5, 30);
The parameters contain the DynamoDB client, the name of the DynamoDB transaction
table, read capacity units, write capacity units, and time to wait. This is a one-time activity
and need not be performed more than once.
Now let's see how to create a transaction and execute it. To begin with, initialize the trans-
action manager, an implementation of which is provided by AWS, with names of the
transaction and transaction images tables, as follows:
TransactionManager txm = new TransactionManager(client,
"Transaction", "Transaction_Images");
Now create a new transaction from the transaction manager and perform the operation you
want to perform:
Search WWH ::




Custom Search