Configuration for the Table.PutItem operation
Inheritance: IConditionalOperationConfig
コード例 #1
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);
        }
コード例 #2
0
 /// <summary>
 /// Initiates the asynchronous execution of the PutItem operation.
 /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/>
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <param name="callback">The callback that will be invoked when the asynchronous operation completes.</param>
 /// <param name="asyncOptions">An instance of AsyncOptions that specifies how the async method should be executed.</param>
 public void PutItemAsync(Document doc, PutItemOperationConfig config,
                          AmazonDynamoDBCallback <Document> callback, AsyncOptions asyncOptions = null)
 {
     asyncOptions = asyncOptions ?? new AsyncOptions();
     DynamoDBAsyncExecutor.ExecuteAsync <Document>(
         () => { return(PutItemHelper(doc, config, true)); },
         asyncOptions,
         callback);
 }
コード例 #3
0
ファイル: Table.Sync.cs プロジェクト: rajdotnet/aws-sdk-net
 /// <summary>
 /// Puts a document into DynamoDB, using optional configs.
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <returns>True if put is successful or false if the condition in the config was not met.</returns>
 public bool TryPutItem(Document doc, PutItemOperationConfig config = null)
 {
     try
     {
         PutItemHelper(doc, config, false);
         return true;
     }
     catch (ConditionalCheckFailedException)
     {
         return false;
     }
 }
コード例 #4
0
ファイル: Table.Sync.cs プロジェクト: eangelov/aws-sdk-net-1
 /// <summary>
 /// Puts a document into DynamoDB, using specified configs.
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <returns>True if put was successful or false if the condition in the config was not met.</returns>
 public bool TryPutItem(Document doc, PutItemOperationConfig config)
 {
     try
     {
         PutItemHelper(doc, config);
         return(true);
     }
     catch (ConditionalCheckFailedException)
     {
         return(false);
     }
 }
コード例 #5
0
        internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync)
        {
            var currentConfig = config ?? new PutItemOperationConfig();

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

            ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)req).AddBeforeRequestHandler(isAsync ?
                                                                                            new RequestEventHandler(UserAgentRequestEventHandlerAsync) :
                                                                                            new RequestEventHandler(UserAgentRequestEventHandlerSync));

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues);
            }

            ValidateConditional(currentConfig);


            if (currentConfig.Expected != null)
            {
                req.Expected = currentConfig.Expected.ToExpectedAttributeMap(Conversion);
            }
            else if (currentConfig.ExpectedState != null &&
                     currentConfig.ExpectedState.ExpectedValues != null &&
                     currentConfig.ExpectedState.ExpectedValues.Count > 0)
            {
                req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(Conversion);
                if (req.Expected.Count > 1)
                {
                    req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator);
                }
            }
            else if (currentConfig.ConditionalExpression != null && currentConfig.ConditionalExpression.IsSet)
            {
                currentConfig.ConditionalExpression.ApplyExpression(req, this.Conversion);
            }

            var resp = DDBClient.PutItem(req);

            doc.CommitChanges();

            Document ret = null;

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                ret = Document.FromAttributeMap(resp.Attributes);
            }
            return(ret);
        }
コード例 #6
0
        internal async Task <Document> PutItemHelperAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken)
        {
            var currentConfig = config ?? new PutItemOperationConfig();

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

            this.AddRequestHandler(req, isAsync: true);

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues);
            }

            ValidateConditional(currentConfig);


            if (currentConfig.Expected != null)
            {
                req.Expected = this.ToExpectedAttributeMap(currentConfig.Expected);
            }
            else if (currentConfig.ExpectedState != null &&
                     currentConfig.ExpectedState.ExpectedValues != null &&
                     currentConfig.ExpectedState.ExpectedValues.Count > 0)
            {
                req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(this);
                if (req.Expected.Count > 1)
                {
                    req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator);
                }
            }
            else if (currentConfig.ConditionalExpression != null && currentConfig.ConditionalExpression.IsSet)
            {
                currentConfig.ConditionalExpression.ApplyExpression(req, this);
            }

            var resp = await DDBClient.PutItemAsync(req, cancellationToken).ConfigureAwait(false);

            doc.CommitChanges();

            Document ret = null;

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                ret = this.FromAttributeMap(resp.Attributes);
            }
            return(ret);
        }
