private static void MultiTableBatchWrite() { // 1. Specify item to add in the Forum table. Table forum = Table.LoadTable(client, "Forum"); var forumBatchWrite = forum.CreateBatchWrite(); var forum1 = new Document(); forum1["Name"] = "Test BatchWrite Forum"; forum1["Threads"] = 0; forumBatchWrite.AddDocumentToPut(forum1); // 2a. Specify item to add in the Thread table. Table thread = Table.LoadTable(client, "Thread"); var threadBatchWrite = thread.CreateBatchWrite(); var thread1 = new Document(); thread1["ForumName"] = "S3 forum"; thread1["Subject"] = "My sample question"; thread1["Message"] = "Message text"; thread1["KeywordTags"] = new List<string> { "S3", "Bucket" }; threadBatchWrite.AddDocumentToPut(thread1); // 2b. Specify item to delete from the Thread table. threadBatchWrite.AddKeyToDelete("someForumName", "someSubject"); // 3. Create multi-table batch. var superBatch = new MultiTableDocumentBatchWrite(); superBatch.AddBatch(forumBatchWrite); superBatch.AddBatch(threadBatchWrite); Console.WriteLine("Performing batch write in MultiTableBatchWrite()"); superBatch.Execute(); }
internal void ExecuteHelper(bool isAsync) { MultiTableDocumentBatchWrite superBatch = new MultiTableDocumentBatchWrite(); foreach (var batch in allBatches) { superBatch.AddBatch(batch.DocumentBatch); } superBatch.ExecuteHelper(isAsync); }
internal Task ExecuteHelperAsync(CancellationToken cancellationToken) { MultiTableDocumentBatchWrite superBatch = new MultiTableDocumentBatchWrite(); foreach (var batch in allBatches) { superBatch.AddBatch(batch.DocumentBatch); } return(superBatch.ExecuteHelperAsync(cancellationToken)); }
private void MultiTableBatchWrite() { this.displayMessage = ("\n*** MultiTableBatchWrite() ***"); ThreadPool.QueueUserWorkItem((s) => { this.displayMessage += ("\n running in background thread"); try { var batchWrite = productCatalog.CreateBatchWrite(); var book1 = new Document(); book1["Id"] = 9111; book1["Title"] = "My 222book1 in batch write using .NET helper classes"; book1["ISBN"] = "902-11-11-1111"; book1["Price"] = 10; book1["ProductCategory"] = "Book"; book1["Authors"] = new List <string> { "Author 1", "Author 2", "Author 3" }; book1["Dimensions"] = "8.5x11x.5"; book1["InStock"] = true; book1["QuantityOnHand"] = null; //Quantity is unknown at this time batchWrite.AddDocumentToPut(book1); // 1. Specify item to add in the Forum table. Table reply = Table.LoadTable(client, "Reply"); var replyBatchWrite = reply.CreateBatchWrite(); // Reply 1 - thread 1. var thread1Reply1 = new Document(); thread1Reply1["Id"] = "Amazon DynamoDB#DynamoDB Thread 1"; // Hash attribute. thread1Reply1["ReplyDateTime"] = DateTime.UtcNow.Subtract(new TimeSpan(21, 0, 0, 0)); // Range attribute. thread1Reply1["Message"] = "DynamoDB Thread 1 Reply 1 text"; thread1Reply1["PostedBy"] = "User A"; thread1Reply1["Votes"] = -2; replyBatchWrite.AddDocumentToPut(thread1Reply1); // 3. Create multi-table batch. var superBatch = new MultiTableDocumentBatchWrite(); superBatch.AddBatch(replyBatchWrite); superBatch.AddBatch(batchWrite); this.displayMessage += ("\nPerforming batch write in MultiTableBatchWrite()"); superBatch.Execute(); this.displayMessage += "\nCompleted!"; } catch (Exception ex) { this.displayMessage += ex.Message; Debug.LogException(ex); } }); }
/// <summary> /// Perform a batch operation involving multiple DynamoDB tables. /// </summary> /// <param name="client">An initialized DynamoDB client object.</param> public static async Task MultiTableBatchWrite(IAmazonDynamoDB client) { // Specify item to add in the Forum table. Table forum = Table.LoadTable(client, "Forum"); var forumBatchWrite = forum.CreateBatchWrite(); var forum1 = new Document { ["Name"] = "Test BatchWrite Forum", ["Threads"] = 0, }; forumBatchWrite.AddDocumentToPut(forum1); // Specify item to add in the Thread table. Table thread = Table.LoadTable(client, "Thread"); var threadBatchWrite = thread.CreateBatchWrite(); var thread1 = new Document { ["ForumName"] = "S3 forum", ["Subject"] = "My sample question", ["Message"] = "Message text", ["KeywordTags"] = new List <string> { "S3", "Bucket" }, }; threadBatchWrite.AddDocumentToPut(thread1); // Specify item to delete from the Thread table. threadBatchWrite.AddKeyToDelete("someForumName", "someSubject"); // Create multi-table batch. var superBatch = new MultiTableDocumentBatchWrite(); superBatch.AddBatch(forumBatchWrite); superBatch.AddBatch(threadBatchWrite); Console.WriteLine("Performing batch write in MultiTableBatchWrite()"); // Execute the batch. await superBatch.ExecuteAsync(); }
internal void ExecuteHelper(bool isAsync) { MultiTableDocumentBatchWrite superBatch = new MultiTableDocumentBatchWrite(); foreach (var batch in allBatches) { superBatch.AddBatch(batch.DocumentBatch); } superBatch.ExecuteHelper(isAsync); }
private void TestMultiTableDocumentBatchWrite(Table hashTable, Table hashRangeTable) { var multiTableDocumentBatchWrite = new MultiTableDocumentBatchWrite(); var doc1a = new Document(); doc1a["Id"] = 5101; doc1a["Data"] = Guid.NewGuid().ToString(); var doc1b = new Document(); doc1b["Id"] = 5102; doc1b["Data"] = Guid.NewGuid().ToString(); { var writer = new DocumentBatchWrite(hashTable); writer.AddDocumentToPut(doc1a); writer.AddDocumentToPut(doc1b); multiTableDocumentBatchWrite.AddBatch(writer); } var doc2a = new Document(); doc2a["Id"] = 5201; doc2a["Data"] = Guid.NewGuid().ToString(); var doc2b = new Document(); doc2b["Id"] = 5202; doc2b["Data"] = Guid.NewGuid().ToString(); { var writer = new DocumentBatchWrite(hashTable); writer.AddDocumentToPut(doc2a); writer.AddDocumentToPut(doc2b); multiTableDocumentBatchWrite.AddBatch(writer); } var doc3a = new Document(); doc3a["Name"] = "Gunnar"; doc3a["Age"] = 77; doc3a["Job"] = "Retired"; doc3a["Data"] = Guid.NewGuid().ToString(); { var writer = new DocumentBatchWrite(hashRangeTable); writer.AddDocumentToPut(doc3a); multiTableDocumentBatchWrite.AddBatch(writer); } multiTableDocumentBatchWrite.Execute(); Document getDoc; getDoc = hashTable.GetItem(5101); Assert.AreEqual(doc1a["Data"].AsString(), getDoc["Data"].AsString()); getDoc = hashTable.GetItem(5102); Assert.AreEqual(doc1b["Data"].AsString(), getDoc["Data"].AsString()); getDoc = hashTable.GetItem(5201); Assert.AreEqual(doc2a["Data"].AsString(), getDoc["Data"].AsString()); getDoc = hashTable.GetItem(5202); Assert.AreEqual(doc2b["Data"].AsString(), getDoc["Data"].AsString()); getDoc = hashRangeTable.GetItem("Gunnar", 77); Assert.AreEqual(doc3a["Data"].AsString(), getDoc["Data"].AsString()); multiTableDocumentBatchWrite = new MultiTableDocumentBatchWrite(); { var deleteWriter = new DocumentBatchWrite(hashTable); deleteWriter.AddItemToDelete(doc1a); deleteWriter.AddItemToDelete(doc1b); deleteWriter.AddItemToDelete(doc2a); deleteWriter.AddItemToDelete(doc2b); multiTableDocumentBatchWrite.AddBatch(deleteWriter); } { var deleteWriter = new DocumentBatchWrite(hashRangeTable); deleteWriter.AddItemToDelete(doc3a); multiTableDocumentBatchWrite.AddBatch(deleteWriter); } multiTableDocumentBatchWrite.Execute(); }