Last active
December 24, 2015 11:09
-
-
Save yuta-imai/6789202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DynamoDBクライアントの初期化 | |
AmazonDynamoDB client = new AmazonDynamoDBClient(); | |
// Transaction管理テーブルの作成 | |
TransactionManager.verifyOrCreateTransactionTable( | |
client, "Transactions" /*tableName*/, | |
10 /*readCapacityUnits*/, | |
10 /*writeCapacityUnits*/, | |
10 * 60 /*waitTimeSeconds*/); | |
// 同じくTransaction管理に必要なテーブルを作成 | |
TransactionManager.verifyOrCreateTransactionImagesTable( | |
client, "TransactionImages" /*tableName*/, | |
10 /*readCapacityUnits*/, | |
10 /*writeCapacityUnits*/, | |
10 * 60 /*waitTimeSeconds*/); | |
// Transactionマネージャの初期化 | |
TransactionManager txManager = new TransactionManager(client, "Transactions", "TransactionImages"); | |
// Transaction開始 | |
Transaction t1 = txManager.newTransaction(); | |
// データを"Reply"テーブルにput | |
Map<String, AttributeValue> reply = new HashMap<String, AttributeValue>(); | |
reply.put("Id", new AttributeValue("Amazon DynamoDB#Transactions?")); | |
reply.put("ReplyDateTime", new AttributeValue("(the current date and time)")); | |
reply.put("PostedBy", new AttributeValue("DavidY@AWS")); | |
reply.put("Message", new AttributeValue("Transactions are now available!")); | |
t1.putItem(new PutItemRequest() | |
.withTableName("Reply") | |
.withItem(reply)); | |
// もうひとつのデータを更新 | |
Map<String, AttributeValue> thread = new HashMap<String, AttributeValue>(); | |
thread.put("ForumName", new AttributeValue("Amazon DynamoDB")); | |
thread.put("Subject", new AttributeValue("Transactions?")); | |
Map<String, AttributeValueUpdate> threadUpdates = new HashMap<String, AttributeValueUpdate>(); | |
threadUpdates.put("Replies", new AttributeValueUpdate(new AttributeValue().withN("1"), "ADD")); | |
t1.updateItem(new UpdateItemRequest() | |
.withTableName("Thread") | |
.withKey(thread) | |
.withAttributeUpdates(threadUpdates)); | |
// TransactionをCommit | |
t1.commit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment