예제 #1
0
        internal Document DeleteHelper(Key key, DeleteItemOperationConfig config, bool isAsync)
        {
            var currentConfig = config ?? new DeleteItemOperationConfig();

            var req = new DeleteItemRequest
            {
                TableName = TableName,
                Key       = key
            };

            req.BeforeRequestEvent += isAsync ?
                                      new RequestEventHandler(UserAgentRequestEventHandlerAsync) :
                                      new RequestEventHandler(UserAgentRequestEventHandlerSync);
            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                req.ReturnValues = EnumToStringMapper.Convert(currentConfig.ReturnValues);
            }
            if (currentConfig.Expected != null)
            {
                req.Expected = currentConfig.Expected.ToExpectedAttributeMap();
            }

            var attributes = DDBClient.DeleteItem(req).Attributes;

            Document ret = null;

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                ret = Document.FromAttributeMap(attributes);
            }
            return(ret);
        }
예제 #2
0
        internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync)
        {
            var currentConfig = config ?? new PutItemOperationConfig();

            PutItemRequest req = new PutItemRequest
            {
                TableName = TableName,
                Item      = doc.ToAttributeMap()
            };

            req.BeforeRequestEvent += isAsync ?
                                      new RequestEventHandler(UserAgentRequestEventHandlerAsync) :
                                      new RequestEventHandler(UserAgentRequestEventHandlerSync);
            if (currentConfig.Expected != null)
            {
                req.Expected = currentConfig.Expected.ToExpectedAttributeMap();
            }
            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                req.ReturnValues = EnumToStringMapper.Convert(currentConfig.ReturnValues);
            }

            var resp = DDBClient.PutItem(req);

            doc.CommitChanges();

            Document ret = null;

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                ret = Document.FromAttributeMap(resp.Attributes);
            }
            return(ret);
        }
예제 #3
0
        private int GetCount()
        {
            if (IsDone)
            {
                return(Matches.Count);
            }
            else
            {
                if (count != -1)
                {
                    return(count);
                }
                else
                {
                    switch (SearchMethod)
                    {
                    case SearchType.Scan:
                        ScanRequest scanReq = new ScanRequest
                        {
                            TableName         = TableName,
                            Select            = EnumToStringMapper.Convert(SelectValues.Count),
                            ExclusiveStartKey = NextKey,
                            ScanFilter        = Filter,
                        };

                        if (this.TotalSegments != 0)
                        {
                            scanReq.TotalSegments = this.TotalSegments;
                            scanReq.Segment       = this.Segment;
                        }
                        scanReq.BeforeRequestEvent += SourceTable.UserAgentRequestEventHandlerSync;

                        ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq).ScanResult;
                        count = Matches.Count + scanResult.Count;
                        return(count);

                    case SearchType.Query:
                        QueryRequest queryReq = new QueryRequest
                        {
                            TableName         = TableName,
                            ConsistentRead    = IsConsistentRead,
                            Select            = EnumToStringMapper.Convert(SelectValues.Count),
                            ExclusiveStartKey = NextKey,
                            ScanIndexForward  = !IsBackwardSearch,
                            KeyConditions     = Filter,
                            IndexName         = IndexName
                        };
                        queryReq.BeforeRequestEvent += SourceTable.UserAgentRequestEventHandlerSync;

                        QueryResult queryResult = SourceTable.DDBClient.Query(queryReq).QueryResult;
                        count = Matches.Count + queryResult.Count;
                        return(count);

                    default:
                        throw new InvalidOperationException("Unknown Search Method");
                    }
                }
            }
        }
예제 #4
0
 /// <summary>
 /// Adds a condition for a specified attribute that consists
 /// of an operator and any number of values
 /// </summary>
 /// <param name="attributeName">Target attribute name</param>
 /// <param name="op">Comparison operator</param>
 /// <param name="values">Values to compare to</param>
 public void AddCondition(string attributeName, QueryOperator op, params DynamoDBEntry[] values)
 {
     AddCondition(attributeName, new Condition
     {
         ComparisonOperator = EnumToStringMapper.Convert(op),
         AttributeValueList = ConvertToAttributeValues(values)
     });
 }
