diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/AsyncSearch.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/AsyncSearch.cs
index e08008c8dc50..159c1281be09 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/AsyncSearch.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/AsyncSearch.cs
@@ -13,18 +13,38 @@
* permissions and limitations under the License.
*/
-using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DocumentModel;
namespace Amazon.DynamoDBv2.DataModel
{
+ ///
+ /// Interface retrieving search results (Query or Scan)
+ /// from DynamoDB.
+ ///
+ public partial interface IAsyncSearch
+ {
+ ///
+ /// Flag that, if true, indicates that the search is done
+ ///
+ bool IsDone { get; }
+
+ ///
+ /// Pagination token corresponding to the item where the search operation stopped,
+ /// inclusive of the previous result set. Use this value to start a new
+ /// operation to resume search from the next item.
+ ///
+ string PaginationToken { get; }
+ }
+
///
/// A strongly-typed object for retrieving search results (Query or Scan)
/// from DynamoDB.
///
- public partial class AsyncSearch
+ public partial class AsyncSearch : IAsyncSearch
{
- #region Constructor
+ private Search _documentSearch { get; set; }
+ private DynamoDBContext _sourceContext { get; set; }
+ private DynamoDBFlatConfig _config { get; set; }
///
/// This constructor is used for mocking. Users that want to mock AsyncSearch can create a subclass of AsyncSearch and make a public parameterless constructor.
@@ -36,47 +56,27 @@ protected AsyncSearch()
internal AsyncSearch(DynamoDBContext source, DynamoDBContext.ContextSearch contextSearch)
{
- SourceContext = source;
- DocumentSearch = contextSearch.Search;
- Config = contextSearch.FlatConfig;
+ _sourceContext = source;
+ _documentSearch = contextSearch.Search;
+ _config = contextSearch.FlatConfig;
}
- #endregion
-
- #region Private members
-
- private Search DocumentSearch { get; set; }
- private DynamoDBContext SourceContext { get; set; }
- private DynamoDBFlatConfig Config { get; set; }
-
- #endregion
-
- #region Public properties
-
- ///
- /// Flag that, if true, indicates that the search is done
- ///
+ ///
public virtual bool IsDone
{
get
{
- return DocumentSearch.IsDone;
+ return _documentSearch.IsDone;
}
}
- ///
- /// Pagination token corresponding to the item where the search operation stopped,
- /// inclusive of the previous result set. Use this value to start a new
- /// operation to resume search from the next item.
- ///
+ ///
public virtual string PaginationToken
{
get
{
- return DocumentSearch.PaginationToken;
+ return _documentSearch.PaginationToken;
}
}
-
- #endregion
}
}
diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs
index 29379dd4a929..7dae11417f1c 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs
@@ -14,11 +14,9 @@
*/
using System;
-using System.Collections;
using System.Collections.Generic;
-using System.Reflection;
-using Amazon.DynamoDBv2.Model;
using Amazon.DynamoDBv2.DocumentModel;
+
#if AWS_ASYNC_API
using System.Threading.Tasks;
#endif
@@ -27,163 +25,151 @@
namespace Amazon.DynamoDBv2.DataModel
{
///
- /// Represents a non-generic object for retrieving a batch of items
+ /// Represents a non-generic interface for retrieving a batch of items
/// from a single DynamoDB table
///
- public abstract partial class BatchGet
+ public partial interface IBatchGet
{
- #region Internal/protected properties
-
///
- /// Gets and sets the UntypedResults property.
+ /// Returns the total number of keys associated with this Batch request.
///
- protected List
/// Type of objects to write
/// Empty strongly-typed BatchWrite object
- BatchWrite CreateBatchWrite();
+ IBatchWrite CreateBatchWrite();
///
/// Creates a strongly-typed BatchWrite object, allowing
@@ -204,7 +203,7 @@ public partial interface IDynamoDBContext : IDisposable
/// Empty strongly-typed BatchWrite object
[Obsolete("Use the CreateBatchWrite overload that takes BatchWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchWrite.")]
- BatchWrite CreateBatchWrite(DynamoDBOperationConfig operationConfig = null);
+ IBatchWrite CreateBatchWrite(DynamoDBOperationConfig operationConfig = null);
///
/// Creates a strongly-typed BatchWrite object, allowing
@@ -218,7 +217,7 @@ public partial interface IDynamoDBContext : IDisposable
///
/// The type of data which will be persisted in this batch.
/// Empty strongly-typed BatchWrite object
- BatchWrite CreateBatchWrite(Type valuesType);
+ IBatchWrite CreateBatchWrite(Type valuesType);
///
/// Creates a strongly-typed BatchWrite object, allowing
@@ -234,7 +233,7 @@ public partial interface IDynamoDBContext : IDisposable
/// Config object which can be used to override that table used.
/// Empty strongly-typed BatchWrite object
[Obsolete("Use the CreateBatchWrite overload that takes BatchWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchWrite.")]
- BatchWrite CreateBatchWrite(Type valuesType, DynamoDBOperationConfig operationConfig = null);
+ IBatchWrite CreateBatchWrite(Type valuesType, DynamoDBOperationConfig operationConfig = null);
///
/// Creates a strongly-typed BatchWrite object, allowing
@@ -243,7 +242,7 @@ public partial interface IDynamoDBContext : IDisposable
/// Type of objects to write
/// Config object that can be used to override properties on the table's context for this request.
/// Empty strongly-typed BatchWrite object
- BatchWrite CreateBatchWrite(BatchWriteConfig batchWriteConfig);
+ IBatchWrite CreateBatchWrite(BatchWriteConfig batchWriteConfig);
///
/// Creates a strongly-typed BatchWrite object, allowing
@@ -258,7 +257,7 @@ public partial interface IDynamoDBContext : IDisposable
/// The type of data which will be persisted in this batch.
/// Config object that can be used to override properties on the table's context for this request.
/// Empty strongly-typed BatchWrite object
- BatchWrite CreateBatchWrite(Type valuesType, BatchWriteConfig batchWriteConfig);
+ IBatchWrite CreateBatchWrite(Type valuesType, BatchWriteConfig batchWriteConfig);
///
/// Creates a MultiTableBatchWrite object, composed of multiple
@@ -266,7 +265,7 @@ public partial interface IDynamoDBContext : IDisposable
///
/// Individual BatchWrite objects
/// Composite MultiTableBatchWrite object
- MultiTableBatchWrite CreateMultiTableBatchWrite(params BatchWrite[] batches);
+ IMultiTableBatchWrite CreateMultiTableBatchWrite(params IBatchWrite[] batches);
#endregion
@@ -278,7 +277,7 @@ public partial interface IDynamoDBContext : IDisposable
///
/// Type of objects to get.
/// Empty strongly-typed TransactGet object.
- TransactGet CreateTransactGet();
+ ITransactGet CreateTransactGet();
///
/// Creates a strongly-typed TransactGet object, allowing
@@ -288,7 +287,7 @@ public partial interface IDynamoDBContext : IDisposable
/// Config object which can be used to override that table used.
/// Empty strongly-typed TransactGet object.
[Obsolete("Use the CreateTransactGet overload that takes TransactGetConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to BatchGet.")]
- TransactGet CreateTransactGet(DynamoDBOperationConfig operationConfig = null);
+ ITransactGet CreateTransactGet(DynamoDBOperationConfig operationConfig = null);
///
/// Creates a strongly-typed TransactGet object, allowing
@@ -297,7 +296,7 @@ public partial interface IDynamoDBContext : IDisposable
/// Type of objects to get.
/// Config object that can be used to override properties on the table's context for this request.
/// Empty strongly-typed TransactGet object.
- TransactGet CreateTransactGet(TransactGetConfig transactGetConfig);
+ ITransactGet CreateTransactGet(TransactGetConfig transactGetConfig);
///
/// Creates a MultiTableTransactGet object, composed of multiple
@@ -305,7 +304,7 @@ public partial interface IDynamoDBContext : IDisposable
///
/// Individual TransactGet objects.
/// Composite MultiTableTransactGet object.
- MultiTableTransactGet CreateMultiTableTransactGet(params TransactGet[] transactionParts);
+ IMultiTableTransactGet CreateMultiTableTransactGet(params ITransactGet[] transactionParts);
#endregion
@@ -317,7 +316,7 @@ public partial interface IDynamoDBContext : IDisposable
///
/// Type of objects to write.
/// Empty strongly-typed TransactWrite object.
- TransactWrite CreateTransactWrite();
+ ITransactWrite CreateTransactWrite();
///
/// Creates a strongly-typed TransactWrite object, allowing
@@ -327,7 +326,7 @@ public partial interface IDynamoDBContext : IDisposable
/// Config object which can be used to override that table used.
/// Empty strongly-typed TransactWrite object.
[Obsolete("Use the CreateTransactWrite overload that takes TransactWriteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to CreateTransactWrite.")]
- TransactWrite CreateTransactWrite(DynamoDBOperationConfig operationConfig = null);
+ ITransactWrite CreateTransactWrite(DynamoDBOperationConfig operationConfig = null);
///
/// Creates a strongly-typed TransactWrite object, allowing
@@ -336,7 +335,7 @@ public partial interface IDynamoDBContext : IDisposable
/// Type of objects to write.
/// Config object that can be used to override properties on the table's context for this request.
/// Empty strongly-typed TransactWrite object.
- TransactWrite CreateTransactWrite(TransactWriteConfig transactWriteConfig);
+ ITransactWrite CreateTransactWrite(TransactWriteConfig transactWriteConfig);
///
/// Creates a MultiTableTransactWrite object, composed of multiple
@@ -344,7 +343,7 @@ public partial interface IDynamoDBContext : IDisposable
///
/// Individual TransactWrite objects.
/// Composite MultiTableTransactWrite object.
- MultiTableTransactWrite CreateMultiTableTransactWrite(params TransactWrite[] transactionParts);
+ IMultiTableTransactWrite CreateMultiTableTransactWrite(params ITransactWrite[] transactionParts);
#endregion
}
diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs
index 369e6fbb54fe..7daa14368bb6 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs
@@ -13,6 +13,7 @@
* permissions and limitations under the License.
*/
+using System;
using System.Collections.Generic;
#if AWS_ASYNC_API
using System.Threading;
@@ -23,124 +24,119 @@
namespace Amazon.DynamoDBv2.DataModel
{
///
- /// Represents a non-generic object for retrieving multiple items
+ /// Represents a non-generic interface for retrieving multiple items
/// from a single DynamoDB table in a transaction.
///
- public abstract partial class TransactGet
+ public partial interface ITransactGet
{
- #region Internal/protected properties
-
///
- /// Gets and sets the UntypedResults property.
+ /// List of non-generic results retrieved from DynamoDB.
///
- protected List UntypedResults { get; set; }
- internal DynamoDBContext Context { get; set; }
- internal DynamoDBFlatConfig Config { get; set; }
- internal DocumentTransactGet DocumentTransaction { get; set; }
-
- #endregion
-
-
- #region Public properties
+ ///
+ /// This is only populated after a call to Execute.
+ ///
+ List UntypedResults { get; }
+ }
+ ///
+ /// Represents a generic interface for retrieving multiple items
+ /// from a single DynamoDB table in a transaction.
+ ///
+ public interface ITransactGet : ITransactGet
+ {
///
- /// List of results retrieved from DynamoDB.
- /// Populated after Execute is called.
+ /// List of generic results retrieved from DynamoDB.
///
- public List Results => UntypedResults;
-
- #endregion
-
-
- #region Constructor
-
- internal TransactGet(DynamoDBContext context, DynamoDBFlatConfig config)
- {
- Context = context;
- Config = config;
- }
-
- #endregion
+ ///
+ /// This is only populated after a call to Execute.
+ ///
+ List Results { get; }
+ ///
+ /// Add a single item to get, identified by its hash primary key.
+ ///
+ /// Hash key of the item to get.
+ void AddKey(object hashKey);
- #region Protected methods
+ ///
+ /// Add a single item to get, identified by its hash-and-range primary key.
+ ///
+ /// Hash key of the item to get.
+ /// Range key of the item to get.
+ void AddKey(object hashKey, object rangeKey);
///
- /// Executes a server call to get the items requested in a transaction.
- /// Populates Results with the retrieved items.
+ /// Add a single item to get.
///
- protected internal abstract void ExecuteHelper();
+ /// Object key of the item to get.
+ void AddKey(T keyObject);
-#if AWS_ASYNC_API
///
- /// Executes an asynchronous server call to get the items requested in a transaction.
- /// Populates Results with the retrieved items.
+ /// Add multiple items to get.
///
- protected internal abstract Task ExecuteHelperAsync(CancellationToken cancellationToken);
-#endif
- #endregion
+ /// Object keys of the items to get.
+ void AddKeys(IEnumerable keyObjects);
+ ///
+ /// Creates a MultiTableTransactGet object that is a combination
+ /// of the current TransactGet and the specified TransactGets.
+ ///
+ /// Other TransactGet objects.
+ ///
+ /// MultiTableTransactGet consisting of the multiple TransactGet objects:
+ /// the current TransactGet object and the passed-in TransactGet objects.
+ ///
+ IMultiTableTransactGet Combine(params ITransactGet[] otherTransactionParts);
+ }
- #region Internal methods
+ ///
+ /// Represents a non-generic object for retrieving multiple items
+ /// from a single DynamoDB table in a transaction.
+ ///
+ public abstract partial class TransactGet : ITransactGet
+ {
+ internal DocumentTransactGet DocumentTransaction { get; set; }
internal abstract void PopulateResults();
- #endregion
+ ///
+ public List UntypedResults { get; } = new();
}
///
/// Represents a strongly-typed object for retrieving multiple items
/// from a single DynamoDB table in a transaction.
///
- public class TransactGet : TransactGet
+ public partial class TransactGet : TransactGet, ITransactGet
{
- #region Public properties
-
- ///
- /// List of results retrieved from DynamoDB.
- /// Populated after Execute is called.
- ///
- public new List Results { get { return TypedResults; } }
-
- #endregion
+ private readonly DynamoDBContext _context;
+ private readonly DynamoDBFlatConfig _config;
+ private readonly ItemStorageConfig _storageConfig;
+ ///
+ public List Results { get; } = new();
- #region Public methods
-
- ///
- /// Add a single item to get, identified by its hash primary key.
- ///
- /// Hash key of the item to get.
+ ///
public void AddKey(object hashKey)
{
AddKey(hashKey, rangeKey: null);
}
- ///
- /// Add a single item to get, identified by its hash-and-range primary key.
- ///
- /// Hash key of the item to get.
- /// Range key of the item to get.
+ ///
public void AddKey(object hashKey, object rangeKey)
{
- Key key = Context.MakeKey(hashKey, rangeKey, StorageConfig, Config);
+ Key key = _context.MakeKey(hashKey, rangeKey, _storageConfig, _config);
DocumentTransaction.AddKeyHelper(key);
}
- ///
- /// Add a single item to get.
- ///
- /// Object key of the item to get.
+ ///
public void AddKey(T keyObject)
{
- Key key = Context.MakeKey(keyObject, StorageConfig, Config);
+ Key key = _context.MakeKey(keyObject, _storageConfig, _config);
DocumentTransaction.AddKeyHelper(key);
}
- ///
- /// Add multiple items to get.
- ///
- /// Object keys of the items to get.
+ ///
public void AddKeys(IEnumerable keyObjects)
{
foreach (var keyObject in keyObjects)
@@ -149,61 +145,32 @@ public void AddKeys(IEnumerable keyObjects)
}
}
- ///
- /// Creates a MultiTableTransactGet object that is a combination
- /// of the current TransactGet and the specified TransactGets.
- ///
- /// Other TransactGet objects.
- ///
- /// MultiTableTransactGet consisting of the multiple TransactGet objects:
- /// the current TransactGet object and the passed-in TransactGet objects.
- ///
- public MultiTableTransactGet Combine(params TransactGet[] otherTransactionParts)
+ ///
+ public IMultiTableTransactGet Combine(params ITransactGet[] otherTransactionParts)
{
return new MultiTableTransactGet(this, otherTransactionParts);
}
- #endregion
-
-
- #region Constructor
-
internal TransactGet(DynamoDBContext context, DynamoDBFlatConfig config)
- : base(context, config)
{
- StorageConfig = context.StorageConfigCache.GetConfig(config);
- Table table = Context.GetTargetTable(StorageConfig, Config);
- DocumentTransaction = table.CreateTransactGet();
+ _context = context;
+ _config = config;
+ _storageConfig = context.StorageConfigCache.GetConfig(config);
+ var table = context.GetTargetTable(_storageConfig, config);
+
+ // Table.CreateTransactGet() returns the IDocumentTransactGet interface.
+ // But since we rely on the internal behavior of DocumentTransactGet, we instantiate it via the constructor.
+ DocumentTransaction = new DocumentTransactGet(table);
}
- #endregion
-
-
- #region Internal/protected/private members
-
- ///
- /// Gets and sets the TypedResults property.
- ///
- protected List TypedResults { get; set; }
-
- internal ItemStorageConfig StorageConfig { get; set; }
-
- ///
- /// Executes a server call to get the items requested in a transaction.
- /// Populates Results with the retrieved items.
- ///
- protected internal override void ExecuteHelper()
+ private void ExecuteHelper()
{
DocumentTransaction.ExecuteHelper();
PopulateResults();
}
#if AWS_ASYNC_API
- ///
- /// Executes an asynchronous server call to get the items requested in a transaction.
- /// Populates Results with the retrieved items.
- ///
- protected internal override async Task ExecuteHelperAsync(CancellationToken cancellationToken)
+ private async Task ExecuteHelperAsync(CancellationToken cancellationToken)
{
await DocumentTransaction.ExecuteHelperAsync(cancellationToken).ConfigureAwait(false);
PopulateResults();
@@ -212,96 +179,95 @@ protected internal override async Task ExecuteHelperAsync(CancellationToken canc
internal override void PopulateResults()
{
- UntypedResults = new List();
- TypedResults = new List();
+ UntypedResults.Clear();
+ Results.Clear();
foreach (var doc in DocumentTransaction.Results)
{
- var result = Context.FromDocumentHelper(doc, Config);
- TypedResults.Add(result);
+ var result = _context.FromDocumentHelper(doc, _config);
UntypedResults.Add(result);
+ Results.Add(result);
}
}
+ }
- #endregion
+ ///
+ /// Interface for retrieving multiple items from multiple DynamoDB tables,
+ /// using multiple strongly-typed TransactGet objects.
+ ///
+ public partial interface IMultiTableTransactGet
+ {
+ ///
+ /// Add a TransactGet object to the multi-table transaction request.
+ ///
+ /// TransactGet to add.
+ public void AddTransactionPart(ITransactGet transactionPart);
}
///
/// Class for retrieving multiple items from multiple DynamoDB tables,
/// using multiple strongly-typed TransactGet objects.
///
- public partial class MultiTableTransactGet
+ public partial class MultiTableTransactGet : IMultiTableTransactGet
{
- #region Private members
-
- private readonly List allTransactionParts;
-
- #endregion
-
-
- #region Constructor
+ private readonly List allTransactionParts;
///
/// Constructs a MultiTableTransactGet object from a number of
/// TransactGet objects.
///
/// Collection of TransactGet objects
- public MultiTableTransactGet(params TransactGet[] transactionParts)
+ public MultiTableTransactGet(params ITransactGet[] transactionParts)
{
- allTransactionParts = new List(transactionParts);
+ allTransactionParts = new List(transactionParts);
}
- internal MultiTableTransactGet(TransactGet first, params TransactGet[] rest)
+ internal MultiTableTransactGet(ITransactGet first, params ITransactGet[] rest)
{
- allTransactionParts = new List();
+ allTransactionParts = new List();
allTransactionParts.Add(first);
allTransactionParts.AddRange(rest);
}
- #endregion
-
-
- #region Public methods
-
- ///
- /// Add a TransactGet object to the multi-table transaction request.
- ///
- /// TransactGet to add.
- public void AddTransactionPart(TransactGet transactionPart)
+ ///
+ public void AddTransactionPart(ITransactGet transactionPart)
{
allTransactionParts.Add(transactionPart);
}
-
- internal void ExecuteHelper()
+ private void ExecuteHelper()
{
MultiTableDocumentTransactGet transaction = new MultiTableDocumentTransactGet();
+ var errorMsg = $"All transactionParts must be of type {nameof(TransactGet)}";
foreach (var transactionPart in allTransactionParts)
{
- transaction.AddTransactionPart(transactionPart.DocumentTransaction);
+ var abstractTransactGet = transactionPart as TransactGet ?? throw new InvalidOperationException(errorMsg);
+ transaction.AddTransactionPart(abstractTransactGet.DocumentTransaction);
}
transaction.ExecuteHelper();
foreach (var transactionPart in allTransactionParts)
{
- transactionPart.PopulateResults();
+ var abstractTransactGet = transactionPart as TransactGet ?? throw new InvalidOperationException(errorMsg);
+ abstractTransactGet.PopulateResults();
}
}
#if AWS_ASYNC_API
- internal async Task ExecuteHelperAsync(CancellationToken cancellationToken)
+ private async Task ExecuteHelperAsync(CancellationToken cancellationToken)
{
MultiTableDocumentTransactGet transaction = new MultiTableDocumentTransactGet();
+ var errorMsg = $"All transactionParts must be of type {nameof(TransactGet)}";
foreach (var transactionPart in allTransactionParts)
{
- transaction.AddTransactionPart(transactionPart.DocumentTransaction);
+ var abstractTransactGet = transactionPart as TransactGet ?? throw new InvalidOperationException(errorMsg);
+ transaction.AddTransactionPart(abstractTransactGet.DocumentTransaction);
}
await transaction.ExecuteHelperAsync(cancellationToken).ConfigureAwait(false);
foreach (var transactionPart in allTransactionParts)
{
- transactionPart.PopulateResults();
+ var abstractTransactGet = transactionPart as TransactGet ?? throw new InvalidOperationException(errorMsg);
+ abstractTransactGet.PopulateResults();
}
}
#endif
-
- #endregion
}
}
diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs
index 5aa70cea7464..de61ba6addaa 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs
@@ -24,53 +24,148 @@
namespace Amazon.DynamoDBv2.DataModel
{
+
///
- /// Represents a non-generic object for writing/deleting/version-checking multiple items
+ /// Represents a non-generic interface for writing/deleting/version-checking multiple items
/// in a single DynamoDB table in a transaction.
///
- public abstract partial class TransactWrite
+ public partial interface ITransactWrite
{
- #region Internal/protected properties
+ }
- internal DynamoDBContext Context { get; set; }
- internal DynamoDBFlatConfig Config { get; set; }
- internal DocumentTransactWrite DocumentTransaction { get; set; }
+ ///
+ /// Represents a generic interface for writing/deleting/version-checking multiple items
+ /// in a single DynamoDB table in a transaction.
+ ///
+ public interface ITransactWrite : ITransactWrite
+ {
+ ///
+ /// Creates a MultiTableTransactWrite object that is a combination
+ /// of the current TransactWrite and the specified TransactWrites.
+ ///
+ /// Other TransactWrite objects.
+ ///
+ /// MultiTableTransactWrite consisting of the multiple TransactWrite objects:
+ /// the current TransactWrite object and the passed-in TransactWrite objects.
+ ///
+ MultiTableTransactWrite Combine(params TransactWrite[] otherTransactionParts);
- #endregion
+ ///
+ /// Add a number of items to be saved in the current transaction operation.
+ ///
+ /// Items to save.
+ void AddSaveItems(IEnumerable values);
+ ///
+ /// Add a single item to be saved in the current transaction operation.
+ ///
+ /// Item to save.
+ void AddSaveItem(T item);
- #region Constructor
+ ///
+ /// Add a single item to be saved in the current transaction operation.
+ /// Item is identified by its hash primary key and will be updated using the update expression provided.
+ ///
+ /// Hash key of the item to delete.
+ /// Update expression to use.
+ /// Condition to check before the operation.
+ void AddSaveItem(object hashKey, Expression updateExpression, Expression conditionExpression = null);
- internal TransactWrite(DynamoDBContext context, DynamoDBFlatConfig config)
- {
- Context = context;
- Config = config;
- }
+ ///
+ /// Add a single item to be saved in the current transaction operation.
+ /// Item is identified by its hash-and-range primary key and will be updated using the update expression provided.
+ ///
+ /// Hash key of the item to delete.
+ /// Range key of the item to delete.
+ /// Update expression to use.
+ /// Condition to check before the operation.
+ void AddSaveItem(object hashKey, object rangeKey, Expression updateExpression, Expression conditionExpression = null);
- #endregion
+ ///
+ /// Add a number of items to be deleted in the current transaction operation.
+ ///
+ /// Items to be deleted.
+ void AddDeleteItems(IEnumerable values);
+ ///
+ /// Add a single item to be deleted in the current transaction operation.
+ ///
+ /// Item to be deleted.
+ void AddDeleteItem(T item);
- #region Protected methods
+ ///
+ /// Add a single item to be deleted in the current transaction operation.
+ /// Item is identified by its hash primary key.
+ ///
+ /// Hash key of the item to delete.
+ void AddDeleteKey(object hashKey);
///
- /// Executes a server call to write/delete/version-check the items requested in a transaction.
+ /// Add a single item to be deleted in the current transaction operation.
+ /// Item is identified by its hash primary key.
///
- protected internal abstract void ExecuteHelper();
+ /// Hash key of the item to delete.
+ /// Condition to check before the operation.
+ void AddDeleteKey(object hashKey, Expression conditionExpression);
-#if AWS_ASYNC_API
///
- /// Executes an asynchronous server call to write/delete/version-check the items requested in a transaction.
+ /// Add a single item to be deleted in the current transaction operation.
+ /// Item is identified by its hash-and-range primary key.
///
- protected internal abstract Task ExecuteHelperAsync(CancellationToken cancellationToken);
-#endif
- #endregion
+ /// Hash key of the item to delete.
+ /// Range key of the item to delete.
+ void AddDeleteKey(object hashKey, object rangeKey);
+ ///
+ /// Add a single item to be deleted in the current transaction operation.
+ /// Item is identified by its hash-and-range primary key.
+ ///
+ /// Hash key of the item to delete.
+ /// Range key of the item to delete.
+ /// Condition to check before the operation.
+ void AddDeleteKey(object hashKey, object rangeKey, Expression conditionExpression);
- #region Internal methods
+ ///
+ /// Add a single item to be version checked in the current transaction operation.
+ /// The item must have a single property marked with the DynamoDBVersionAttribute.
+ ///
+ /// Item to be version checked.
+ void AddVersionCheckItem(T item);
- internal abstract void PopulateObjects();
+ ///
+ /// Add a number of items to be version checked in the current transaction operation.
+ /// All items must have a single property marked with the DynamoDBVersionAttribute.
+ ///
+ /// Items to be version checked.
+ void AddVersionCheckItems(IEnumerable items);
- #endregion
+ ///
+ /// Add a single item to be version checked in the current transaction operation.
+ /// Item is identified by its hash primary key.
+ ///
+ /// Hash key of the item to be version checked.
+ /// Version of the item.
+ void AddVersionCheckKey(object hashKey, object version);
+
+ ///
+ /// Add a single item to be version checked in the current transaction operation.
+ /// Item is identified by its hash-and-range primary key.
+ ///
+ /// Hash key of the item to be version checked.
+ /// Range key of the item to be version checked.
+ /// Version of the item.
+ void AddVersionCheckKey(object hashKey, object rangeKey, object version);
+ }
+
+ ///
+ /// Represents a non-generic object for writing/deleting/version-checking multiple items
+ /// in a single DynamoDB table in a transaction.
+ ///
+ public abstract partial class TransactWrite : ITransactWrite
+ {
+ internal DocumentTransactWrite DocumentTransaction { get; set; }
+
+ internal abstract void PopulateObjects();
}
///
@@ -80,33 +175,32 @@ internal TransactWrite(DynamoDBContext context, DynamoDBFlatConfig config)
#if NET8_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Amazon.DynamoDBv2.Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)]
#endif
- public class TransactWrite : TransactWrite
+ public partial class TransactWrite : TransactWrite, ITransactWrite
{
- #region Public Combine methods
+ private readonly DynamoDBContext _context;
+ private readonly DynamoDBFlatConfig _config;
+ private readonly ItemStorageConfig _storageConfig;
+ private readonly List _objectItems = new();
- ///
- /// Creates a MultiTableTransactWrite object that is a combination
- /// of the current TransactWrite and the specified TransactWrites.
- ///
- /// Other TransactWrite objects.
- ///
- /// MultiTableTransactWrite consisting of the multiple TransactWrite objects:
- /// the current TransactWrite object and the passed-in TransactWrite objects.
- ///
+ internal TransactWrite(DynamoDBContext context, DynamoDBFlatConfig config)
+ {
+ _context = context;
+ _config = config;
+ _storageConfig = context.StorageConfigCache.GetConfig(config);
+ Table table = _context.GetTargetTable(_storageConfig, _config);
+
+ // table.CreateTransactWrite() return the IDocumentTransactWrite interface.
+ // But since we rely on the internal behavior of DocumentTransactWrite, we instatiate it via the constructor.
+ DocumentTransaction = new DocumentTransactWrite(table);
+ }
+
+ ///
public MultiTableTransactWrite Combine(params TransactWrite[] otherTransactionParts)
{
return new MultiTableTransactWrite(this, otherTransactionParts);
}
- #endregion
-
-
- #region Public Save methods
-
- ///
- /// Add a number of items to be saved in the current transaction operation.
- ///
- /// Items to save.
+ ///
public void AddSaveItems(IEnumerable values)
{
if (values == null) return;
@@ -117,15 +211,12 @@ public void AddSaveItems(IEnumerable values)
}
}
- ///
- /// Add a single item to be saved in the current transaction operation.
- ///
- /// Item to save.
+ ///
public void AddSaveItem(T item)
{
if (item == null) return;
- ItemStorage storage = Context.ObjectToItemStorageHelper(item, StorageConfig, Config, keysOnly: false, Config.IgnoreNullValues ?? false);
+ ItemStorage storage = _context.ObjectToItemStorageHelper(item, _storageConfig, _config, keysOnly: false, _config.IgnoreNullValues ?? false);
if (storage == null) return;
Expression conditionExpression = CreateConditionExpressionForVersion(storage);
SetNewVersion(storage);
@@ -140,29 +231,16 @@ public void AddSaveItem(T item)
OriginalObject = item,
ItemStorage = storage
};
- objectItems.Add(objectItem);
+ _objectItems.Add(objectItem);
}
- ///
- /// Add a single item to be saved in the current transaction operation.
- /// Item is identified by its hash primary key and will be updated using the update expression provided.
- ///
- /// Hash key of the item to delete.
- /// Update expression to use.
- /// Condition to check before the operation.
+ ///
public void AddSaveItem(object hashKey, Expression updateExpression, Expression conditionExpression = null)
{
AddSaveItem(hashKey, rangeKey: null, updateExpression, conditionExpression);
}
- ///
- /// Add a single item to be saved in the current transaction operation.
- /// Item is identified by its hash-and-range primary key and will be updated using the update expression provided.
- ///
- /// Hash key of the item to delete.
- /// Range key of the item to delete.
- /// Update expression to use.
- /// Condition to check before the operation.
+ ///
public void AddSaveItem(object hashKey, object rangeKey, Expression updateExpression, Expression conditionExpression = null)
{
var operationConfig = conditionExpression != null
@@ -173,18 +251,10 @@ public void AddSaveItem(object hashKey, object rangeKey, Expression updateExpres
}
: null;
- DocumentTransaction.AddDocumentToUpdateHelper(Context.MakeKey(hashKey, rangeKey, StorageConfig, Config), updateExpression, operationConfig);
+ DocumentTransaction.AddDocumentToUpdateHelper(_context.MakeKey(hashKey, rangeKey, _storageConfig, _config), updateExpression, operationConfig);
}
- #endregion
-
-
- #region Public Delete methods
-
- ///
- /// Add a number of items to be deleted in the current transaction operation.
- ///
- /// Items to be deleted.
+ ///
public void AddDeleteItems(IEnumerable values)
{
if (values == null) return;
@@ -195,15 +265,12 @@ public void AddDeleteItems(IEnumerable values)
}
}
- ///
- /// Add a single item to be deleted in the current transaction operation.
- ///
- /// Item to be deleted.
+ ///
public void AddDeleteItem(T item)
{
if (item == null) return;
- ItemStorage storage = Context.ObjectToItemStorageHelper(item, StorageConfig, Config, keysOnly: true, Config.IgnoreNullValues ?? false);
+ ItemStorage storage = _context.ObjectToItemStorageHelper(item, _storageConfig, _config, keysOnly: true, _config.IgnoreNullValues ?? false);
if (storage == null) return;
Expression conditionExpression = CreateConditionExpressionForVersion(storage);
@@ -214,45 +281,25 @@ public void AddDeleteItem(T item)
});
}
- ///
- /// Add a single item to be deleted in the current transaction operation.
- /// Item is identified by its hash primary key.
- ///
- /// Hash key of the item to delete.
+ ///
public void AddDeleteKey(object hashKey)
{
AddDeleteKey(hashKey, conditionExpression: null);
}
- ///
- /// Add a single item to be deleted in the current transaction operation.
- /// Item is identified by its hash primary key.
- ///
- /// Hash key of the item to delete.
- /// Condition to check before the operation.
+ ///
public void AddDeleteKey(object hashKey, Expression conditionExpression)
{
AddDeleteKey(hashKey, rangeKey: null, conditionExpression);
}
- ///
- /// Add a single item to be deleted in the current transaction operation.
- /// Item is identified by its hash-and-range primary key.
- ///
- /// Hash key of the item to delete.
- /// Range key of the item to delete.
+ ///
public void AddDeleteKey(object hashKey, object rangeKey)
{
AddDeleteKey(hashKey, rangeKey, conditionExpression: null);
}
- ///
- /// Add a single item to be deleted in the current transaction operation.
- /// Item is identified by its hash-and-range primary key.
- ///
- /// Hash key of the item to delete.
- /// Range key of the item to delete.
- /// Condition to check before the operation.
+ ///
public void AddDeleteKey(object hashKey, object rangeKey, Expression conditionExpression)
{
var operationConfig = conditionExpression != null
@@ -263,26 +310,17 @@ public void AddDeleteKey(object hashKey, object rangeKey, Expression conditionEx
}
: null;
- DocumentTransaction.AddKeyToDeleteHelper(Context.MakeKey(hashKey, rangeKey, StorageConfig, Config), operationConfig);
+ DocumentTransaction.AddKeyToDeleteHelper(_context.MakeKey(hashKey, rangeKey, _storageConfig, _config), operationConfig);
}
- #endregion
-
-
- #region Public VersionCheck methods
-
- ///
- /// Add a single item to be version checked in the current transaction operation.
- /// The item must have a single property marked with the DynamoDBVersionAttribute.
- ///
- /// Item to be version checked.
+ ///
public void AddVersionCheckItem(T item)
{
CheckUseVersioning();
if (item == null) return;
- ItemStorage storage = Context.ObjectToItemStorageHelper(item, StorageConfig, Config, keysOnly: true, Config.IgnoreNullValues ?? false);
+ ItemStorage storage = _context.ObjectToItemStorageHelper(item, _storageConfig, _config, keysOnly: true, _config.IgnoreNullValues ?? false);
if (storage == null) return;
Expression conditionExpression = CreateConditionExpressionForVersion(storage);
@@ -293,11 +331,7 @@ public void AddVersionCheckItem(T item)
});
}
- ///
- /// Add a number of items to be version checked in the current transaction operation.
- /// All items must have a single property marked with the DynamoDBVersionAttribute.
- ///
- /// Items to be version checked.
+ ///
public void AddVersionCheckItems(IEnumerable items)
{
foreach (var item in items)
@@ -306,40 +340,29 @@ public void AddVersionCheckItems(IEnumerable items)
}
}
- ///
- /// Add a single item to be version checked in the current transaction operation.
- /// Item is identified by its hash primary key.
- ///
- /// Hash key of the item to be version checked.
- /// Version of the item.
+ ///
public void AddVersionCheckKey(object hashKey, object version)
{
AddVersionCheckKey(hashKey, rangeKey: null, version);
}
- ///
- /// Add a single item to be version checked in the current transaction operation.
- /// Item is identified by its hash-and-range primary key.
- ///
- /// Hash key of the item to be version checked.
- /// Range key of the item to be version checked.
- /// Version of the item.
+ ///
public void AddVersionCheckKey(object hashKey, object rangeKey, object version)
{
CheckUseVersioning();
- Key key = Context.MakeKey(hashKey, rangeKey, StorageConfig, Config);
- DynamoDBEntry versionEntry = Context.ToDynamoDBEntry(StorageConfig.VersionPropertyStorage, version, Config);
+ Key key = _context.MakeKey(hashKey, rangeKey, _storageConfig, _config);
+ DynamoDBEntry versionEntry = _context.ToDynamoDBEntry(_storageConfig.VersionPropertyStorage, version, _config);
Primitive versionPrimitive = versionEntry?.AsPrimitive();
if (versionEntry != null && versionPrimitive == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
"Version property {0} must be Primitive.",
- StorageConfig.VersionPropertyName));
+ _storageConfig.VersionPropertyName));
}
- ItemStorage storage = new ItemStorage(StorageConfig)
+ ItemStorage storage = new ItemStorage(_storageConfig)
{
CurrentVersion = versionPrimitive
};
@@ -353,42 +376,14 @@ public void AddVersionCheckKey(object hashKey, object rangeKey, object version)
});
}
- #endregion
-
-
- #region Constructor
-
- internal TransactWrite(DynamoDBContext context, DynamoDBFlatConfig config)
- : base(context, config)
- {
- StorageConfig = context.StorageConfigCache.GetConfig(config);
- Table table = Context.GetTargetTable(StorageConfig, Config);
- DocumentTransaction = table.CreateTransactWrite();
- }
-
- #endregion
-
-
- #region Internal/protected/private members
-
- private readonly List objectItems = new List();
-
- internal ItemStorageConfig StorageConfig { get; set; }
-
- ///
- /// Executes a server call to write/delete/version-check the items requested in a transaction.
- ///
- protected internal override void ExecuteHelper()
+ private void ExecuteHelper()
{
DocumentTransaction.ExecuteHelper();
PopulateObjects();
}
#if AWS_ASYNC_API
- ///
- /// Executes an asynchronous server call to write/delete/version-check the items requested in a transaction.
- ///
- protected internal override async Task ExecuteHelperAsync(CancellationToken cancellationToken)
+ private async Task ExecuteHelperAsync(CancellationToken cancellationToken)
{
await DocumentTransaction.ExecuteHelperAsync(cancellationToken).ConfigureAwait(false);
PopulateObjects();
@@ -397,27 +392,27 @@ protected internal override async Task ExecuteHelperAsync(CancellationToken canc
internal override void PopulateObjects()
{
- foreach (var objectItem in objectItems)
+ foreach (var objectItem in _objectItems)
{
- objectItem.PopulateObject(Context, Config);
+ objectItem.PopulateObject(_context, _config);
}
}
private bool ShouldUseVersioning()
{
- var skipVersionCheck = Config.SkipVersionCheck ?? false;
- return !skipVersionCheck && StorageConfig.HasVersion;
+ var skipVersionCheck = _config.SkipVersionCheck ?? false;
+ return !skipVersionCheck && _storageConfig.HasVersion;
}
private void CheckUseVersioning()
{
- if (Config.SkipVersionCheck == true)
+ if (_config.SkipVersionCheck == true)
{
throw new InvalidOperationException(
"Using DynamoDBContextConfig.SkipVersionCheck property with true value is not supported for this operation.");
}
- if (!StorageConfig.HasVersion)
+ if (!_storageConfig.HasVersion)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
"Object {0} does not have a versioning field, which is not supported for this operation.",
@@ -439,86 +434,86 @@ private void SetNewVersion(ItemStorage storage)
if (!ShouldUseVersioning()) return;
DynamoDBContext.SetNewVersion(storage);
}
+ }
- #endregion
+ ///
+ /// Interface for writing/deleting/version-checking multiple items in multiple DynamoDB tables,
+ /// using multiple strongly-typed TransactWrite objects.
+ ///
+ public partial interface IMultiTableTransactWrite
+ {
+ ///
+ /// Add a TransactWrite object to the multi-table transaction request.
+ ///
+ /// TransactWrite to add.
+ void AddTransactionPart(ITransactWrite transactionPart);
}
///
/// Class for writing/deleting/version-checking multiple items in multiple DynamoDB tables,
/// using multiple strongly-typed TransactWrite objects.
///
- public partial class MultiTableTransactWrite
+ public partial class MultiTableTransactWrite : IMultiTableTransactWrite
{
- #region Private members
-
- private readonly List allTransactionParts;
-
- #endregion
-
-
- #region Constructor
+ private readonly List allTransactionParts;
///
/// Constructs a MultiTableTransactWrite object from a number of
/// TransactWrite objects
///
/// Collection of TransactWrite objects
- public MultiTableTransactWrite(params TransactWrite[] transactionParts)
+ public MultiTableTransactWrite(params ITransactWrite[] transactionParts)
{
- allTransactionParts = new List(transactionParts);
+ allTransactionParts = new List(transactionParts);
}
- internal MultiTableTransactWrite(TransactWrite first, params TransactWrite[] rest)
+ internal MultiTableTransactWrite(ITransactWrite first, params ITransactWrite[] rest)
{
- allTransactionParts = new List();
+ allTransactionParts = new List();
allTransactionParts.Add(first);
allTransactionParts.AddRange(rest);
}
- #endregion
-
-
- #region Public methods
-
- ///
- /// Add a TransactWrite object to the multi-table transaction request.
- ///
- /// TransactWrite to add.
- public void AddTransactionPart(TransactWrite transactionPart)
+ ///
+ public void AddTransactionPart(ITransactWrite transactionPart)
{
allTransactionParts.Add(transactionPart);
}
- internal void ExecuteHelper()
+ private void ExecuteHelper()
{
MultiTableDocumentTransactWrite transaction = new MultiTableDocumentTransactWrite();
+ var errMsg = $"All transactionParts must be of type {nameof(TransactWrite)}";
foreach (var transactionPart in allTransactionParts)
{
- transaction.AddTransactionPart(transactionPart.DocumentTransaction);
+ var abstractTransactWrite = transactionPart as TransactWrite ?? throw new InvalidOperationException(errMsg);
+ transaction.AddTransactionPart(abstractTransactWrite.DocumentTransaction);
}
transaction.ExecuteHelper();
foreach (var transactionPart in allTransactionParts)
{
- transactionPart.PopulateObjects();
+ var abstractTransactWrite = transactionPart as TransactWrite ?? throw new InvalidOperationException(errMsg);
+ abstractTransactWrite.PopulateObjects();
}
}
#if AWS_ASYNC_API
- internal async Task ExecuteHelperAsync(CancellationToken cancellationToken)
+ private async Task ExecuteHelperAsync(CancellationToken cancellationToken)
{
MultiTableDocumentTransactWrite transaction = new MultiTableDocumentTransactWrite();
+ var errMsg = $"All transactionParts must be of type {nameof(TransactWrite)}";
foreach (var transactionPart in allTransactionParts)
{
- transaction.AddTransactionPart(transactionPart.DocumentTransaction);
+ var abstractTransactWrite = transactionPart as TransactWrite ?? throw new InvalidOperationException(errMsg);
+ transaction.AddTransactionPart(abstractTransactWrite.DocumentTransaction);
}
await transaction.ExecuteHelperAsync(cancellationToken).ConfigureAwait(false);
foreach (var transactionPart in allTransactionParts)
{
- transactionPart.PopulateObjects();
+ var abstractTransactWrite = transactionPart as TransactWrite ?? throw new InvalidOperationException(errMsg);
+ abstractTransactWrite.PopulateObjects();
}
}
#endif
-
- #endregion
}
}
diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs
index 8945c588fabd..c37d83a73c6d 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs
@@ -18,21 +18,10 @@
using System.Threading;
using System.Threading.Tasks;
-using Amazon.Runtime.Internal;
-using Amazon.DynamoDBv2.DocumentModel;
-using Amazon.DynamoDBv2.DataModel;
-
namespace Amazon.DynamoDBv2.DataModel
{
- ///
- /// A strongly-typed object for retrieving search results (Query or Scan)
- /// from DynamoDB.
- ///
- ///
- public partial class AsyncSearch
+ public partial interface IAsyncSearch
{
- #region Async public
-
///
/// Initiates the asynchronous execution to get the next set of results from DynamoDB.
///
@@ -45,12 +34,7 @@ public partial class AsyncSearch
/// A Task that can be used to poll or wait for results, or both.
/// Results will include the next set of result items from DynamoDB.
///
- public virtual async Task> GetNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
- {
- var documents = await DocumentSearch.GetNextSetHelperAsync(cancellationToken).ConfigureAwait(false);
- List items = SourceContext.FromDocumentsHelper(documents, this.Config).ToList();
- return items;
- }
+ Task> GetNextSetAsync(CancellationToken cancellationToken = default(CancellationToken));
///
/// Initiates the asynchronous execution to get all the remaining results from DynamoDB.
@@ -60,13 +44,25 @@ public partial class AsyncSearch
/// A Task that can be used to poll or wait for results, or both.
/// Results will include the remaining result items from DynamoDB.
///
- public virtual async Task> GetRemainingAsync(CancellationToken cancellationToken = default(CancellationToken))
+ Task> GetRemainingAsync(CancellationToken cancellationToken = default(CancellationToken));
+ }
+
+ public partial class AsyncSearch : IAsyncSearch
+ {
+ ///
+ public virtual async Task> GetNextSetAsync(CancellationToken cancellationToken = default(CancellationToken))
{
- var documents = await DocumentSearch.GetRemainingHelperAsync(cancellationToken).ConfigureAwait(false);
- List items = SourceContext.FromDocumentsHelper(documents, this.Config).ToList();
+ var documents = await _documentSearch.GetNextSetHelperAsync(cancellationToken).ConfigureAwait(false);
+ List items = _sourceContext.FromDocumentsHelper(documents, this._config).ToList();
return items;
}
- #endregion
+ ///
+ public virtual async Task> GetRemainingAsync(CancellationToken cancellationToken = default(CancellationToken))
+ {
+ var documents = await _documentSearch.GetRemainingHelperAsync(cancellationToken).ConfigureAwait(false);
+ List items = _sourceContext.FromDocumentsHelper(documents, this._config).ToList();
+ return items;
+ }
}
}
diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchGet.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchGet.Async.cs
index b40710792c17..561e70161b56 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchGet.Async.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchGet.Async.cs
@@ -14,48 +14,39 @@
*/
#pragma warning disable 1574
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Reflection;
-using Amazon.DynamoDBv2.Model;
-using Amazon.DynamoDBv2.DocumentModel;
using System.Threading;
using System.Threading.Tasks;
-using Amazon.Runtime.Internal;
namespace Amazon.DynamoDBv2.DataModel
{
- ///
- /// Represents a non-generic object for retrieving a batch of items
- /// from a single DynamoDB table
- ///
- public abstract partial class BatchGet
+ public partial interface IBatchGet
{
- #region Public methods
-
///
/// Executes a server call to batch-get the items requested.
///
/// Token which can be used to cancel the task.
///
/// A Task that can be used to poll or wait for results, or both.
- public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
+ Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
+ }
+
+ public abstract partial class BatchGet
+ {
+ ///
+ public abstract Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
+ }
+
+ public partial class BatchGet : BatchGet, IBatchGet
+ {
+ ///
+ public override Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return ExecuteHelperAsync(cancellationToken);
}
-
- #endregion
}
- ///
- /// Class for retrieving a batch of items from multiple DynamoDB tables,
- /// using multiple strongly-typed BatchGet objects
- ///
- public partial class MultiTableBatchGet
+ public partial interface IMultiTableBatchGet
{
- #region Public methods
-
///
/// Executes a multi-table batch request against all configured batches.
/// Results are stored in the respective BatchGet objects.
@@ -63,11 +54,15 @@ public partial class MultiTableBatchGet
/// Token which can be used to cancel the task.
///
/// A Task that can be used to poll or wait for results, or both.
+ Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
+ }
+
+ public partial class MultiTableBatchGet : IMultiTableBatchGet
+ {
+ ///
public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return ExecuteHelperAsync(cancellationToken);
}
-
- #endregion
}
}
diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchWrite.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchWrite.Async.cs
index 4f4cdc0d4789..ec77b8766dd5 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchWrite.Async.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchWrite.Async.cs
@@ -14,26 +14,13 @@
*/
#pragma warning disable 1574
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Reflection;
-using Amazon.DynamoDBv2.Model;
-using Amazon.DynamoDBv2.DocumentModel;
using System.Threading.Tasks;
-using Amazon.Runtime.Internal;
using System.Threading;
namespace Amazon.DynamoDBv2.DataModel
{
- ///
- /// Represents a non-generic object for writing/deleting a batch of items
- /// in a single DynamoDB table
- ///
- public abstract partial class BatchWrite
+ public partial interface IBatchWrite
{
- #region Public methods
-
///
/// Executes a server call to batch-write/delete the items requested.
///
@@ -43,22 +30,26 @@ public abstract partial class BatchWrite
/// Token which can be used to cancel the task.
///
/// A Task that can be used to poll or wait for results, or both.
- public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
+ Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
+ }
+
+ public abstract partial class BatchWrite : IBatchWrite
+ {
+ ///
+ public abstract Task ExecuteAsync(CancellationToken cancellationToken);
+ }
+
+ public partial class BatchWrite : BatchWrite, IBatchWrite
+ {
+ ///
+ public override Task ExecuteAsync(CancellationToken cancellationToken)
{
return ExecuteHelperAsync(cancellationToken);
}
-
- #endregion
}
- ///
- /// Class for writing/deleting a batch of items in multiple DynamoDB tables,
- /// using multiple strongly-typed BatchWrite objects
- ///
- public partial class MultiTableBatchWrite
+ public partial interface IMultiTableBatchWrite
{
- #region Public methods
-
///
/// Executes a multi-table batch request against all configured batches.
///
@@ -68,11 +59,15 @@ public partial class MultiTableBatchWrite
/// Token which can be used to cancel the task.
///
/// A Task that can be used to poll or wait for results, or both.
+ Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken));
+ }
+
+ public partial class MultiTableBatchWrite : IMultiTableBatchWrite
+ {
+ ///
public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return ExecuteHelperAsync(cancellationToken);
}
-
- #endregion
}
}
diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs
index 5a320690d12c..731287ef7fda 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs
@@ -16,12 +16,9 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Amazon.DynamoDBv2.DocumentModel;
-using Amazon.DynamoDBv2.Model;
-using Amazon.Runtime.Internal;
namespace Amazon.DynamoDBv2.DataModel
{
@@ -197,31 +194,14 @@ public Task DeleteAsync(object hashKey, object rangeKey, DeleteConfig deleteC
#region BatchGet async
- ///
- /// Issues a batch-get request with multiple batches.
- ///
- /// Results are stored in the individual batches.
- ///
- ///
- /// Configured BatchGet objects
- ///
- public Task ExecuteBatchGetAsync(params BatchGet[] batches)
+ ///
+ public Task ExecuteBatchGetAsync(params IBatchGet[] batches)
{
return ExecuteBatchGetAsync(batches, default(CancellationToken));
}
- ///
- /// Issues a batch-get request with multiple batches.
- ///
- /// Results are stored in the individual batches.
- ///
- ///
- /// Configured BatchGet objects
- ///
- ///
- /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
- ///
- public Task ExecuteBatchGetAsync(BatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken))
+ ///
+ public Task ExecuteBatchGetAsync(IBatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken))
{
MultiTableBatchGet superBatch = new MultiTableBatchGet(batches);
return superBatch.ExecuteAsync(cancellationToken);
@@ -231,16 +211,8 @@ public Task ExecuteBatchGetAsync(params BatchGet[] batches)
#region BatchWrite async
- ///
- /// Issues a batch-write request with multiple batches.
- ///
- ///
- /// Configured BatchWrite objects
- ///
- ///
- /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
- ///
- public Task ExecuteBatchWriteAsync(BatchWrite[] batches, CancellationToken cancellationToken = default(CancellationToken))
+ ///
+ public Task ExecuteBatchWriteAsync(IBatchWrite[] batches, CancellationToken cancellationToken = default(CancellationToken))
{
MultiTableBatchWrite superBatch = new MultiTableBatchWrite(batches);
return superBatch.ExecuteAsync(cancellationToken);
@@ -250,14 +222,8 @@ public Task ExecuteBatchGetAsync(params BatchGet[] batches)
#region TransactGet async
- ///
- /// Issues a transactional get request with multiple TransactGet objects.
- /// Results are stored in the individual TransactGet objects.
- ///
- /// Configured TransactGet objects.
- /// Token which can be used to cancel the task.
- /// A Task that can be used to poll or wait for results, or both.
- public Task ExecuteTransactGetAsync(TransactGet[] transactionParts, CancellationToken cancellationToken = default(CancellationToken))
+ ///
+ public Task ExecuteTransactGetAsync(ITransactGet[] transactionParts, CancellationToken cancellationToken = default(CancellationToken))
{
MultiTableTransactGet transaction = new MultiTableTransactGet(transactionParts);
return transaction.ExecuteAsync(cancellationToken);
@@ -267,13 +233,8 @@ public Task ExecuteBatchGetAsync(params BatchGet[] batches)
#region TransactWrite async
- ///
- /// Issues a transactional write request with multiple TransactWrite objects.
- ///
- /// Configured TransactWrite objects.
- /// Token which can be used to cancel the task.
- /// A Task that can be used to poll or wait for results, or both.
- public Task ExecuteTransactWriteAsync(TransactWrite[] transactionParts, CancellationToken cancellationToken = default(CancellationToken))
+ ///
+ public Task ExecuteTransactWriteAsync(ITransactWrite[] transactionParts, CancellationToken cancellationToken = default(CancellationToken))
{
MultiTableTransactWrite transaction = new MultiTableTransactWrite(transactionParts);
return transaction.ExecuteAsync(cancellationToken);
@@ -284,7 +245,7 @@ public Task ExecuteBatchGetAsync(params BatchGet[] batches)
#region Scan async
///
- public AsyncSearch ScanAsync(IEnumerable conditions)
+ public IAsyncSearch ScanAsync(IEnumerable conditions)
{
var scan = ConvertScan(conditions, null);
return FromSearchAsync(scan);
@@ -292,21 +253,21 @@ public AsyncSearch ScanAsync(IEnumerable conditions)
///
[Obsolete("Use the ScanAsync overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to ScanAsync.")]
- public AsyncSearch ScanAsync(IEnumerable conditions, DynamoDBOperationConfig operationConfig = null)
+ public IAsyncSearch ScanAsync(IEnumerable conditions, DynamoDBOperationConfig operationConfig = null)
{
var scan = ConvertScan(conditions, operationConfig);
return FromSearchAsync(scan);
}
///
- public AsyncSearch ScanAsync(IEnumerable conditions, ScanConfig scanConfig)
+ public IAsyncSearch ScanAsync(IEnumerable conditions, ScanConfig scanConfig)
{
var scan = ConvertScan(conditions, scanConfig?.ToDynamoDBOperationConfig());
return FromSearchAsync(scan);
}
///
- public AsyncSearch FromScanAsync(ScanOperationConfig scanConfig)
+ public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig)
{
if (scanConfig == null) throw new ArgumentNullException("scanConfig");
@@ -316,7 +277,7 @@ public AsyncSearch FromScanAsync(ScanOperationConfig scanConfig)
///
[Obsolete("Use the FromScanAsync overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromScanAsync.")]
- public AsyncSearch FromScanAsync(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig = null)
+ public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig = null)
{
if (scanConfig == null) throw new ArgumentNullException("scanConfig");
@@ -325,7 +286,7 @@ public AsyncSearch FromScanAsync(ScanOperationConfig scanConfig, DynamoDBO
}
///
- public AsyncSearch FromScanAsync(ScanOperationConfig scanConfig, FromScanConfig fromScanConfig)
+ public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, FromScanConfig fromScanConfig)
{
if (scanConfig == null) throw new ArgumentNullException("scanConfig");
@@ -338,7 +299,7 @@ public AsyncSearch FromScanAsync(ScanOperationConfig scanConfig, FromScanC
#region Query async
///
- public AsyncSearch QueryAsync(object hashKeyValue)
+ public IAsyncSearch QueryAsync(object hashKeyValue)
{
var query = ConvertQueryByValue(hashKeyValue, null, null);
return FromSearchAsync(query);
@@ -346,21 +307,21 @@ public AsyncSearch QueryAsync(object hashKeyValue)
///
[Obsolete("Use the QueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to QueryAsync.")]
- public AsyncSearch QueryAsync(object hashKeyValue, DynamoDBOperationConfig operationConfig = null)
+ public IAsyncSearch QueryAsync(object hashKeyValue, DynamoDBOperationConfig operationConfig = null)
{
var query = ConvertQueryByValue(hashKeyValue, null, operationConfig);
return FromSearchAsync(query);
}
///
- public AsyncSearch QueryAsync(object hashKeyValue, QueryConfig queryConfig)
+ public IAsyncSearch QueryAsync(object hashKeyValue, QueryConfig queryConfig)
{
var query = ConvertQueryByValue(hashKeyValue, null, queryConfig?.ToDynamoDBOperationConfig());
return FromSearchAsync(query);
}
///
- public AsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values)
+ public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values)
{
if (values == null)
throw new ArgumentNullException("values");
@@ -371,7 +332,7 @@ public AsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnum
///
[Obsolete("Use the QueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to QueryAsync.")]
- public AsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig = null)
+ public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig = null)
{
if (values == null)
throw new ArgumentNullException("values");
@@ -381,7 +342,7 @@ public AsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnum
}
///
- public AsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, QueryConfig queryConfig)
+ public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, QueryConfig queryConfig)
{
if (values == null)
throw new ArgumentNullException("values");
@@ -391,7 +352,7 @@ public AsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnum
}
///
- public AsyncSearch FromQueryAsync(QueryOperationConfig queryConfig)
+ public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig)
{
if (queryConfig == null) throw new ArgumentNullException("queryConfig");
@@ -401,7 +362,7 @@ public AsyncSearch FromQueryAsync(QueryOperationConfig queryConfig)
///
[Obsolete("Use the FromQueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromQueryAsync.")]
- public AsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig = null)
+ public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig = null)
{
if (queryConfig == null) throw new ArgumentNullException("queryConfig");
@@ -410,7 +371,7 @@ public AsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, Dynamo
}
///
- public AsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, FromQueryConfig fromQueryConfig)
+ public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, FromQueryConfig fromQueryConfig)
{
if (queryConfig == null) throw new ArgumentNullException("queryConfig");
diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/IDynamoDBContext.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/IDynamoDBContext.Async.cs
index 7f10ebfa10c7..98a1bee4674d 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/IDynamoDBContext.Async.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/IDynamoDBContext.Async.cs
@@ -407,6 +407,17 @@ partial interface IDynamoDBContext
#region BatchGet async
+ ///
+ /// Issues a batch-get request with multiple batches.
+ ///
+ /// Results are stored in the individual batches.
+ ///
+ ///
+ /// Configured BatchGet objects
+ ///
+ /// A Task that can be used to poll or wait for results, or both.
+ Task ExecuteBatchGetAsync(params IBatchGet[] batches);
+
///
/// Issues a batch-get request with multiple batches.
///
@@ -417,7 +428,7 @@ partial interface IDynamoDBContext
///
/// Token which can be used to cancel the task.
/// A Task that can be used to poll or wait for results, or both.
- Task ExecuteBatchGetAsync(BatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken));
+ Task ExecuteBatchGetAsync(IBatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken));
#endregion
@@ -431,7 +442,7 @@ partial interface IDynamoDBContext
///
/// Token which can be used to cancel the task.
/// A Task that can be used to poll or wait for results, or both.
- Task ExecuteBatchWriteAsync(BatchWrite[] batches, CancellationToken cancellationToken = default(CancellationToken));
+ Task ExecuteBatchWriteAsync(IBatchWrite[] batches, CancellationToken cancellationToken = default(CancellationToken));
#endregion
@@ -444,7 +455,7 @@ partial interface IDynamoDBContext
/// Configured TransactGet objects.
/// Token which can be used to cancel the task.
/// A Task that can be used to poll or wait for results, or both.
- Task ExecuteTransactGetAsync(TransactGet[] transactionParts, CancellationToken cancellationToken = default(CancellationToken));
+ Task ExecuteTransactGetAsync(ITransactGet[] transactionParts, CancellationToken cancellationToken = default(CancellationToken));
#endregion
@@ -456,7 +467,7 @@ partial interface IDynamoDBContext
/// Configured TransactWrite objects.
/// Token which can be used to cancel the task.
/// A Task that can be used to poll or wait for results, or both.
- Task ExecuteTransactWriteAsync(TransactWrite[] transactionParts, CancellationToken cancellationToken = default(CancellationToken));
+ Task ExecuteTransactWriteAsync(ITransactWrite[] transactionParts, CancellationToken cancellationToken = default(CancellationToken));
#endregion
@@ -471,7 +482,7 @@ partial interface IDynamoDBContext
/// Conditions that the results should meet.
///
/// AsyncSearch which can be used to retrieve DynamoDB data.
- AsyncSearch ScanAsync(IEnumerable conditions);
+ IAsyncSearch ScanAsync(IEnumerable conditions);
///
/// Configures an async Scan operation against DynamoDB, finding items
@@ -485,7 +496,7 @@ partial interface IDynamoDBContext
/// AsyncSearch which can be used to retrieve DynamoDB data.
[Obsolete("Use the ScanAsync overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to ScanAsync.")]
- AsyncSearch ScanAsync(IEnumerable conditions, DynamoDBOperationConfig operationConfig = null);
+ IAsyncSearch ScanAsync(IEnumerable conditions, DynamoDBOperationConfig operationConfig = null);
///
/// Configures an async Scan operation against DynamoDB, finding items
@@ -497,7 +508,7 @@ partial interface IDynamoDBContext
///
/// Config object that can be used to override properties on the table's context for this request.
/// AsyncSearch which can be used to retrieve DynamoDB data.
- AsyncSearch ScanAsync(IEnumerable conditions, ScanConfig scanConfig);
+ IAsyncSearch ScanAsync(IEnumerable conditions, ScanConfig scanConfig);
///