/*
* 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;
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 PutItem
///
/// Puts a document into DynamoDB, using optional configs.
///
/// Document to save.
/// Configuration to use.
/// Null or updated attributes, depending on config.
public Document PutItem(Document doc, PutItemOperationConfig config = null)
{
return PutItemHelper(doc, config);
}
///
/// Puts a document into DynamoDB, using optional configs.
///
/// Document to save.
/// Configuration to use.
/// True if put is successful or false if the condition in the config was not met.
public bool TryPutItem(Document doc, PutItemOperationConfig config = null)
{
try
{
PutItemHelper(doc, config);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}
#endregion
#region GetItem
///
/// Gets a document from DynamoDB by hash primary key, using specified configs.
///
/// Hash key element of the document.
/// Configuration to use.
/// Document from DynamoDB.
public Document GetItem(Primitive hashKey, GetItemOperationConfig config = null)
{
return GetItem(hashKey, null, config);
}
///
/// Gets a document from DynamoDB by hash-and-range primary key,
/// using specified configs.
///
/// Hash key element of the document.
/// Range key element of the document.
/// Configuration to use.
/// Document from DynamoDB.
public Document GetItem(Primitive hashKey, Primitive rangeKey, GetItemOperationConfig config = null)
{
return GetItemHelper(MakeKey(hashKey, rangeKey), config);
}
///
/// Gets a document from DynamoDB by key, using specified configs.
///
/// Key of the document.
/// Configuration to use.
/// Document from DynamoDB.
public Document GetItem(IDictionary key, GetItemOperationConfig config = null)
{
return GetItemHelper(MakeKey(key), config);
}
#endregion
#region UpdateItem
///
/// Update a document in DynamoDB, using specified config.
///
/// Document to update.
/// Configuration to use.
/// Null or updated attributes, depending on config.
///
public Document UpdateItem(Document doc, UpdateItemOperationConfig config = null)
{
return UpdateHelper(doc, MakeKey(doc), config);
}
///
/// Update a document in DynamoDB, using specified config.
///
/// Document to update.
/// Configuration to use.
/// True if updated or false if the condition in the config was not met.
///
public bool TryUpdateItem(Document doc, UpdateItemOperationConfig config = null)
{
try
{
UpdateHelper(doc, MakeKey(doc), config);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}
///
/// Update a document in DynamoDB, with a key to identify the
/// document, and using the specified config.
///
/// Attributes to update.
/// Key of the document.
/// Configuration to use.
/// Null or updated attributes, depending on config.
///
public Document UpdateItem(Document doc, IDictionary key, UpdateItemOperationConfig config = null)
{
return UpdateHelper(doc, MakeKey(key), config);
}
///
/// Update a document in DynamoDB, with a key to identify the
/// document, and using the specified config.
///
/// Attributes to update.
/// Key of the document.
/// Configuration to use.
/// True if updated or false if the condition in the config was not met.
///
public bool TryUpdateItem(Document doc, IDictionary key, UpdateItemOperationConfig config = null)
{
try
{
UpdateHelper(doc, MakeKey(key), config);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}
///
/// Update a document in DynamoDB, with a hash primary key to identify
/// the document, and using the specified config.
///
/// Attributes to update.
/// Hash key element of the document.
/// Configuration to use.
/// Null or updated attributes, depending on config.
///
public Document UpdateItem(Document doc, Primitive hashKey, UpdateItemOperationConfig config = null)
{
return UpdateHelper(doc, MakeKey(hashKey, null), config);
}
///
/// Update a document in DynamoDB, with a hash primary key to identify
/// the document, and using the specified config.
///
/// Attributes to update.
/// Hash key element of the document.
/// Configuration to use.
/// True if updated or false if the condition in the config was not met.
///
public bool TryUpdateItem(Document doc, Primitive hashKey, UpdateItemOperationConfig config = null)
{
try
{
UpdateHelper(doc, MakeKey(hashKey, null), config);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}
///
/// Update a document in DynamoDB, with a hash-and-range primary key to identify
/// the document, and using the specified config.
///
/// Attributes to update.
/// Hash key element of the document.
/// Range key element of the document.
/// Configuration to use.
/// Null or updated attributes, depending on config.
///
public Document UpdateItem(Document doc, Primitive hashKey, Primitive rangeKey, UpdateItemOperationConfig config = null)
{
return UpdateHelper(doc, MakeKey(hashKey, rangeKey), config);
}
///
/// Update a document in DynamoDB, with a hash-and-range primary key to identify
/// the document, and using the specified config.
///
/// Attributes to update.
/// Hash key element of the document.
/// Range key element of the document.
/// Configuration to use.
/// True if updated or false if the condition in the config was not met.
///
public bool TryUpdateItem(Document doc, Primitive hashKey, Primitive rangeKey, UpdateItemOperationConfig config = null)
{
try
{
UpdateHelper(doc, MakeKey(hashKey, rangeKey), config);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}
#endregion
#region DeleteItem
///
/// Delete a document in DynamoDB, using specified configs.
///
/// If the condition set on the config fails.
/// Document to delete.
/// Configuration to use.
/// Null or old attributes, depending on config.
public Document DeleteItem(Document document, DeleteItemOperationConfig config = null)
{
return DeleteHelper(MakeKey(document), config);
}
///
/// Delete a document in DynamoDB, using specified configs.
///
/// Document to delete.
/// Configuration to use.
/// True if deleted or false if the condition in the config was not met.
public bool TryDeleteItem(Document document, DeleteItemOperationConfig config = null)
{
try
{
DeleteItem(document, config);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}
///
/// Delete a document in DynamoDB, identified by hash-key,
/// using the specified configs.
///
/// If the condition set on the config fails.
/// Hash key element of the document.
/// Configuration to use.
/// Null or old attributes, depending on config.
public Document DeleteItem(Primitive hashKey, DeleteItemOperationConfig config = null)
{
return DeleteHelper(MakeKey(hashKey, null), config);
}
///
/// Delete a document in DynamoDB, identified by a hash primary key,
/// using specified configs.
///
/// Hash key element of the document.
/// Configuration to use.
/// True if deleted or false if the condition in the config was not met.
public bool TryDeleteItem(Primitive hashKey, DeleteItemOperationConfig config = null)
{
try
{
DeleteItem(hashKey, config);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}
///
/// Delete a document in DynamoDB, identified by hash-and-range primary key,
/// using the specified configs.
///
/// If the condition set on the config fails.
/// Hash key element of the document.
/// Range key element of the document.
/// Configuration to use.
/// Null or old attributes, depending on config.
public Document DeleteItem(Primitive hashKey, Primitive rangeKey, DeleteItemOperationConfig config = null)
{
return DeleteHelper(MakeKey(hashKey, rangeKey), config);
}
///
/// Delete a document in DynamoDB, identified by hash-and-range primary key,
/// using the specified configs.
///
/// Hash key element of the document.
/// Range key element of the document.
/// Configuration to use.
/// True if deleted or false if the condition in the config was not met.
public bool TryDeleteItem(Primitive hashKey, Primitive rangeKey, DeleteItemOperationConfig config = null)
{
try
{
DeleteItem(hashKey, rangeKey, config);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}
///
/// Delete a document in DynamoDB, identified by a key, using specified configs.
///
/// If the condition set on the config fails.
/// Key of the document.
/// Configuration to use.
/// Null or old attributes, depending on config.
public Document DeleteItem(IDictionary key, DeleteItemOperationConfig config = null)
{
return DeleteHelper(MakeKey(key), config);
}
///
/// Delete a document in DynamoDB, identified by a key, using specified configs.
///
/// Key of the document.
/// Configuration to use.
/// True if deleted or false if the condition in the config was not met.
public bool TryDeleteItem(IDictionary key, DeleteItemOperationConfig config = null)
{
try
{
DeleteHelper(MakeKey(key), config);
return true;
}
catch (ConditionalCheckFailedException)
{
return false;
}
}
#endregion
}
}