Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public abstract class BaseOperationConfig
public DynamoDBEntryConversion Conversion { get; set; }

/// <summary>
/// Contorls how <see cref="DynamoDBContext"/> interprets emptry string values.
/// Controls how <see cref="DynamoDBContext"/> interprets empty string values.
/// If the property is false (or not set), empty string values will be
/// interpreted as null values.
/// </summary>
Expand Down
54 changes: 54 additions & 0 deletions sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGetConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using System;

namespace Amazon.DynamoDBv2.DataModel
{
/// <summary>
/// Input for the BatchGet operation in the object-persistence programming model
/// </summary>
#if NET8_0_OR_GREATER
// The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)]
#endif
public class BatchGetConfig : BaseOperationConfig
{
/// <summary>
/// Property that directs <see cref="DynamoDBContext"/> to use consistent reads.
/// If property is not set, behavior defaults to non-consistent reads.
/// </summary>
public bool? ConsistentRead { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can you add a link to https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html in the property comment. This will helps users exercise better judgment while setting this value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 6895929


/// <summary>
/// If true, all <see cref="DateTime"/> properties are retrieved in UTC timezone while reading data from DynamoDB. Else, the local timezone is used.
/// </summary>
/// <remarks>
/// This setting is only applicable to the high-level library. Service calls made via
/// <see cref="AmazonDynamoDBClient"/> will always return <see cref="DateTime"/> attributes in UTC.
/// </remarks>
public bool? RetrieveDateTimeInUtc { get; set; }

/// <inheritdoc/>
internal override DynamoDBOperationConfig ToDynamoDBOperationConfig()
{
var config = base.ToDynamoDBOperationConfig();
config.ConsistentRead = ConsistentRead;
config.RetrieveDateTimeInUtc = RetrieveDateTimeInUtc;

return config;
}
}
}
52 changes: 52 additions & 0 deletions sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWriteConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

namespace Amazon.DynamoDBv2.DataModel
{
/// <summary>
/// Input for the BatchWrite operation in the object-persistence programming model
/// </summary>
#if NET8_0_OR_GREATER
// The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)]
#endif
public class BatchWriteConfig : BaseOperationConfig
{
/// <summary>
/// Property that directs <see cref="DynamoDBContext"/> to skip version checks
/// when saving or deleting an object with a version attribute.
/// If property is not set, version checks are performed.
/// </summary>
public bool? SkipVersionCheck { get; set; }

/// <summary>
/// Directs <see cref="DynamoDBContext" /> to ignore null values when
/// converting an object to a DynamoDB item. If the property is false
/// (or not set), null values will be interpreted as directives to
/// delete the specific attributes on the DynamoDB item.
/// </summary>
public bool? IgnoreNullValues { get; set; }

/// <inheritdoc/>
internal override DynamoDBOperationConfig ToDynamoDBOperationConfig()
{
var config = base.ToDynamoDBOperationConfig();
config.SkipVersionCheck = SkipVersionCheck;
config.IgnoreNullValues = IgnoreNullValues;

return config;
}
}
}
99 changes: 92 additions & 7 deletions sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#if AWS_ASYNC_API
using System.Threading.Tasks;
#endif
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DocumentModel;

namespace Amazon.DynamoDBv2.DataModel
Expand Down Expand Up @@ -208,7 +207,7 @@ public void Dispose()

#endregion

#region Factory Creates
#region BatchGet

/// <summary>
/// Creates a strongly-typed BatchGet object, allowing
Expand All @@ -218,7 +217,7 @@ public void Dispose()
/// <returns>Empty strongly-typed BatchGet object</returns>
public BatchGet<T> CreateBatchGet<T>()
{
return CreateBatchGet<T>(null);
return CreateBatchGet<T>((BatchGetConfig)null);
}

/// <summary>
Expand All @@ -228,12 +227,25 @@ public BatchGet<T> CreateBatchGet<T>()
/// <typeparam name="T">Type of objects to get</typeparam>
/// <param name="operationConfig">Config object which can be used to override that table used.</param>
/// <returns>Empty strongly-typed BatchGet object</returns>
[Obsolete("Use the CreateBatchGet overload that takes BatchGetConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchGet.")]
public BatchGet<T> CreateBatchGet<T>(DynamoDBOperationConfig operationConfig)
{
DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config);
return new BatchGet<T>(this, config);
}