コード例 #7
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.ReturnValues == ReturnValues.AllOldAttributes)
            {
                req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues);
            }
            if (currentConfig.Expected != null && currentConfig.ExpectedState != null)
            {
                throw new InvalidOperationException("Expected and ExpectedState cannot be set at the same time");
            }
            if (currentConfig.Expected != null)
            {
                req.Expected = currentConfig.Expected.ToExpectedAttributeMap();
            }
            if (currentConfig.ExpectedState != null &&
                currentConfig.ExpectedState.ExpectedValues != null &&
                currentConfig.ExpectedState.ExpectedValues.Count > 0)
            {
                req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap();
                if (req.Expected.Count > 1)
                {
                    req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator);
                }
            }

            var resp = DDBClient.PutItem(req);

            doc.CommitChanges();

            Document ret = null;

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                ret = Document.FromAttributeMap(resp.Attributes);
            }
            return(ret);
        }
コード例 #8
0
 /// <summary>
 /// Puts a document into DynamoDB, using optional configs.
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <returns>Null or updated attributes, depending on config.</returns>
 public Document PutItem(Document doc, PutItemOperationConfig config = null)
 {
     return(PutItemHelper(doc, config, false));
 }
コード例 #9
0
ファイル: Table.Sync.cs プロジェクト: eangelov/aws-sdk-net-1
 /// <summary>
 /// Puts a document into DynamoDB, using specified configs.
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <returns>Null or updated attributes, depending on config.</returns>
 public Document PutItem(Document doc, PutItemOperationConfig config)
 {
     return(PutItemHelper(doc, config));
 }
コード例 #10
0
ファイル: Table.cs プロジェクト: rossmas/aws-sdk-net
        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.ReturnValues == ReturnValues.AllOldAttributes)
                req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues);
            if (currentConfig.Expected != null && currentConfig.ExpectedState != null)
                throw new InvalidOperationException("Expected and ExpectedState cannot be set at the same time");
            if (currentConfig.Expected != null)
                req.Expected = currentConfig.Expected.ToExpectedAttributeMap();
            if (currentConfig.ExpectedState != null &&
                currentConfig.ExpectedState.ExpectedValues != null &&
                currentConfig.ExpectedState.ExpectedValues.Count > 0)
            {
                req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap();
                if (req.Expected.Count > 1)
                    req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator);
            }

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

            Document ret = null;
            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                ret = Document.FromAttributeMap(resp.Attributes);
            }
            return ret;
        }
コード例 #11
0
ファイル: Table.Async.cs プロジェクト: aws/aws-sdk-net
 /// <summary>
 /// Initiates the asynchronous execution of the PutItem operation.
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>        
 /// <param name="callback">The callback that will be invoked when the asynchronous operation completes.</param> 
 /// <param name="asyncOptions">An instance of AsyncOptions that specifies how the async method should be executed.</param>
 public void PutItemAsync(Document doc, PutItemOperationConfig config,
     AmazonDynamoDBCallback<Document> callback, AsyncOptions asyncOptions = null)
 {
     asyncOptions = asyncOptions ?? new AsyncOptions();
     DynamoDBAsyncExecutor.ExecuteAsync<Document>(
         () => { return PutItemHelper(doc, config, true); },
         asyncOptions,
         callback);
 }
コード例 #12
0
ファイル: Table.Async.cs プロジェクト: philasmar/aws-sdk-net
 /// <summary>
 /// Initiates the asynchronous execution of the PutItem operation.
 /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/>
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <param name="cancellationToken">Token which can be used to cancel the task.</param>
 /// <returns>A Task that can be used to poll or wait for results, or both.</returns>
 public Task <Document> PutItemAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(PutItemHelperAsync(doc, config, cancellationToken));
 }
コード例 #13
0
 /// <summary>
 /// Initiates the asynchronous execution of the PutItem operation.
 /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/>
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <param name="cancellationToken">Token which can be used to cancel the task.</param>
 /// <returns>A Task that can be used to poll or wait for results, or both.</returns>
 public Task <Document> PutItemAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(AsyncRunner.Run(() => PutItemHelper(doc, config, true), cancellationToken));
 }
