コード例 #1
0
 /// <summary>
 /// Sets the LastEvaluatedKey property
 /// </summary>
 /// <param name="lastEvaluatedKey">The value to set for the LastEvaluatedKey property </param>
 /// <returns>this instance</returns>
 public ScanResult WithLastEvaluatedKey(Key lastEvaluatedKey)
 {
     this.lastEvaluatedKey = lastEvaluatedKey;
     return this;
 }
コード例 #2
0
ファイル: Table.cs プロジェクト: skilitics/aws-sdk-net
        internal Key MakeKey(Primitive hashKey, Primitive rangeKey)
        {
            Key newKey = new Key();

            newKey.HashKeyElement = hashKey.ConvertToAttributeValue();
            if (HashKeyType != hashKey.Type)
                throw new InvalidOperationException("Table schema hash key inconsistent with specified hash key value");

            if ((rangeKey == null) == RangeKeyIsDefined)
            {
                throw new ArgumentException("Range Key does not match schema");
            }
            else
            {
                if (RangeKeyIsDefined)
                {
                    newKey.RangeKeyElement = rangeKey.ConvertToAttributeValue();
                    if (RangeKeyType != rangeKey.Type)
                        throw new InvalidOperationException("Table schema range key inconsistent with specified range key value");
                }
            }

            return newKey;
        }
コード例 #3
0
ファイル: Table.cs プロジェクト: skilitics/aws-sdk-net
        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 ?
                    new Dictionary<string,AttributeValueUpdate>() : attributeUpdates,
                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.UpdateItemResult.Attributes;
            doc.CommitChanges();

            Document ret = null;
            if (currentConfig.ReturnValues != ReturnValues.None)
            {
                ret = Document.FromAttributeMap(returnedAttributes);
            }
            return ret;
        }
コード例 #4
0
ファイル: Table.cs プロジェクト: skilitics/aws-sdk-net
        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).DeleteItemResult.Attributes;

            Document ret = null;
            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                ret = Document.FromAttributeMap(attributes);
            }
            return ret;
        }
コード例 #5
0
ファイル: Table.cs プロジェクト: skilitics/aws-sdk-net
        internal Document GetItemHelper(Key key, GetItemOperationConfig config, bool isAsync)
        {
            var currentConfig = config ?? new GetItemOperationConfig();
            var request = new GetItemRequest
            {
                TableName = TableName,
                Key = key,
                ConsistentRead = currentConfig.ConsistentRead
            };
            request.BeforeRequestEvent += isAsync ?
                new RequestEventHandler(UserAgentRequestEventHandlerAsync) :
                new RequestEventHandler(UserAgentRequestEventHandlerSync);
            if (currentConfig.AttributesToGet != null)
                request.WithAttributesToGet(currentConfig.AttributesToGet);

            var result = DDBClient.GetItem(request);
            var attributeMap = result.GetItemResult.Item;
            if (attributeMap == null)
                return null;
            return Document.FromAttributeMap(attributeMap);
        }
コード例 #6
0
ファイル: ScanRequest.cs プロジェクト: thecloudbook/amazon
 /// <summary>
 /// Sets the ExclusiveStartKey property
 /// </summary>
 /// <param name="exclusiveStartKey">The value to set for the ExclusiveStartKey property </param>
 /// <returns>this instance</returns>
 public ScanRequest WithExclusiveStartKey(Key exclusiveStartKey)
 {
     this.exclusiveStartKey = exclusiveStartKey;
     return this;
 }
コード例 #7
0
 /// <summary>
 /// Sets the Key property
 /// </summary>
 /// <param name="key">The value to set for the Key property </param>
 /// <returns>this instance</returns>
 public DeleteRequest WithKey(Key key)
 {
     this.key = key;
     return this;
 }
コード例 #8
0
 /// <summary>
 /// Sets the Key property
 /// </summary>
 /// <param name="key">The value to set for the Key property </param>
 /// <returns>this instance</returns>
 public GetItemRequest WithKey(Key key)
 {
     this.key = key;
     return this;
 }
コード例 #9
0
ファイル: Table.cs プロジェクト: buddydvd/aws-sdk-for-net
        private Document UpdateHelper(Document doc, Key key, UpdateItemOperationConfig config)
        {
            var currentConfig = config ?? new UpdateItemOperationConfig();

            var attributeUpdates = doc.ToAttributeUpdateMap(true);
            foreach (var keyName in this.keyNames)
            {
                if (keyName != null)
                {
                    attributeUpdates.Remove(keyName);
                }
            }

            UpdateItemRequest req = new UpdateItemRequest
            {
                TableName = TableName,
                Key = key,
                AttributeUpdates = attributeUpdates,
                ReturnValues = EnumToStringMapper.Convert(currentConfig.ReturnValues)
            };
            req.BeforeRequestEvent += new RequestEventHandler(this.UserAgentRequestEventHandler);
            if (currentConfig.Expected != null)
                req.Expected = currentConfig.Expected.ToExpectedAttributeMap();

            var resp = DDBClient.UpdateItem(req);
            doc.CommitChanges();

            Document ret = null;
            if (currentConfig.ReturnValues != ReturnValues.None)
            {
                ret = Document.FromAttributeMap(resp.UpdateItemResult.Attributes);
            }
            return ret;
        }