/// <summary>
/// Creates a strongly-typed BatchGet object, allowing
/// a batch-get operation against DynamoDB.
/// </summary>
/// <typeparam name="T">Type of objects to get</typeparam>
/// <param name="batchGetConfig">Config object that can be used to override properties on the table's context for this request</param>
/// <returns>Empty strongly-typed BatchGet object</returns>
public BatchGet<T> CreateBatchGet<T>(BatchGetConfig batchGetConfig)
{
return new BatchGet<T>(this, new DynamoDBFlatConfig(batchGetConfig?.ToDynamoDBOperationConfig(), Config));
}

/// <summary>
/// Creates a MultiTableBatchGet object, composed of multiple
/// individual BatchGet objects.
Expand All @@ -245,6 +257,10 @@ public MultiTableBatchGet CreateMultiTableBatchGet(params BatchGet[] batches)
return new MultiTableBatchGet(batches);
}

#endregion

#region BatchWrite

/// <summary>
/// Creates a strongly-typed BatchWrite object, allowing
/// a batch-write operation against DynamoDB.
Expand All @@ -253,7 +269,7 @@ public MultiTableBatchGet CreateMultiTableBatchGet(params BatchGet[] batches)
/// <returns>Empty strongly-typed BatchWrite object</returns>
public BatchWrite<T> CreateBatchWrite<T>()
{
return CreateBatchWrite<T>(null);
return CreateBatchWrite<T>((BatchWriteConfig)null);
}

/// <summary>
Expand All @@ -263,6 +279,7 @@ public BatchWrite<T> CreateBatchWrite<T>()
/// <typeparam name="T">Type of objects to write</typeparam>
/// <param name="operationConfig">Config object which can be used to override that table used.</param>
/// <returns>Empty strongly-typed BatchWrite object</returns>
[Obsolete("Use the CreateBatchWrite overload that takes BatchWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchWrite.")]
public BatchWrite<T> CreateBatchWrite<T>(DynamoDBOperationConfig operationConfig)
{
DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config);
Expand All @@ -283,7 +300,7 @@ public BatchWrite<T> CreateBatchWrite<T>(DynamoDBOperationConfig operationConfig
/// <returns>Empty strongly-typed BatchWrite object</returns>
public BatchWrite<object> CreateBatchWrite(Type valuesType)
{
return CreateBatchWrite(valuesType, null);
return CreateBatchWrite(valuesType, (BatchWriteConfig)null);
}

/// <summary>
Expand All @@ -299,12 +316,43 @@ public BatchWrite<object> CreateBatchWrite(Type valuesType)
/// <param name="valuesType">Type of objects to write</param>
/// <param name="operationConfig">Config object which can be used to override that table used.</param>
/// <returns>Empty strongly-typed BatchWrite object</returns>
[Obsolete("Use the CreateBatchWrite overload that takes BatchWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchWrite.")]
public BatchWrite<object> CreateBatchWrite(Type valuesType, DynamoDBOperationConfig operationConfig)
{
DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config);
return new BatchWrite<object>(this, valuesType, config);
}

/// <summary>
/// Creates a strongly-typed BatchWrite object, allowing
/// a batch-write operation against DynamoDB.
/// </summary>
/// <typeparam name="T">Type of objects to write</typeparam>
/// <param name="batchWriteConfig">Config object that can be used to override properties on the table's context for this request.</param>
/// <returns>Empty strongly-typed BatchWrite object</returns>
public BatchWrite<T> CreateBatchWrite<T>(BatchWriteConfig batchWriteConfig)
{
return new BatchWrite<T>(this, new DynamoDBFlatConfig(batchWriteConfig?.ToDynamoDBOperationConfig(), Config));
}

/// <summary>
/// Creates a strongly-typed BatchWrite object, allowing
/// a batch-write operation against DynamoDB.
///
/// This is intended for use only when the valuesType is not known at compile-time, for example,
/// when hooking into EF's ChangeTracker to record audit logs from EF into DynamoDB.
///
/// In scenarios when the valuesType is known at compile-time, the
/// <see cref="CreateBatchWrite{T}(DynamoDBOperationConfig)"/> method is generally preferred.
/// </summary>
/// <param name="valuesType">The type of data which will be persisted in this batch.</param>
/// <param name="batchWriteConfig">Config object that can be used to override properties on the table's context for this request.</param>
/// <returns>Empty strongly-typed BatchWrite object</returns>
public BatchWrite<object> CreateBatchWrite(Type valuesType, BatchWriteConfig batchWriteConfig)
{
return new BatchWrite<object>(this, valuesType, new DynamoDBFlatConfig(batchWriteConfig.ToDynamoDBOperationConfig(), Config));
}

