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; }
/// <summary> /// Initiates the asynchronous execution of the PutItem operation. /// <seealso cref="Amazon.DynamoDB.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); }
/// <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, false); }
// 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; }