예제 #5
0
 /// <summary>
 /// Adds a condition for a specified attribute that consists
 /// of an operator and any number of AttributeValues.
 /// </summary>
 /// <param name="attributeName">Target attribute name</param>
 /// <param name="op">Comparison operator</param>
 /// <param name="values">AttributeValues to compare to</param>
 public void AddCondition(string attributeName, QueryOperator op, List <AttributeValue> values)
 {
     AddCondition(attributeName, new Condition
     {
         ComparisonOperator = EnumToStringMapper.Convert(op),
         AttributeValueList = values
     });
 }
예제 #6
0
        internal Document UpdateHelper(Document doc, Key key, UpdateItemOperationConfig config, bool isAsync)
        {
            var currentConfig = config ?? new UpdateItemOperationConfig();

            // If the keys have been changed, treat entire document as having changed
            bool haveKeysChanged             = HaveKeysChanged(doc);
            bool updateChangedAttributesOnly = !haveKeysChanged;

            var attributeUpdates = doc.ToAttributeUpdateMap(updateChangedAttributesOnly);

            foreach (var keyName in this.keyNames)
            {
                attributeUpdates.Remove(keyName);
            }

            UpdateItemRequest req = new UpdateItemRequest
            {
                TableName        = TableName,
                Key              = key,
                AttributeUpdates = attributeUpdates.Count == 0 ? null : attributeUpdates, // pass null if keys-only update
                ReturnValues     = EnumToStringMapper.Convert(currentConfig.ReturnValues)
            };

            req.BeforeRequestEvent += isAsync ?
                                      new RequestEventHandler(UserAgentRequestEventHandlerAsync) :
                                      new RequestEventHandler(UserAgentRequestEventHandlerSync);
            if (currentConfig.Expected != null)
            {
                req.Expected = currentConfig.Expected.ToExpectedAttributeMap();
            }

            var resp = DDBClient.UpdateItem(req);
            var returnedAttributes = resp.Attributes;

            doc.CommitChanges();

            Document ret = null;

            if (currentConfig.ReturnValues != ReturnValues.None)
            {
                ret = Document.FromAttributeMap(returnedAttributes);
            }
            return(ret);
        }
예제 #7
0
        private List <Document> GetNextSetHelper(bool isAsync)
        {
            List <Document> ret = new List <Document>();

            if (!IsDone)
            {
                switch (SearchMethod)
                {
                case SearchType.Scan:
                    ScanRequest scanReq = new ScanRequest
                    {
                        ExclusiveStartKey = NextKey,
                        Limit             = Limit,
                        TableName         = TableName,
                        AttributesToGet   = AttributesToGet,
                        ScanFilter        = Filter,
                        Select            = EnumToStringMapper.Convert(Select)
                    };

                    if (this.TotalSegments != 0)
                    {
                        scanReq.TotalSegments = this.TotalSegments;
                        scanReq.Segment       = this.Segment;
                    }

                    scanReq.BeforeRequestEvent += isAsync ?
                                                  new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) :
                                                  new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync);

                    ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq).ScanResult;
                    foreach (var item in scanResult.Items)
                    {
                        Document doc = Document.FromAttributeMap(item);
                        ret.Add(doc);
                        Matches.Add(doc);
                    }
                    NextKey = scanResult.LastEvaluatedKey;
                    if (NextKey == null)
                    {
                        IsDone = true;
                    }
                    return(ret);

                case SearchType.Query:
                    QueryRequest queryReq = new QueryRequest
                    {
                        ConsistentRead    = IsConsistentRead,
                        ExclusiveStartKey = NextKey,
                        Limit             = Limit,
                        ScanIndexForward  = !IsBackwardSearch,
                        TableName         = TableName,
                        AttributesToGet   = AttributesToGet,
                        KeyConditions     = Filter,
                        IndexName         = IndexName,
                        Select            = EnumToStringMapper.Convert(Select)
                    };
                    queryReq.BeforeRequestEvent += isAsync ?
                                                   new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) :
                                                   new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync);

                    QueryResult queryResult = SourceTable.DDBClient.Query(queryReq).QueryResult;
                    foreach (var item in queryResult.Items)
                    {
                        Document doc = Document.FromAttributeMap(item);
                        ret.Add(doc);
                        Matches.Add(doc);
                    }
                    NextKey = queryResult.LastEvaluatedKey;
                    if (NextKey == null)
                    {
                        IsDone = true;
                    }
                    return(ret);

                default:
                    throw new InvalidOperationException("Unknown Search Method");
                }
            }

            return(ret);
        }