Class for retrieving a batch of Documents from a single DynamoDB table.
 public RequestSet(IEnumerable <Dictionary <string, AttributeValue> > items, DocumentBatchGet batch)
     : base(items)
 {
     Batch = batch;
 }
 /// <summary>
 /// Add a DocumentBatchGet object to the multi-table batch request.
 /// </summary>
 /// <param name="batch">DocumentBatchGet to add.</param>
 public void AddBatch(DocumentBatchGet batch)
 {
     Batches.Add(batch);
 }
 /// <summary>
 /// Creates a MultiTableDocumentBatchGet object that is a combination
 /// of the current DocumentBatchGet and the specified DocumentBatchGet.
 /// </summary>
 /// <param name="otherBatch">Other DocumentBatchGet object.</param>
 /// <returns>
 /// MultiTableDocumentBatchGet consisting of the two DocumentBatchGet
 /// objects.
 /// </returns>
 public MultiTableDocumentBatchGet Combine(DocumentBatchGet otherBatch)
 {
     return(new MultiTableDocumentBatchGet(this, otherBatch));
 }
 /// <summary>
 /// Add a DocumentBatchGet object to the multi-table batch request.
 /// </summary>
 /// <param name="batch">DocumentBatchGet to add.</param>
 public void AddBatch(DocumentBatchGet batch)
 {
     Batches.Add(batch);
 }
 /// <summary>
 /// Creates a MultiTableDocumentBatchGet object that is a combination
 /// of the current DocumentBatchGet and the specified DocumentBatchGet.
 /// </summary>
 /// <param name="otherBatch">Other DocumentBatchGet object.</param>
 /// <returns>
 /// MultiTableDocumentBatchGet consisting of the two DocumentBatchGet
 /// objects.
 /// </returns>
 public MultiTableDocumentBatchGet Combine(DocumentBatchGet otherBatch)
 {
     return new MultiTableDocumentBatchGet(this, otherBatch);
 }
        private Dictionary <string, List <Dictionary <string, AttributeValue> > > GetAttributeItems(bool isAsync)
        {
            var allItems = new Dictionary <string, List <Dictionary <string, AttributeValue> > >();

            if (Batches == null || Batches.Count == 0)
            {
                return(allItems);
            }

            DocumentBatchGet    firstBatch = this.Batches[0];
            BatchGetItemRequest request    = new BatchGetItemRequest();

            request.BeforeRequestEvent += isAsync ?
                                          new RequestEventHandler(firstBatch.TargetTable.UserAgentRequestEventHandlerAsync) :
                                          new RequestEventHandler(firstBatch.TargetTable.UserAgentRequestEventHandlerSync);

            foreach (var batch in Batches)
            {
                if (batch.Keys != null && batch.Keys.Count > 0)
                {
                    if (request.RequestItems.ContainsKey(batch.TargetTable.TableName))
                    {
                        throw new InvalidOperationException("Multiple batches refer to the same table.");
                    }

                    request.RequestItems.Add(
                        batch.TargetTable.TableName,
                        new KeysAndAttributes
                    {
                        Keys            = batch.Keys.Select((Key k) => k as Dictionary <string, AttributeValue>).ToList(),
                        AttributesToGet = batch.AttributesToGet,
                        ConsistentRead  = batch.ConsistentRead
                    });
                }
            }
            var client = firstBatch.TargetTable.DDBClient;

            do
            {
                var batchGetItemResponse = client.BatchGetItem(request);
                var result = batchGetItemResponse.BatchGetItemResult;

                var responses = result.Responses;
                foreach (var response in responses)
                {
                    string tableName = response.Key;
                    List <Dictionary <string, AttributeValue> > items = response.Value;

                    List <Dictionary <string, AttributeValue> > fetchedItems;
                    if (!allItems.TryGetValue(tableName, out fetchedItems))
                    {
                        fetchedItems        = new List <Dictionary <string, AttributeValue> >();
                        allItems[tableName] = fetchedItems;
                    }
                    fetchedItems.AddRange(items);
                }

                request.RequestItems = result.UnprocessedKeys;
            } while (request.RequestItems.Count > 0);

            return(allItems);
        }