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); }
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); }
internal Document PutItemHelper(Document doc, PutItemOperationConfig config) { var currentConfig = config ?? new PutItemOperationConfig(); PutItemRequest req = new PutItemRequest { TableName = TableName, Item = this.ToAttributeMap(doc) }; this.AddRequestHandler(req, isAsync: false); 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 = DDBClient.PutItem(req); doc.CommitChanges(); Document ret = null; if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes) { ret = this.FromAttributeMap(resp.Attributes); } return(ret); }
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); }