/// <summary>
/// Creates a MultiTableBatchWrite object, composed of multiple
/// individual BatchWrite objects.
Expand All @@ -316,6 +364,10 @@ public MultiTableBatchWrite CreateMultiTableBatchWrite(params BatchWrite[] batch
return new MultiTableBatchWrite(batches);
}

#endregion

#region TransactGet

/// <summary>
/// Creates a strongly-typed TransactGet object, allowing
/// a transactional get operation against DynamoDB.
Expand All @@ -324,7 +376,7 @@ public MultiTableBatchWrite CreateMultiTableBatchWrite(params BatchWrite[] batch
/// <returns>Empty strongly-typed TransactGet object.</returns>
public TransactGet<T> CreateTransactGet<T>()
{
return CreateTransactGet<T>(null);
return CreateTransactGet<T>((TransactGetConfig)null);
}

/// <summary>
Expand All @@ -334,12 +386,26 @@ public TransactGet<T> CreateTransactGet<T>()
/// <typeparam name="T">Type of objects to get.</typeparam>
/// <param name="operationConfig">Config object which can be used to override that table used.</param>
/// <returns>Empty strongly-typed TransactGet object.</returns>
[Obsolete("Use the CreateTransactGet overload that takes TransactGetConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchGet.")]
public TransactGet<T> CreateTransactGet<T>(DynamoDBOperationConfig operationConfig)
{
DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config);
return new TransactGet<T>(this, config);
}

/// <summary>
/// Creates a strongly-typed TransactGet object, allowing
/// a transactional get operation against DynamoDB.
/// </summary>
/// <typeparam name="T">Type of objects to get.</typeparam>
/// <param name="transactGetConfig">Config object that can be used to override properties on the table's context for this request.</param>
/// <returns>Empty strongly-typed TransactGet object.</returns>
public TransactGet<T> CreateTransactGet<T>(TransactGetConfig transactGetConfig)
{
DynamoDBFlatConfig config = new DynamoDBFlatConfig(transactGetConfig?.ToDynamoDBOperationConfig(), this.Config);
return new TransactGet<T>(this, config);
}

/// <summary>
/// Creates a MultiTableTransactGet object, composed of multiple
/// individual TransactGet objects.
Expand All @@ -351,6 +417,10 @@ public MultiTableTransactGet CreateMultiTableTransactGet(params TransactGet[] tr
return new MultiTableTransactGet(transactionParts);
}

#endregion

#region TransactWrite

/// <summary>
/// Creates a strongly-typed TransactWrite object, allowing
/// a transactional write operation against DynamoDB.
Expand All @@ -359,7 +429,7 @@ public MultiTableTransactGet CreateMultiTableTransactGet(params TransactGet[] tr
/// <returns>Empty strongly-typed TransactWrite object.</returns>
public TransactWrite<T> CreateTransactWrite<T>()
{
return CreateTransactWrite<T>(null);
return CreateTransactWrite<T>((TransactWriteConfig)null);
}

/// <summary>
Expand All @@ -369,12 +439,27 @@ public TransactWrite<T> CreateTransactWrite<T>()
/// <typeparam name="T">Type of objects to write.</typeparam>
/// <param name="operationConfig">Config object which can be used to override that table used.</param>
/// <returns>Empty strongly-typed TransactWrite object.</returns>

[Obsolete("Use the CreateTransactWrite overload that takes TransactWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to CreateTransactWrite.")]
public TransactWrite<T> CreateTransactWrite<T>(DynamoDBOperationConfig operationConfig)
{
DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config);
return new TransactWrite<T>(this, config);
}

/// <summary>
/// Creates a strongly-typed TransactWrite object, allowing
/// a transactional write operation against DynamoDB.
/// </summary>
/// <typeparam name="T">Type of objects to write.</typeparam>
/// <param name="transactWriteConfig">Config object that can be used to override properties on the table's context for this request.</param>
/// <returns>Empty strongly-typed TransactWrite object.</returns>
public TransactWrite<T> CreateTransactWrite<T>(TransactWriteConfig transactWriteConfig)
{
DynamoDBFlatConfig config = new DynamoDBFlatConfig(transactWriteConfig?.ToDynamoDBOperationConfig(), this.Config);
return new TransactWrite<T>(this, config);
}

/// <summary>
/// Creates a MultiTableTransactWrite object, composed of multiple
/// individual TransactWrite objects.
Expand Down
Loading