当前位置: 首页>>代码示例>>C#>>正文


C# Document.CommitChanges方法代码示例

本文整理汇总了C#中Amazon.DynamoDB.DocumentModel.Document.CommitChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Document.CommitChanges方法的具体用法?C# Document.CommitChanges怎么用?C# Document.CommitChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.DynamoDB.DocumentModel.Document的用法示例。


在下文中一共展示了Document.CommitChanges方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateHelper

        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;
        }
开发者ID:skilitics,项目名称:aws-sdk-net,代码行数:39,代码来源:Table.cs

示例2: PutItemHelper

        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.PutItemResult.Attributes);
            }
            return ret;
        }
开发者ID:skilitics,项目名称:aws-sdk-net,代码行数:29,代码来源:Table.cs

示例3: FromAttributeMap

        /// <summary>
        /// Creates a Document from an attribute map.
        /// </summary>
        /// <param name="data">Map of attribute names to attribute values.</param>
        /// <returns>Document representing the data.</returns>
        public static Document FromAttributeMap(Dictionary<string, AttributeValue> data)
        {
            Document doc = new Document();

            if (data != null)
            {
                // Add Primitives and PrimitiveLists
                foreach (var attribute in data)
                {
                    string wholeKey = attribute.Key;
                    AttributeValue value = attribute.Value;

                    DynamoDBEntry convertedValue = AttributeValueToDynamoDBEntry(value);
                    if (convertedValue != null)
                        doc.currentValues[wholeKey] = convertedValue;
                }
            }

            doc.CommitChanges();
            return doc;
        }
开发者ID:davidsidlinger,项目名称:aws-sdk-net,代码行数:26,代码来源:Document.cs

示例4: UpdateHelper

        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;
        }
开发者ID:buddydvd,项目名称:aws-sdk-for-net,代码行数:34,代码来源:Table.cs

示例5: UpdateHelper

        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;
        }
开发者ID:nburn42,项目名称:aws-sdk-for-net,代码行数:68,代码来源:Table.cs

示例6: FromAttributeMap

        /// <summary>
        /// Creates a Document from an attribute map.
        /// </summary>
        /// <param name="data">Map of attribute names to attribute values.</param>
        /// <returns>Document representing the data.</returns>
        public static Document FromAttributeMap(Dictionary<string, AttributeValue> data)
        {
            Document doc = new Document();

            // Add Primitives and PrimitiveLists
            foreach (var attribute in data)
            {
                string wholeKey = attribute.Key;
                AttributeValue value = attribute.Value;

                if (value.S != null)
                {
                    doc.currentValues[wholeKey] = value.S;
                }
                else if (value.N != null)
                {
                    Primitive primitive = value.N;
                    primitive.SaveAsNumeric = true;
                    doc.currentValues[wholeKey] = primitive;
                }
                else if (value.SS != null && value.SS.Count != 0)
                {
                    doc.currentValues[wholeKey] = value.SS;
                }
                else if (value.NS != null && value.NS.Count != 0)
                {
                    PrimitiveList primitiveList = value.NS;
                    primitiveList.SaveAsNumeric = true;
                    doc.currentValues[wholeKey] = primitiveList;
                }
            }

            doc.CommitChanges();
            return doc;
        }
开发者ID:buddydvd,项目名称:aws-sdk-for-net,代码行数:40,代码来源:Document.cs


注:本文中的Amazon.DynamoDB.DocumentModel.Document.CommitChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。