コード例 #10
0
ファイル: Table.cs プロジェクト: nburn42/aws-sdk-for-net
        internal Document UpdateHelper(Document doc, Key key, UpdateItemOperationConfig config, bool isAsync)
        {
            var currentConfig = config ?? new UpdateItemOperationConfig();

            var attributeUpdates = doc.ToAttributeUpdateMap(true);
            foreach (var keyName in this.keyNames)
            {
                attributeUpdates.Remove(keyName);
            }

            ReturnValues currentReturnValue = currentConfig.ReturnValues;
            bool keysOnlyUpdate = attributeUpdates.Count == 0;
            // If there are no non-key attributes, make an Update call with AllNewAttributes
            // return value. If no attributes returned, the item doesn't exist yet, so
            // make a Put call.
            if (keysOnlyUpdate)
            {
                currentReturnValue = ReturnValues.AllNewAttributes;
            }

            UpdateItemRequest req = new UpdateItemRequest
            {
                TableName = TableName,
                Key = key,
                AttributeUpdates = attributeUpdates,
                ReturnValues = EnumToStringMapper.Convert(currentReturnValue)
            };
            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.UpdateItemResult.Attributes;
            doc.CommitChanges();

            if (keysOnlyUpdate)
            {
                if (returnedAttributes == null || returnedAttributes.Count == 0)
                {
                    // if only keys were specified and no attributes are returned, we must issue a Put
                    return CallKeysOnlyPut(key, currentConfig, isAsync);
                }
                else
                {
                    // update was called with AllNewAttributes, item exists
                    // return correct set of attributes
                    // [None] is handled at the end
                    // [AllNewAttributes, AllOldAttributes] are equivalent in this case, no-op
                    // [UpdatedNewAttributes, UpdatedOldAttributes] must return no attributes
                    switch (currentConfig.ReturnValues)
                    {
                        case ReturnValues.UpdatedNewAttributes:
                        case ReturnValues.UpdatedOldAttributes:
                            returnedAttributes = new Dictionary<string,AttributeValue>();
                            break;
                    }
                }
            }

            Document ret = null;
            if (currentConfig.ReturnValues != ReturnValues.None)
            {
                ret = Document.FromAttributeMap(returnedAttributes);
            }
            return ret;
        }
コード例 #11
0
 internal void AddKey(Key key)
 {
     Keys.Add(key);
 }
コード例 #12
0
ファイル: Table.cs プロジェクト: nburn42/aws-sdk-for-net
        // Creates a PutItemOperationConfig for the keys-only Put operation
        private PutItemOperationConfig CreateKeysOnlyPutConfig(Key key, UpdateItemOperationConfig config)
        {
            // configure the expected document
            Document expected = new Document();

            expected[this.HashKeyName] = null;
            if (this.RangeKeyIsDefined)
            {
                expected[this.RangeKeyName] = null;
            }

            // create the PutItemOperationConfig
            var putConfig = new PutItemOperationConfig
            {
                Expected = expected,
                ReturnValues = ReturnValues.None
            };

            return putConfig;
        }
コード例 #13
0
ファイル: Table.cs プロジェクト: nburn42/aws-sdk-for-net
 // Creates a Document object that consists of the hash and potentially range keys
 private Document CreateKeysOnlyDocument(Key key)
 {
     // create document to put
     Document doc = new Document();
     if (!doc.Contains(this.HashKeyName))
     {
         DynamoDBEntry hashKey = Document.AttributeValueToDynamoDBEntry(key.HashKeyElement);
         if (hashKey == null) throw new InvalidOperationException("Cannot convert hash key attribute");
         doc[this.HashKeyName] = hashKey;
     }
     if (this.RangeKeyIsDefined && !doc.Contains(this.RangeKeyName))
     {
         DynamoDBEntry rangeKey = Document.AttributeValueToDynamoDBEntry(key.RangeKeyElement);
         if (rangeKey == null) throw new InvalidOperationException("Cannot convert range key attribute");
         doc[this.RangeKeyName] = rangeKey;
     }
     return doc;
 }
コード例 #14
0
ファイル: Table.cs プロジェクト: nburn42/aws-sdk-for-net
        // calls Put, but returns like Update
        private Document CallKeysOnlyPut(Key key, UpdateItemOperationConfig config, bool isAsync)
        {
            // configure the keys-only Document
            Document doc = CreateKeysOnlyDocument(key);

            // configure the put operation
            PutItemOperationConfig putConfig = CreateKeysOnlyPutConfig(key, config);

            // call put
            PutItemHelper(doc, putConfig, isAsync);

            /*
            New item created, return Update-appropriate response.
            For update, when no item exists:
             [None] - returns null,
             [AllOld, UpdatedNew, UpdatedOld] - return no attributes
             [AllNew] - returns all attributes
            */
            Document response;
            switch (config.ReturnValues)
            {
                case ReturnValues.None:
                    response = null;
                    break;
                case ReturnValues.AllNewAttributes:
                    response = doc;
                    break;
                default:
                    response = new Document();
                    break;
            }

            return response;
        }
コード例 #15
0
 /// <summary>
 /// Sets the Key property
 /// </summary>
 /// <param name="key">The value to set for the Key property </param>
 /// <returns>this instance</returns>
 public UpdateItemRequest WithKey(Key key)
 {
     this.key = key;
     return this;
 }
コード例 #16
0
 /// <summary>
 /// Sets the Key property
 /// </summary>
 /// <param name="key">The value to set for the Key property </param>
 /// <returns>this instance</returns>
 public GetItemRequest WithKey(Key key)
 {
     this.key = key;
     return this;
 }