|
13 | 13 | * permissions and limitations under the License. |
14 | 14 | */ |
15 | 15 |
|
16 | | -using System; |
17 | | - |
| 16 | +using Amazon.DynamoDBv2.DataModel; |
18 | 17 | using Amazon.DynamoDBv2.Model; |
19 | | -using Amazon.Runtime; |
20 | | -using Amazon.Util; |
| 18 | +using Amazon.Runtime.Internal.UserAgent; |
| 19 | +using Amazon.Runtime.Internal.Util; |
| 20 | +using Amazon.Runtime.Telemetry.Tracing; |
| 21 | +using System; |
| 22 | +using System.Collections.Generic; |
| 23 | +using System.Globalization; |
21 | 24 | using System.Linq; |
| 25 | +using System.Linq.Expressions; |
22 | 26 | using System.Threading; |
23 | 27 | using System.Threading.Tasks; |
24 | | -using System.Collections.Generic; |
25 | | -using System.Globalization; |
26 | | -using Amazon.DynamoDBv2.DataModel; |
27 | | -using Amazon.Runtime.Internal.Util; |
28 | | -using Amazon.Runtime.Telemetry.Tracing; |
29 | | -using Amazon.Runtime.Internal.UserAgent; |
30 | 28 |
|
31 | 29 | namespace Amazon.DynamoDBv2.DocumentModel |
32 | 30 | { |
@@ -1362,6 +1360,82 @@ internal Task<Document> UpdateHelperAsync(Document doc, Primitive hashKey, Primi |
1362 | 1360 | return UpdateHelperAsync(doc, key, config, expression, cancellationToken); |
1363 | 1361 | } |
1364 | 1362 |
|
| 1363 | + //internal async Task<Document> UpdateHelperAsync(UpdateItemDocumentOperationRequest request, |
| 1364 | + // CancellationToken cancellationToken) |
| 1365 | + //{ |
| 1366 | + // if (request == null) |
| 1367 | + // throw new ArgumentNullException(nameof(request)); |
| 1368 | + |
| 1369 | + // var doc = request.Document; |
| 1370 | + |
| 1371 | + // Expression updateExpression = request.UpdateExpression; |
| 1372 | + |
| 1373 | + // // Validate that either doc or updateExpression is set, but not both null or both set to non-meaningful values |
| 1374 | + // if ((doc == null && (updateExpression == null || !updateExpression.IsSet)) || |
| 1375 | + // (doc != null && updateExpression != null && updateExpression.IsSet)) |
| 1376 | + // { |
| 1377 | + // throw new ArgumentException("Either Document or UpdateExpression must be set in the request.", |
| 1378 | + // nameof(request)); |
| 1379 | + // } |
| 1380 | + |
| 1381 | + // Key key = request.Key != null ? MakeKey(request.Key) : null; |
| 1382 | + |
| 1383 | + // if(doc!=null) |
| 1384 | + // { |
| 1385 | + // key ??= MakeKey(doc); |
| 1386 | + // bool haveKeysChanged = HaveKeysChanged(doc); |
| 1387 | + // bool updateChangedAttributesOnly = !haveKeysChanged; |
| 1388 | + // var attributeUpdates = this.ToAttributeUpdateMap(doc, updateChangedAttributesOnly); |
| 1389 | + // foreach (var keyName in this.KeyNames) |
| 1390 | + // { |
| 1391 | + // attributeUpdates.Remove(keyName); |
| 1392 | + // } |
| 1393 | + // //todo build update expression from attributeUpdates |
| 1394 | + // string statement; |
| 1395 | + // Dictionary<string, AttributeValue> expressionAttributeValues; |
| 1396 | + // Dictionary<string, string> expressionAttributeNames; |
| 1397 | + |
| 1398 | + // Common.ConvertAttributeUpdatesToUpdateExpression(attributeUpdates, updateExpression, this, |
| 1399 | + // out statement, out expressionAttributeValues, out expressionAttributeNames); |
| 1400 | + |
| 1401 | + // //updateExpression = new Expression |
| 1402 | + // //{ |
| 1403 | + // // ExpressionStatement = statement, |
| 1404 | + // // ExpressionAttributeValues = expressionAttributeValues, |
| 1405 | + // // ExpressionAttributeNames = expressionAttributeNames |
| 1406 | + // //}; |
| 1407 | + // } |
| 1408 | + |
| 1409 | + // if (key == null || key.Count == 0) |
| 1410 | + // { |
| 1411 | + // throw new InvalidOperationException( |
| 1412 | + // "UpdateItem requires a key to be specified either in the request or in the Document."); |
| 1413 | + // } |
| 1414 | + |
| 1415 | + // UpdateItemRequest req = new UpdateItemRequest |
| 1416 | + // { |
| 1417 | + // TableName = TableName, |
| 1418 | + // Key = key, |
| 1419 | + // ReturnValues = EnumMapper.Convert(request.ReturnValues) |
| 1420 | + // }; |
| 1421 | + // request.UpdateExpression.ApplyExpression(req, this); |
| 1422 | + // request.ConditionalExpression?.ApplyExpression(req, this); |
| 1423 | + |
| 1424 | + // this.UpdateRequestUserAgentDetails(req, isAsync: true); |
| 1425 | + |
| 1426 | + // var resp = await DDBClient.UpdateItemAsync(req, cancellationToken).ConfigureAwait(false); |
| 1427 | + // var returnedAttributes = resp.Attributes; |
| 1428 | + // doc.CommitChanges(); |
| 1429 | + |
| 1430 | + // Document ret = null; |
| 1431 | + // if (request.ReturnValues != ReturnValues.None) |
| 1432 | + // { |
| 1433 | + // ret = this.FromAttributeMap(returnedAttributes); |
| 1434 | + // } |
| 1435 | + |
| 1436 | + // return ret; |
| 1437 | + //} |
| 1438 | + |
1365 | 1439 | internal Document UpdateHelper(Document doc, Key key, UpdateItemOperationConfig config, Expression updateExpression) |
1366 | 1440 | { |
1367 | 1441 | var currentConfig = config ?? new UpdateItemOperationConfig(); |
@@ -1809,7 +1883,8 @@ public IDocumentTransactWrite CreateTransactWrite() |
1809 | 1883 | { |
1810 | 1884 | return new DocumentTransactWrite(this); |
1811 | 1885 | } |
1812 | | - |
| 1886 | + // Add this private method to the Table class |
1813 | 1887 | #endregion |
| 1888 | + |
1814 | 1889 | } |
1815 | 1890 | } |
0 commit comments