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