Skip to content

Commit d0738c2

Browse files
committed
Create separate operation-specific configs for the object-persistence Scan and Query operations (#3383)
1 parent 682a41b commit d0738c2

File tree

12 files changed

+861
-168
lines changed

12 files changed

+861
-168
lines changed

sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextInternal.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ private static bool ShouldSave(DynamoDBEntry entry, bool ignoreNullValues)
331331
throw new InvalidOperationException("Unrecognized DynamoDBEntry object");
332332
}
333333

334-
// Deserializing DynamoDB document into an object
334+
/// <summary>
335+
/// Deserializes a DynamoDB document to an object
336+
/// </summary>
335337
private T DocumentToObject<T>(ItemStorage storage, DynamoDBFlatConfig flatConfig)
336338
{
337339
Type type = typeof(T);
@@ -392,7 +394,9 @@ private void PopulateInstance(ItemStorage storage, object instance, DynamoDBFlat
392394
}
393395
}
394396

395-
// Serializing an object into a DynamoDB document
397+
/// <summary>
398+
/// Serializes an object into a DynamoDB document
399+
/// </summary>
396400
private ItemStorage ObjectToItemStorage<T>(T toStore, bool keysOnly, DynamoDBFlatConfig flatConfig)
397401
{
398402
if (toStore == null) return null;
@@ -769,8 +773,10 @@ private static bool IsSupportedDictionaryType(Type type, out Type keyType, out T
769773
return true;
770774
}
771775

772-
// Deserializes a given Document to instance of targetType
773-
// Use only for property conversions, not for full item conversion
776+
/// <summary>
777+
/// Deserializes a given Document to instance of targetType
778+
/// Use only for property conversions, not for full item conversion
779+
/// </summary>
774780
private object DeserializeFromDocument(Document document, Type targetType, DynamoDBFlatConfig flatConfig)
775781
{
776782
ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(targetType, flatConfig, conversionOnly: true);
@@ -779,8 +785,11 @@ private object DeserializeFromDocument(Document document, Type targetType, Dynam
779785
object value = DocumentToObject(targetType, storage, flatConfig);
780786
return value;
781787
}
782-
// Serializes a given value to Document
783-
// Use only for property conversions, not for full item conversion
788+
789+
/// <summary>
790+
/// Serializes a given value to Document
791+
/// Use only for property conversions, not for full item conversion
792+
/// </summary>
784793
private Document SerializeToDocument(object value, Type type, DynamoDBFlatConfig flatConfig)
785794
{
786795
ItemStorageConfig config = StorageConfigCache.GetConfig(type, flatConfig, conversionOnly: true);
@@ -789,7 +798,9 @@ private Document SerializeToDocument(object value, Type type, DynamoDBFlatConfig
789798
return doc;
790799
}
791800

792-
// Get/Set object properties
801+
/// <summary>
802+
/// Get/Set object properties
803+
/// </summary>
793804
private static bool TrySetValue(object instance, MemberInfo member, object value)
794805
{
795806
FieldInfo fieldInfo = member as FieldInfo;
@@ -832,7 +843,9 @@ private static bool TryGetValue(object instance, MemberInfo member, out object v
832843
}
833844
}
834845

835-
// Query/Scan building
846+
/// <summary>
847+
/// Query/Scan building
848+
/// </summary>
836849
private ScanFilter ComposeScanFilter(IEnumerable<ScanCondition> conditions, ItemStorageConfig storageConfig, DynamoDBFlatConfig flatConfig)
837850
{
838851
ScanFilter filter = new ScanFilter();
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
using Amazon.DynamoDBv2.DocumentModel;
17+
using System;
18+
using System.Collections.Generic;
19+
20+
namespace Amazon.DynamoDBv2.DataModel
21+
{
22+
/// <summary>
23+
/// Input for the Query operation in the object-persistence programming model
24+
/// </summary>
25+
#if NET8_0_OR_GREATER
26+
// The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible
27+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)]
28+
#endif
29+
public class QueryConfig : BaseOperationConfig
30+
{
31+
/// <summary>
32+
/// Indicates whether a query should traverse the index backwards in descending order by range key value.
33+
/// If the property is false (or not set), traversal shall be in ascending order.
34+
/// </summary>
35+
public bool? BackwardQuery { get; set; }
36+
37+
/// <summary>
38+
/// Indicates the name of the index to query against.
39+
/// This value is optional if the index name can be inferred from the call.
40+
/// </summary>
41+
public string IndexName { get; set; }
42+
43+
/// <summary>
44+
/// The logical operator to apply to the filter conditions.
45+
/// </summary>
46+
/// <remarks>
47+
/// <list type="bullet">
48+
/// <item>
49+
/// <term><see cref="ConditionalOperatorValues.And" /></term>
50+
/// <definition>If all of the conditions evaluate to true, then the entire filter evaluates to true.</definition>
51+
/// </item>
52+
/// <item>
53+
/// <term><see cref="ConditionalOperatorValues.Or" /></term>
54+
/// <definition>If at least one of the conditions evaluate to true, then the entire filter evaluates to true.</definition>
55+
/// </item>
56+
/// </list>
57+
/// The default value is <see cref="ConditionalOperatorValues.And" />.
58+
/// </remarks>
59+
public ConditionalOperatorValues ConditionalOperator { get; set; }
60+
61+
/// <summary>
62+
/// Query filter for the Query operation. Evaluates the query results and returns only
63+
/// the matching values. If you specify more than one condition, then by default all of the
64+
/// conditions must evaluate to true. To match only some conditions, set <see cref="ConditionalOperator"/> to <see cref="ConditionalOperatorValues.Or" />.
65+
/// </summary>
66+
/// <remarks>
67+
/// Note: Conditions must be against non-key properties.
68+
/// </remarks>
69+
public List<ScanCondition> QueryFilter { get; set; }
70+
71+
/// <summary>
72+
/// Property that directs <see cref="DynamoDBContext" /> to use consistent reads.
73+
/// If property is not set, behavior defaults to non-consistent reads.
74+
/// </summary>
75+
/// <remarks>
76+
/// Refer to the <see href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html">
77+
/// Read Consistency</see> topic in the DynamoDB Developer Guide for more information.
78+
/// </remarks>
79+
public bool? ConsistentRead { get; set; }
80+
81+
/// <summary>
82+
/// If true, all <see cref="DateTime"/> properties are retrieved in UTC timezone while reading data from DynamoDB. Else, the local timezone is used.
83+
/// </summary>
84+
/// <remarks>
85+
/// This setting is only applicable to the high-level library. Service calls made via
86+
/// <see cref="AmazonDynamoDBClient"/> will always return <see cref="DateTime"/> attributes in UTC.
87+
/// </remarks>
88+
public bool? RetrieveDateTimeInUtc { get; set; }
89+
90+
/// <inheritdoc/>
91+
internal override DynamoDBOperationConfig ToDynamoDBOperationConfig()
92+
{
93+
var config = base.ToDynamoDBOperationConfig();
94+
config.BackwardQuery = BackwardQuery;
95+
config.IndexName = IndexName;
96+
config.ConditionalOperator = ConditionalOperator;
97+
config.QueryFilter = QueryFilter;
98+
config.ConsistentRead = ConsistentRead;
99+
config.RetrieveDateTimeInUtc = RetrieveDateTimeInUtc;
100+
101+
return config;
102+
}
103+
}
104+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
using Amazon.DynamoDBv2.DocumentModel;
17+
using System;
18+
using System.Collections.Generic;
19+
20+
namespace Amazon.DynamoDBv2.DataModel
21+
{
22+
/// <summary>
23+
/// Input for the Scan operation in the object-persistence programming model
24+
/// </summary>
25+
#if NET8_0_OR_GREATER
26+
// The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible
27+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)]
28+
#endif
29+
public class ScanConfig : BaseOperationConfig
30+
{
31+
/// <summary>
32+
/// Indicates the name of the index to scan against.
33+
/// This value is optional if the index name can be inferred from the call.
34+
/// </summary>
35+
public string IndexName { get; set; }
36+
37+
/// <summary>
38+
/// The logical operator to apply to the filter conditions.
39+
/// </summary>
40+
/// <remarks>
41+
/// <list type="bullet">
42+
/// <item>
43+
/// <term><see cref="ConditionalOperatorValues.And" /></term>
44+
/// <definition>If all of the conditions evaluate to true, then the entire filter evaluates to true.</definition>
45+
/// </item>
46+
/// <item>
47+
/// <term><see cref="ConditionalOperatorValues.Or" /></term>
48+
/// <definition>If at least one of the conditions evaluate to true, then the entire filter evaluates to true.</definition>
49+
/// </item>
50+
/// </list>
51+
/// The default value is <see cref="ConditionalOperatorValues.And" />.
52+
/// </remarks>
53+
public ConditionalOperatorValues ConditionalOperator { get; set; }
54+
55+
/// <summary>
56+
/// Filter for the Scan operation. Evaluates the query results and returns only
57+
/// the matching values. If you specify more than one condition, then by default all of the
58+
/// conditions must evaluate to true. To match only some conditions, set <see cref="ConditionalOperator"/> to <see cref="ConditionalOperatorValues.Or" />.
59+
/// </summary>
60+
/// <remarks>
61+
/// Note: Conditions must be against non-key properties.
62+
/// </remarks>
63+
public List<ScanCondition> QueryFilter { get; set; }
64+
65+
/// <summary>
66+
/// Property that directs <see cref="DynamoDBContext" /> to use consistent reads.
67+
/// If property is not set, behavior defaults to non-consistent reads.
68+
/// </summary>
69+
/// <remarks>
70+
/// Refer to the <see href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html">
71+
/// Read Consistency</see> topic in the DynamoDB Developer Guide for more information.
72+
/// </remarks>
73+
public bool? ConsistentRead { get; set; }
74+
75+
/// <summary>
76+
/// If true, all <see cref="DateTime"/> properties are retrieved in UTC timezone while reading data from DynamoDB. Else, the local timezone is used.
77+
/// </summary>
78+
/// <remarks>
79+
/// This setting is only applicable to the high-level library. Service calls made via
80+
/// <see cref="AmazonDynamoDBClient"/> will always return <see cref="DateTime"/> attributes in UTC.
81+
/// </remarks>
82+
public bool? RetrieveDateTimeInUtc { get; set; }
83+
84+
/// <inheritdoc/>
85+
internal override DynamoDBOperationConfig ToDynamoDBOperationConfig()
86+
{
87+
var config = base.ToDynamoDBOperationConfig();
88+
config.IndexName = IndexName;
89+
config.ConditionalOperator = ConditionalOperator;
90+
config.QueryFilter = QueryFilter;
91+
config.ConsistentRead = ConsistentRead;
92+
config.RetrieveDateTimeInUtc = RetrieveDateTimeInUtc;
93+
94+
return config;
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)