/* * Copyright 2012-2013 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; using Amazon.DynamoDBv2.Model; using Amazon.Runtime; using Amazon.Util; using System.Linq; using System.Threading; using System.Collections.Generic; using System.Collections.ObjectModel; namespace Amazon.DynamoDBv2.DocumentModel { public partial class Table { #region Constructor/factory /// /// Creates a Table object with the specified name, using the /// passed-in client to load the table definition. /// The returned table will use the conversion specified by /// AWSConfigs.DynamoDBConfig.ConversionSchema /// /// This method return an exception if the table does not exist within the callback. /// /// Client to use to access DynamoDB. /// Name of the table. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public static void LoadTableAsync(IAmazonDynamoDB ddbClient, string tableName, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { LoadTableAsync(ddbClient,tableName, DynamoDBEntryConversion.CurrentConversion, callback,asyncOptions); } /// /// Creates a Table object with the specified name, using the /// passed-in client to load the table definition. /// /// This method return an exception if the table does not exist within the callback. /// /// Client to use to access DynamoDB. /// Name of the table. /// Conversion to use for converting .NET values to DynamoDB values. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public static void LoadTableAsync(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, AmazonDynamoDBCallback
callback, AsyncOptions asyncOptions = null) { var config = new TableConfig(tableName, conversion, DynamoDBConsumer.DocumentModel, storeAsEpoch: null); LoadTableAsync(ddbClient, config, callback, asyncOptions); } /// /// Creates a Table object with the specified configuration, using the /// passed-in client to load the table definition. /// /// This method will throw an exception if the table does not exist. /// /// Client to use to access DynamoDB. /// Configuration to use for the table. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public static void LoadTableAsync(IAmazonDynamoDB ddbClient, TableConfig config, AmazonDynamoDBCallback
callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions??new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync
( ()=>{ return LoadTable(ddbClient, config); },asyncOptions,callback); } #endregion #region PutItemAsync /// /// Initiates the asynchronous execution of the PutItem operation. /// /// Document to save. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void PutItemAsync(Document doc, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return PutItemHelper(doc, null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the PutItem operation. /// /// Document to save. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void PutItemAsync(Document doc, PutItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return PutItemHelper(doc, config); }, asyncOptions, callback); } #endregion #region GetItemAsync /// /// Initiates the asynchronous execution of the GetItem operation. /// /// Hash key element of the document. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void GetItemAsync(Primitive hashKey, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return GetItemHelper(MakeKey(hashKey, null), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the GetItem operation. /// /// Hash key element of the document. /// Range key element of the document. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void GetItemAsync(Primitive hashKey, Primitive rangeKey, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return GetItemHelper(MakeKey(hashKey, rangeKey), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the GetItem operation. /// /// Hash key element of the document. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void GetItemAsync(Primitive hashKey, GetItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return GetItemHelper(MakeKey(hashKey, null), config); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the GetItem operation. /// /// Hash key element of the document. /// Range key element of the document. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void GetItemAsync(Primitive hashKey, Primitive rangeKey, GetItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return GetItemHelper(MakeKey(hashKey, rangeKey), config); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the GetItem operation. /// /// Key of the document. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void GetItemAsync(IDictionary key, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return GetItemHelper(MakeKey(key), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the GetItem operation. /// /// Ley of the document. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void GetItemAsync(IDictionary key, GetItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return GetItemHelper(MakeKey(key), config); }, asyncOptions, callback); } #endregion #region UpdateItemAsync /// /// Initiates the asynchronous execution of the UpdateItem operation. /// /// Document to update. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void UpdateItemAsync(Document doc, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return UpdateHelper(doc, MakeKey(doc), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the UpdateItem operation. /// /// Attributes to update. /// Hash key element of the document. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void UpdateItemAsync(Document doc, Primitive hashKey, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return UpdateHelper(doc, MakeKey(hashKey, null), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the UpdateItem operation. /// /// Attributes to update. /// Hash key element of the document. /// Range key element of the document. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void UpdateItemAsync(Document doc, Primitive hashKey, Primitive rangeKey, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return UpdateHelper(doc, MakeKey(hashKey, rangeKey), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the UpdateItem operation. /// /// Attributes to update. /// Key of the document. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void UpdateItemAsync(Document doc, IDictionary key, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return UpdateHelper(doc, MakeKey(key), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the UpdateItem operation. /// /// Document to update. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void UpdateItemAsync(Document doc, UpdateItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return UpdateHelper(doc, MakeKey(doc), config); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the UpdateItem operation. /// /// Attributes to update. /// Hash key element of the document. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void UpdateItemAsync(Document doc, Primitive hashKey, UpdateItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return UpdateHelper(doc, MakeKey(hashKey, null), config); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the UpdateItem operation. /// /// Attributes to update. /// Hash key element of the document. /// Range key element of the document. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void UpdateItemAsync(Document doc, Primitive hashKey, Primitive rangeKey, UpdateItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return UpdateHelper(doc, MakeKey(hashKey, rangeKey), config); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the UpdateItem operation. /// /// Attributes to update. /// Key of the document. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void UpdateItemAsync(Document doc, IDictionary key, UpdateItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { return UpdateHelper(doc, MakeKey(key), config); }, asyncOptions, callback); } #endregion #region DeleteItemAsync /// /// Initiates the asynchronous execution of the DeleteItem operation. /// /// Document to delete. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void DeleteItemAsync(Document document, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { DeleteHelper(MakeKey(document), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the DeleteItem operation. /// /// Hash key element of the document. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void DeleteItemAsync(Primitive hashKey, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { DeleteHelper(MakeKey(hashKey, null), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the DeleteItem operation. /// /// Hash key element of the document. /// Range key element of the document. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void DeleteItemAsync(Primitive hashKey, Primitive rangeKey, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { DeleteHelper(MakeKey(hashKey, rangeKey), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the DeleteItem operation. /// /// Key of the document. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void DeleteItemAsync(IDictionary key, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { DeleteHelper(MakeKey(key), null); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the DeleteItem operation. /// /// Document to delete. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void DeleteItemAsync(Document document, DeleteItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { DeleteHelper(MakeKey(document), config); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the DeleteItem operation. /// /// Hash key element of the document. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void DeleteItemAsync(Primitive hashKey, DeleteItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { DeleteHelper(MakeKey(hashKey, null), config); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the DeleteItem operation. /// /// Hash key element of the document. /// Range key element of the document. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void DeleteItemAsync(Primitive hashKey, Primitive rangeKey, DeleteItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { DeleteHelper(MakeKey(hashKey, rangeKey), config); }, asyncOptions, callback); } /// /// Initiates the asynchronous execution of the DeleteItem operation. /// /// Key of the document. /// Configuration to use. /// The callback that will be invoked when the asynchronous operation completes. /// An instance of AsyncOptions that specifies how the async method should be executed. public void DeleteItemAsync(IDictionary key, DeleteItemOperationConfig config, AmazonDynamoDBCallback callback, AsyncOptions asyncOptions = null) { asyncOptions = asyncOptions ?? new AsyncOptions(); DynamoDBAsyncExecutor.ExecuteAsync( () => { DeleteHelper(MakeKey(key), config); }, asyncOptions, callback); } #endregion } }