Skip to content

Commit c4e2519

Browse files
authored
Separate DynamoDBOperationConfig Into Operation-Specific Configs (#3421)
1 parent 0c5879b commit c4e2519

28 files changed

+2670
-720
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
namespace Amazon.DynamoDBv2.DataModel
17+
{
18+
/// <summary>
19+
/// Base class for operation-specific configurations for DynamoDB object persistence operations.
20+
/// </summary>
21+
/// <remarks>
22+
/// This should only contain members that are relevant to all object persistence operations,
23+
/// anything operation-specific should be added to derived classes.
24+
/// </remarks>
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 abstract class BaseOperationConfig
30+
{
31+
/// <summary>
32+
/// Indicates which DynamoDB table to use. This overrides the table specified
33+
/// by the <see cref="DynamoDBTableAttribute"/> on the .NET objects that you're saving or loading.
34+
/// </summary>
35+
public string OverrideTableName { get; set; }
36+
37+
/// <summary>
38+
/// Directs <see cref="DynamoDBContext"/> to prefix all table names
39+
/// with a specific string. If this is null or empty, no prefix is used
40+
/// and default table names are used.
41+
/// </summary>
42+
public string TableNamePrefix { get; set; }
43+
44+
/// <summary>
45+
/// The object persistence model API relies on an internal cache of the DynamoDB table's metadata to
46+
/// construct and validate requests. This controls how the cache key is derived, which influences
47+
/// when the SDK will call DescribeTable internally to populate the cache.
48+
/// </summary>
49+
/// <remarks>
50+
/// For <see cref="MetadataCachingMode.Default"/> the cache key will be a combination of the table name, credentials, region and service URL.
51+
/// For <see cref="MetadataCachingMode.TableNameOnly"/> the cache key will only consist of the table name. This reduces cache misses in contexts
52+
/// where you are accessing tables with identical structure but using different credentials or endpoints (such as a multi-tenant application).
53+
/// </remarks>
54+
public MetadataCachingMode? MetadataCachingMode { get; set; }
55+
56+
/// <summary>
57+
/// If true disables fetching table metadata automatically from DynamoDB. Table metadata must be
58+
/// defined by <see cref="DynamoDBAttribute"/> attributes and/or in <see cref = "AWSConfigsDynamoDB"/>.
59+
/// </summary>
60+
/// <remarks>
61+
/// Setting this to true can avoid latency and thread starvation due to blocking asynchronous
62+
/// DescribeTable calls that are used to populate the SDK's cache of table metadata.
63+
/// It requires that the table's index schema be accurately described via the above methods,
64+
/// otherwise exceptions may be thrown and/or the results of certain DynamoDB operations may change.
65+
/// </remarks>
66+
public bool? DisableFetchingTableMetadata { get; set; }
67+
68+
/// <summary>
69+
/// Specification which controls the conversion between .NET and DynamoDB types.
70+
/// </summary>
71+
public DynamoDBEntryConversion Conversion { get; set; }
72+
73+
/// <summary>
74+
/// Controls how <see cref="DynamoDBContext"/> interprets empty string values.
75+
/// If the property is false (or not set), empty string values will be
76+
/// interpreted as null values.
77+
/// </summary>
78+
public bool? IsEmptyStringValueEnabled { get; set; }
79+
80+
/// <summary>
81+
/// Converts this to the shared <see cref="DynamoDBOperationConfig"/>
82+
/// </summary>
83+
/// <remarks>
84+
/// Users should interact with the new, operation-specific configs, but we
85+
/// convert to the internal shared config for the internal code paths.
86+
/// </remarks>
87+
/// <returns>A new <see cref="DynamoDBOperationConfig"/> with settings copied from the operation-specific config</returns>
88+
internal virtual DynamoDBOperationConfig ToDynamoDBOperationConfig()
89+
{
90+
return new DynamoDBOperationConfig()
91+
{
92+
OverrideTableName = OverrideTableName,
93+
TableNamePrefix = TableNamePrefix,
94+
MetadataCachingMode = MetadataCachingMode,
95+
DisableFetchingTableMetadata = DisableFetchingTableMetadata,
96+
Conversion = Conversion,
97+
IsEmptyStringValueEnabled = IsEmptyStringValueEnabled
98+
};
99+
}
100+
}
101+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 System;
17+
18+
namespace Amazon.DynamoDBv2.DataModel
19+
{
20+
/// <summary>
21+
/// Input for the BatchGet operation in the object-persistence programming model
22+
/// </summary>
23+
#if NET8_0_OR_GREATER
24+
// The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible
25+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)]
26+
#endif
27+
public class BatchGetConfig : BaseOperationConfig
28+
{
29+
/// <summary>
30+
/// Property that directs <see cref="DynamoDBContext"/> to use consistent reads.
31+
/// If property is not set, behavior defaults to non-consistent reads.
32+
/// </summary>
33+
/// <remarks>
34+
/// Refer to the <see href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html">
35+
/// Read Consistency</see> topic in the DynamoDB Developer Guide for more information.
36+
/// </remarks>
37+
public bool? ConsistentRead { get; set; }
38+
39+
/// <summary>
40+
/// If true, all <see cref="DateTime"/> properties are retrieved in UTC timezone while reading data from DynamoDB. Else, the local timezone is used.
41+
/// </summary>
42+
/// <remarks>
43+
/// This setting is only applicable to the high-level library. Service calls made via
44+
/// <see cref="AmazonDynamoDBClient"/> will always return <see cref="DateTime"/> attributes in UTC.
45+
/// </remarks>
46+
public bool? RetrieveDateTimeInUtc { get; set; }
47+
48+
/// <inheritdoc/>
49+
internal override DynamoDBOperationConfig ToDynamoDBOperationConfig()
50+
{
51+
var config = base.ToDynamoDBOperationConfig();
52+
config.ConsistentRead = ConsistentRead;
53+
config.RetrieveDateTimeInUtc = RetrieveDateTimeInUtc;
54+
55+
return config;
56+
}
57+
}
58+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
namespace Amazon.DynamoDBv2.DataModel
17+
{
18+
/// <summary>
19+
/// Input for the BatchWrite operation in the object-persistence programming model
20+
/// </summary>
21+
#if NET8_0_OR_GREATER
22+
// The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible
23+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)]
24+
#endif
25+
public class BatchWriteConfig : BaseOperationConfig
26+
{
27+
/// <summary>
28+
/// Property that directs <see cref="DynamoDBContext"/> to skip version checks
29+
/// when saving or deleting an object with a version attribute.
30+
/// If property is not set, version checks are performed.
31+
/// </summary>
32+
public bool? SkipVersionCheck { get; set; }
33+
34+
/// <summary>
35+
/// Directs <see cref="DynamoDBContext" /> to ignore null values when
36+
/// converting an object to a DynamoDB item. If the property is false
37+
/// (or not set), null values will be interpreted as directives to
38+
/// delete the specific attributes on the DynamoDB item.
39+
/// </summary>
40+
public bool? IgnoreNullValues { get; set; }
41+
42+
/// <inheritdoc/>
43+
internal override DynamoDBOperationConfig ToDynamoDBOperationConfig()
44+
{
45+
var config = base.ToDynamoDBOperationConfig();
46+
config.SkipVersionCheck = SkipVersionCheck;
47+
config.IgnoreNullValues = IgnoreNullValues;
48+
49+
return config;
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)