コード例 #14
0
 /// <summary>
 /// Initiates the asynchronous execution of the PutItem operation.
 /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/>
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndPutItem
 ///         operation.</returns>
 public IAsyncResult BeginPutItem(Document doc, PutItemOperationConfig config, AsyncCallback callback, object state)
 {
     return(DynamoDBAsyncExecutor.BeginOperation(() => PutItemHelper(doc, config, true), callback, state));
 }
コード例 #15
0
ファイル: Table.Sync.cs プロジェクト: rajdotnet/aws-sdk-net
 /// <summary>
 /// Puts a document into DynamoDB, using optional configs.
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <returns>Null or updated attributes, depending on config.</returns>
 public Document PutItem(Document doc, PutItemOperationConfig config = null)
 {
     return PutItemHelper(doc, config, false);
 }
コード例 #16
0
 /// <summary>
 /// Initiates the asynchronous execution of the PutItem operation.
 /// Puts a document into DynamoDB, using specified configs.
 /// Returns updated Document in callback
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <param name="callback">An AmazonDynamoCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// <returns>void</returns>
 public void PutItemAsync(Document doc, PutItemOperationConfig config, AmazonDynamoCallback <Document> callback, object state)
 {
     DynamoDBAsyncExecutor.AsyncOperation <Document>(() => PutItemHelper(doc, config, true), "PutItemAsync", callback, state);
 }
コード例 #17
0
ファイル: Table.cs プロジェクト: skilitics/aws-sdk-net
 /// <summary>
 /// Initiates the asynchronous execution of the PutItem operation.
 /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/>
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndPutItem
 ///         operation.</returns>
 public IAsyncResult BeginPutItem(Document doc, PutItemOperationConfig config, AsyncCallback callback, object state)
 {
     return DynamoDBAsyncExecutor.BeginOperation(() => PutItemHelper(doc, config, true), callback, state);
 }
コード例 #18
0
ファイル: Table.cs プロジェクト: rinselmann/aws-sdk-net
        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;
        }
コード例 #19
0
 /// <summary>
 /// Puts a document into DynamoDB, using specified configs.
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <returns>Null or updated attributes, depending on config.</returns>
 internal Document PutItem(Document doc, PutItemOperationConfig config)
 {
     DynamoDBAsyncExecutor.IsMainThread("PutItemAsync");
     return(PutItemHelper(doc, config, false));
 }
コード例 #20
0
ファイル: Table.cs プロジェクト: johnryork/aws-sdk-unity
        internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync)
        {
            var currentConfig = config ?? new PutItemOperationConfig();

            PutItemRequest req = new PutItemRequest
            {
                TableName = TableName,
                Item = doc.ToAttributeMap(Conversion)
            };
            ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)req).AddBeforeRequestHandler(isAsync ?
                new RequestEventHandler(UserAgentRequestEventHandlerAsync) :
                new RequestEventHandler(UserAgentRequestEventHandlerSync));

            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
                req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues);

            ValidateConditional(currentConfig);


            if (currentConfig.Expected != null)
            {
                req.Expected = currentConfig.Expected.ToExpectedAttributeMap(Conversion);
            }
            else if (currentConfig.ExpectedState != null &&
                currentConfig.ExpectedState.ExpectedValues != null &&
                currentConfig.ExpectedState.ExpectedValues.Count > 0)
            {
                req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(Conversion);
                if (req.Expected.Count > 1)
                    req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator);
            }
            else if (currentConfig.ConditionalExpression != null && currentConfig.ConditionalExpression.IsSet)
            {
                currentConfig.ConditionalExpression.ApplyExpression(req, this.Conversion);
            }

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

            Document ret = null;
            if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
            {
                ret = Document.FromAttributeMap(resp.Attributes);
            }
            return ret;
        }
コード例 #21
0
ファイル: Table.Async.cs プロジェクト: rajdotnet/aws-sdk-net
 /// <summary>
 /// Initiates the asynchronous execution of the PutItem operation.
 /// <seealso cref="Amazon.DynamoDBv2.DocumentModel.Table.PutItem"/>
 /// </summary>
 /// <param name="doc">Document to save.</param>
 /// <param name="config">Configuration to use.</param>
 /// <param name="cancellationToken">Token which can be used to cancel the task.</param>
 /// <returns>A Task that can be used to poll or wait for results, or both.</returns>
 public Task<Document> PutItemAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken))
 {
     return AsyncRunner.Run(() => PutItemHelper(doc, config, true), cancellationToken);
 }