Example #1
0
 internal static void LoadTableAsync(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion, AmazonDynamoDBCallback<Table> callback, AsyncOptions asyncOptions = null)
 {
     asyncOptions = asyncOptions??new AsyncOptions();
     DynamoDBAsyncExecutor.ExecuteAsync<Table>(
     ()=>{
         return LoadTable(ddbClient,tableName,consumer,conversion);
     },asyncOptions,callback);
 }
Example #2
0
        /// <summary>
        /// Converts this ExpectedValue instance to Amazon.DynamoDBv2.Model.ExpectedAttributeValue
        /// </summary>
        /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
        /// <returns>Amazon.DynamoDBv2.Model.ExpectedAttributeValue</returns>
        public ExpectedAttributeValue ToExpectedAttributeValue(DynamoDBEntryConversion conversion)
        {
            var eav = new ExpectedAttributeValue();

            if (this.Exists)
            {
                eav.ComparisonOperator = EnumMapper.Convert(this.Comparison);
                foreach (var val in this.Values)
                    eav.AttributeValueList.Add(val.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion)));
            }
            else
                eav.Exists = this.Exists;

            return eav;
        }
        internal  Dictionary<string, AttributeValue> ConvertToAttributeValues(DynamoDBEntryConversion conversion)
        {
            var convertedValues = new Dictionary<string, AttributeValue>();
            if (this._expressionAttributeValues != null)
            {
                foreach (var kvp in this.ExpressionAttributeValues)
                {
                    if (kvp.Value == null)
                        convertedValues[kvp.Key] = new AttributeValue { NULL = true };
                    else
                        convertedValues[kvp.Key] = kvp.Value.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion));
                }
            }

            return convertedValues;
        }
Example #4
0
        /// <summary>
        /// Creates a list of AttributeValues from a list of DynamoDBEntry items
        /// </summary>
        /// <param name="conversion"></param>
        /// <param name="isEmptyStringValueEnabled"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        protected static List <AttributeValue> ConvertToAttributeValues(DynamoDBEntryConversion conversion,
                                                                        bool isEmptyStringValueEnabled, params DynamoDBEntry[] values)
        {
            List <AttributeValue> attributes = new List <AttributeValue>();

            foreach (DynamoDBEntry value in values)
            {
                var            attributeConversionConfig = new DynamoDBEntry.AttributeConversionConfig(conversion, isEmptyStringValueEnabled);
                AttributeValue nativeValue = value.ConvertToAttributeValue(attributeConversionConfig);
                if (nativeValue != null)
                {
                    attributes.Add(nativeValue);
                }
            }
            return(attributes);
        }
Example #5
0
        private Dictionary <string, Condition> ToConditions(DynamoDBEntryConversion conversion,
                                                            IEnumerable <string> epochAttributes, bool isEmptyStringValueEnabled)
        {
            var dic = new Dictionary <string, Condition>();

            foreach (var kvp in Conditions)
            {
                string          name = kvp.Key;
                FilterCondition fc   = kvp.Value;
                bool            convertToEpochSeconds = epochAttributes != null && epochAttributes.Contains(name);
                Condition       condition             = fc.ToCondition(conversion, convertToEpochSeconds, name, isEmptyStringValueEnabled);

                dic[name] = condition;
            }

            return(dic);
        }
Example #6
0
        internal TableConfig(string tableName, DynamoDBEntryConversion conversion, Table.DynamoDBConsumer consumer,
                             IEnumerable <string> storeAsEpoch, bool isEmptyStringValueEnabled)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                throw new ArgumentNullException("tableName");
            }

            TableName  = tableName;
            Conversion = conversion;
            Consumer   = consumer;
            IsEmptyStringValueEnabled = isEmptyStringValueEnabled;
            AttributesToStoreAsEpoch  = new List <string>();
            if (storeAsEpoch != null)
            {
                AttributesToStoreAsEpoch.AddRange(storeAsEpoch);
            }
        }
Example #7
0
        private void LoadTables(DynamoDBEntryConversion conversion, out Table hashTable, out Table hashRangeTable)
        {
            TableCache.Clear();

            using (var counter = CountServiceResponses(Client))
            {
                // Load table using TryLoadTable API
                hashTable = null;
                Assert.IsFalse(Table.TryLoadTable(Client, "FakeHashTableThatShouldNotExist", conversion, out hashTable));
                Assert.AreEqual(0, counter.ResponseCount);
                Assert.IsTrue(Table.TryLoadTable(Client, hashTableName, conversion, out hashTable));
                Assert.AreEqual(1, counter.ResponseCount);

                Assert.IsNotNull(hashTable);
                Assert.AreEqual(hashTableName, hashTable.TableName);
                Assert.AreEqual(3, hashTable.Attributes.Count);
                Assert.AreEqual(1, hashTable.GlobalSecondaryIndexes.Count);
                Assert.AreEqual(1, hashTable.GlobalSecondaryIndexes["GlobalIndex"].ProvisionedThroughput.ReadCapacityUnits);
                Assert.AreEqual(1, hashTable.GlobalSecondaryIndexNames.Count);
                Assert.AreEqual(1, hashTable.HashKeys.Count);
                Assert.AreEqual(0, hashTable.RangeKeys.Count);
                Assert.AreEqual(1, hashTable.Keys.Count);
                Assert.AreEqual(0, hashTable.LocalSecondaryIndexes.Count);
                Assert.AreEqual(0, hashTable.LocalSecondaryIndexNames.Count);

                // Load table using LoadTable API (may throw an exception)
                AssertExtensions.ExpectException(() => Table.LoadTable(Client, "FakeHashRangeTableThatShouldNotExist", conversion));
                Assert.AreEqual(1, counter.ResponseCount);
                hashRangeTable = Table.LoadTable(Client, hashRangeTableName, conversion);
                Assert.AreEqual(2, counter.ResponseCount);
                Assert.IsNotNull(hashRangeTable);
                Assert.AreEqual(hashRangeTableName, hashRangeTable.TableName);
                Assert.AreEqual(5, hashRangeTable.Attributes.Count);
                Assert.AreEqual(1, hashRangeTable.GlobalSecondaryIndexes.Count);
                Assert.AreEqual(1, hashRangeTable.GlobalSecondaryIndexes["GlobalIndex"].ProvisionedThroughput.ReadCapacityUnits);
                Assert.AreEqual(1, hashRangeTable.GlobalSecondaryIndexNames.Count);
                Assert.AreEqual(1, hashRangeTable.HashKeys.Count);
                Assert.AreEqual(1, hashRangeTable.RangeKeys.Count);
                Assert.AreEqual(2, hashRangeTable.Keys.Count);
                Assert.AreEqual(1, hashRangeTable.LocalSecondaryIndexes.Count);
                Assert.AreEqual(2, hashRangeTable.LocalSecondaryIndexes["LocalIndex"].KeySchema.Count);
                Assert.AreEqual(1, hashRangeTable.LocalSecondaryIndexNames.Count);
            }
        }
Example #8
0
        /// <summary>
        /// Converts this ExpectedValue instance to Amazon.DynamoDBv2.Model.ExpectedAttributeValue
        /// </summary>
        /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
        /// <returns>Amazon.DynamoDBv2.Model.ExpectedAttributeValue</returns>
        public ExpectedAttributeValue ToExpectedAttributeValue(DynamoDBEntryConversion conversion)
        {
            var eav = new ExpectedAttributeValue();

            if (this.Exists)
            {
                eav.ComparisonOperator = EnumMapper.Convert(this.Comparison);
                foreach (var val in this.Values)
                {
                    eav.AttributeValueList.Add(val.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion)));
                }
            }
            else
            {
                eav.Exists = this.Exists;
            }

            return(eav);
        }
Example #9
0
        /// <summary>
        /// Creates a map of attribute names mapped to AttributeValue objects.
        /// </summary>
        /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
        /// <returns></returns>
        public Dictionary <string, AttributeValue> ToAttributeMap(DynamoDBEntryConversion conversion)
        {
            if (conversion == null)
            {
                throw new ArgumentNullException("conversion");
            }
            Dictionary <string, AttributeValue> ret = new Dictionary <string, AttributeValue>();

            foreach (var attribute in currentValues)
            {
                AttributeValue value = attribute.Value.ConvertToAttributeValue(new AttributeConversionConfig(conversion));
                if (value != null)
                {
                    ret.Add(attribute.Key, value);
                }
            }

            return(ret);
        }
Example #10
0
        private void LoadTables(DynamoDBEntryConversion conversion, out Table hashTable, out Table hashRangeTable)
        {
            SharedTestFixture.TableCache.Clear();

            using (var counter = DynamoDBTestsFixture.CountServiceResponses(Client))
            {
                // Load table using TryLoadTable API
                hashTable = null;
                Assert.False(Table.TryLoadTable(Client, "FakeHashTableThatShouldNotExist", conversion, out hashTable));
                Assert.Equal(0, counter.ResponseCount);
                Assert.True(Table.TryLoadTable(Client, SharedTestFixture.hashTableName, conversion, out hashTable));
                Assert.Equal(1, counter.ResponseCount);

                Assert.NotNull(hashTable);
                Assert.Equal(SharedTestFixture.hashTableName, hashTable.TableName);
                Assert.Equal(3, hashTable.Attributes.Count);
                Assert.Equal(1, hashTable.GlobalSecondaryIndexes.Count);
                Assert.Equal(1, hashTable.GlobalSecondaryIndexNames.Count);
                Assert.Equal(1, hashTable.HashKeys.Count);
                Assert.Equal(0, hashTable.RangeKeys.Count);
                Assert.Equal(1, hashTable.Keys.Count);
                Assert.Equal(0, hashTable.LocalSecondaryIndexes.Count);
                Assert.Equal(0, hashTable.LocalSecondaryIndexNames.Count);

                // Load table using LoadTable API (may throw an exception)
                Assert.Throws <ResourceNotFoundException>(() => Table.LoadTable(Client, "FakeHashRangeTableThatShouldNotExist", conversion));
                Assert.Equal(1, counter.ResponseCount);
                hashRangeTable = Table.LoadTable(Client, SharedTestFixture.hashRangeTableName, conversion);
                Assert.Equal(2, counter.ResponseCount);
                Assert.NotNull(hashRangeTable);
                Assert.Equal(SharedTestFixture.hashRangeTableName, hashRangeTable.TableName);
                Assert.Equal(5, hashRangeTable.Attributes.Count);
                Assert.Equal(1, hashRangeTable.GlobalSecondaryIndexes.Count);
                Assert.Equal(1, hashRangeTable.GlobalSecondaryIndexNames.Count);
                Assert.Equal(1, hashRangeTable.HashKeys.Count);
                Assert.Equal(1, hashRangeTable.RangeKeys.Count);
                Assert.Equal(2, hashRangeTable.Keys.Count);
                Assert.Equal(1, hashRangeTable.LocalSecondaryIndexes.Count);
                Assert.Equal(2, hashRangeTable.LocalSecondaryIndexes["LocalIndex"].KeySchema.Count);
                Assert.Equal(1, hashRangeTable.LocalSecondaryIndexNames.Count);
            }
        }
Example #11
0
            public Condition ToCondition(DynamoDBEntryConversion conversion)
            {
                var attributeValues = AttributeValues;
                if (attributeValues == null)
                {
                    attributeValues = new List<AttributeValue>();
                    foreach(var entry in DynamoDBEntries)
                    {
                        var attributeValue = entry.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion));
                        attributeValues.Add(attributeValue);
                    }
                }

                var condition = new Condition
                {
                    ComparisonOperator = ComparisonOperator,
                    AttributeValueList = attributeValues
                };
                return condition;
            }
Example #12
0
        internal static ExpectedAttributeValue ToExpectedAttributeValue(bool exists, IEnumerable <DynamoDBEntry> values, ScanOperator comparison,
                                                                        DynamoDBEntryConversion conversion)
        {
            var eav = new ExpectedAttributeValue();

            if (exists)
            {
                eav.ComparisonOperator = EnumMapper.Convert(comparison);
                foreach (var val in values)
                {
                    eav.AttributeValueList.Add(val.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion)));
                }
            }
            else
            {
                eav.Exists = exists;
            }

            return(eav);
        }
Example #13
0
        internal Dictionary <string, ExpectedAttributeValue> ToExpectedAttributeMap(DynamoDBEntryConversion conversion, IEnumerable <string> epochAttributes)
        {
            if (conversion == null)
            {
                throw new ArgumentNullException("conversion");
            }
            Dictionary <string, ExpectedAttributeValue> ret = new Dictionary <string, ExpectedAttributeValue>();

            foreach (var kvp in currentValues)
            {
                var attributeName = kvp.Key;
                var entry         = kvp.Value;

                ApplyEpochRules(epochAttributes, attributeName, ref entry);

                ret.Add(attributeName, entry.ConvertToExpectedAttributeValue(new AttributeConversionConfig(conversion)));
            }

            return(ret);
        }
Example #14
0
        private Table(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion)
        {
#if (WIN_RT || WINDOWS_PHONE)
            DDBClient = ddbClient as AmazonDynamoDBClient;
#else
            DDBClient = ddbClient;
#endif

            TableConsumer             = consumer;
            TableName                 = tableName;
            Keys                      = new Dictionary <string, KeyDescription>();
            HashKeys                  = new List <string>();
            RangeKeys                 = new List <string>();
            LocalSecondaryIndexes     = new Dictionary <string, LocalSecondaryIndexDescription>();
            LocalSecondaryIndexNames  = new List <string>();
            GlobalSecondaryIndexes    = new Dictionary <string, GlobalSecondaryIndexDescription>();
            GlobalSecondaryIndexNames = new List <string>();
            Attributes                = new List <AttributeDefinition>();
            Conversion                = conversion;
        }
Example #15
0
        public DynamoDBFlatConfig(DynamoDBOperationConfig operationConfig, DynamoDBContextConfig contextConfig)
        {
            if (operationConfig == null)
            {
                operationConfig = _emptyOperationConfig;
            }
            if (contextConfig == null)
            {
                contextConfig = _emptyContextConfig;
            }

            bool   consistentRead            = operationConfig.ConsistentRead ?? contextConfig.ConsistentRead ?? false;
            bool   skipVersionCheck          = operationConfig.SkipVersionCheck ?? contextConfig.SkipVersionCheck ?? false;
            bool   ignoreNullValues          = operationConfig.IgnoreNullValues ?? contextConfig.IgnoreNullValues ?? false;
            bool   isEmptyStringValueEnabled = operationConfig.IsEmptyStringValueEnabled ?? contextConfig.IsEmptyStringValueEnabled ?? false;
            string overrideTableName         =
                !string.IsNullOrEmpty(operationConfig.OverrideTableName) ? operationConfig.OverrideTableName : string.Empty;
            string tableNamePrefix =
                !string.IsNullOrEmpty(operationConfig.TableNamePrefix) ? operationConfig.TableNamePrefix :
                !string.IsNullOrEmpty(contextConfig.TableNamePrefix) ? contextConfig.TableNamePrefix : string.Empty;
            bool   backwardQuery = operationConfig.BackwardQuery ?? false;
            string indexName     =
                !string.IsNullOrEmpty(operationConfig.IndexName) ? operationConfig.IndexName : DefaultIndexName;
            List <ScanCondition>      queryFilter         = operationConfig.QueryFilter ?? new List <ScanCondition>();
            ConditionalOperatorValues conditionalOperator = operationConfig.ConditionalOperator;
            DynamoDBEntryConversion   conversion          = operationConfig.Conversion ?? contextConfig.Conversion ?? DynamoDBEntryConversion.CurrentConversion;

            ConsistentRead            = consistentRead;
            SkipVersionCheck          = skipVersionCheck;
            IgnoreNullValues          = ignoreNullValues;
            IsEmptyStringValueEnabled = isEmptyStringValueEnabled;
            OverrideTableName         = overrideTableName;
            TableNamePrefix           = tableNamePrefix;
            BackwardQuery             = backwardQuery;
            IndexName           = indexName;
            QueryFilter         = queryFilter;
            ConditionalOperator = conditionalOperator;
            Conversion          = conversion;

            State = new OperationState();
        }
        /// <summary>
        /// Creates a map of attribute names mapped to AttributeValueUpdate objects.
        /// </summary>
        /// <param name="changedAttributesOnly">If true, only attributes that have been changed will be in the map.</param>
        /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
        /// <returns></returns>
        public Dictionary <string, AttributeValueUpdate> ToAttributeUpdateMap(DynamoDBEntryConversion conversion, bool changedAttributesOnly)
        {
            if (conversion == null)
            {
                throw new ArgumentNullException("conversion");
            }
            Dictionary <string, AttributeValueUpdate> ret = new Dictionary <string, AttributeValueUpdate>();

            foreach (var attribute in currentValues)
            {
                string        name  = attribute.Key;
                DynamoDBEntry value = attribute.Value;

                if (!changedAttributesOnly || this.IsAttributeChanged(name))
                {
                    ret.Add(name, value.ConvertToAttributeUpdateValue(new AttributeConversionConfig(conversion)));
                }
            }

            return(ret);
        }
Example #17
0
            public Condition ToCondition(DynamoDBEntryConversion conversion)
            {
                var attributeValues = AttributeValues;

                if (attributeValues == null)
                {
                    attributeValues = new List <AttributeValue>();
                    foreach (var entry in DynamoDBEntries)
                    {
                        var attributeValue = entry.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion));
                        attributeValues.Add(attributeValue);
                    }
                }

                var condition = new Condition
                {
                    ComparisonOperator = ComparisonOperator,
                    AttributeValueList = attributeValues
                };

                return(condition);
            }
Example #18
0
        private bool TryToScalar(object value, Type type, DynamoDBFlatConfig flatConfig, ref DynamoDBEntry entry)
        {
            var typeWrapper = TypeFactory.GetTypeInfo(type);
            var elementType = Utils.GetElementType(type);

            if (elementType != null)
            {
                IEnumerable enumerable = value as IEnumerable;

                // Strings are collections of chars, don't treat them as collections
                if (enumerable == null || value is string)
                {
                    // Only convert if value matches collection element type
                    if (TypeFactory.GetTypeInfo(value.GetType()).IsAssignableFrom(TypeFactory.GetTypeInfo(elementType)))
                    {
                        DynamoDBEntryConversion conversion = flatConfig.Conversion;
                        if (conversion.HasConverter(elementType))
                        {
                            if (conversion.TryConvertToEntry(elementType, value, out entry))
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            try
                            {
                                entry = SerializeToDocument(value, elementType, flatConfig);
                                return(true);
                            }
                            catch { }
                        }
                    }
                }
            }

            return(false);
        }
Example #19
0
        private void TestEnums(DynamoDBEntryConversion conversion)
        {
            Product product = new Product
            {
                Id          = 1,
                Name        = "CloudSpotter",
                CompanyName = "CloudsAreGrate",
                Price       = 1200,
                TagSet      = new HashSet <string> {
                    "Prod", "1.0"
                },
                CurrentStatus   = Status.Active,
                FormerStatus    = Status.Upcoming,
                Supports        = Support.Unix | Support.Windows,
                PreviousSupport = null,
            };

            // try round-tripping the enums
            var doc1     = Context.ToDocument(product);
            var product2 = Context.FromDocument <Product>(doc1);

            Assert.AreEqual(product.CurrentStatus, product2.CurrentStatus);
            Assert.AreEqual(product.FormerStatus, product2.FormerStatus);
            Assert.AreEqual(product.Supports, product2.Supports);

            // try changing underlying enum data to strings
            var doc2 = Context.ToDocument(product);

            doc2["CurrentStatus"] = product.CurrentStatus.ToString();
            doc2["FormerStatus"]  = product.FormerStatus.ToString();
            doc2["Supports"]      = product.Supports.ToString();
            doc2 = doc2.ForceConversion(conversion);
            var product3 = Context.FromDocument <Product>(doc2);

            Assert.AreEqual(product.CurrentStatus, product3.CurrentStatus);
            Assert.AreEqual(product.FormerStatus, product3.FormerStatus);
            Assert.AreEqual(product.Supports, product3.Supports);
        }
Example #20
0
        internal static void ApplyExpression(QueryRequest request, DynamoDBEntryConversion conversion,
                                             Expression keyExpression, Expression filterExpression)
        {
            if (keyExpression == null)
            {
                keyExpression = new Expression();
            }
            if (filterExpression == null)
            {
                filterExpression = new Expression();
            }

            if (!keyExpression.IsSet && !filterExpression.IsSet)
            {
                return;
            }

            if (keyExpression.IsSet)
            {
                request.KeyConditionExpression = keyExpression.ExpressionStatement;
            }
            if (filterExpression.IsSet)
            {
                request.FilterExpression = filterExpression.ExpressionStatement;
            }

            var kean        = keyExpression.ExpressionAttributeNames;
            var fean        = filterExpression.ExpressionAttributeNames;
            var combinedEan = Common.Combine(kean, fean, StringComparer.Ordinal);

            request.ExpressionAttributeNames = combinedEan;

            var keav        = new Document(keyExpression.ExpressionAttributeValues).ForceConversion(conversion);
            var feav        = new Document(filterExpression.ExpressionAttributeValues).ForceConversion(conversion);
            var combinedEav = Common.Combine(keav, feav, null);

            request.ExpressionAttributeValues = ConvertToAttributeValues(combinedEav, conversion);
        }
Example #21
0
        internal Dictionary <string, AttributeValueUpdate> ToAttributeUpdateMap(DynamoDBEntryConversion conversion, bool changedAttributesOnly, IEnumerable <string> epochAttributes)
        {
            if (conversion == null)
            {
                throw new ArgumentNullException("conversion");
            }
            Dictionary <string, AttributeValueUpdate> ret = new Dictionary <string, AttributeValueUpdate>();

            foreach (var kvp in currentValues)
            {
                string        attributeName = kvp.Key;
                DynamoDBEntry entry         = kvp.Value;

                ApplyEpochRules(epochAttributes, attributeName, ref entry);

                if (!changedAttributesOnly || this.IsAttributeChanged(attributeName))
                {
                    ret.Add(attributeName, entry.ConvertToAttributeUpdateValue(new AttributeConversionConfig(conversion)));
                }
            }

            return(ret);
        }
Example #22
0
        private Dictionary <string, ExpectedAttributeValue> ToExpectedAttributeMap(DynamoDBEntryConversion conversion, IEnumerable <string> epochAttributes)
        {
            Dictionary <string, ExpectedAttributeValue> ret = new Dictionary <string, ExpectedAttributeValue>();

            foreach (var kvp in ExpectedValues)
            {
                string        attributeName = kvp.Key;
                ExpectedValue expectedValue = kvp.Value;

                ExpectedAttributeValue eav;
                if (epochAttributes != null && epochAttributes.Contains(attributeName))
                {
                    var values = expectedValue.Values.Select(p => Document.DateTimeToEpochSeconds(p, attributeName)).ToList();
                    eav = ExpectedValue.ToExpectedAttributeValue(expectedValue.Exists, values, expectedValue.Comparison, conversion);
                }
                else
                {
                    eav = expectedValue.ToExpectedAttributeValue(conversion);
                }
                ret[attributeName] = eav;
            }

            return(ret);
        }
Example #23
0
        internal Dictionary <string, AttributeValue> ConvertToAttributeValues(DynamoDBEntryConversion conversion)
        {
            var convertedValues = new Dictionary <string, AttributeValue>();

            if (this._expressionAttributeValues != null)
            {
                foreach (var kvp in this.ExpressionAttributeValues)
                {
                    if (kvp.Value == null)
                    {
                        convertedValues[kvp.Key] = new AttributeValue {
                            NULL = true
                        }
                    }
                    ;
                    else
                    {
                        convertedValues[kvp.Key] = kvp.Value.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion));
                    }
                }
            }

            return(convertedValues);
        }
Example #24
0
        /// <summary>
        /// Converts filter to a map of conditions
        /// </summary>
        /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
        /// <returns>Map from attribute name to condition</returns>
        public Dictionary<string, Condition> ToConditions(DynamoDBEntryConversion conversion)
        {
            var dic = new Dictionary<string, Condition>();
            foreach(var kvp in Conditions)
            {
                string name = kvp.Key;
                FilterCondition fc = kvp.Value;
                Condition condition = fc.ToCondition(conversion);

                dic[name] = condition;
            }

            return dic;
        }
Example #25
0
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 ///
 /// This method will throw an exception if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
 /// <returns>Table object representing the specified table.</returns>
 public static Table LoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion)
 {
     return(LoadTable(ddbClient, tableName, DynamoDBConsumer.DocumentModel, conversion));
 }
Example #26
0
        internal static Table LoadTable(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion)
        {
            Table table = new Table(ddbClient, tableName, consumer, conversion);

            table.LoadTableInfo();
            return(table);
        }
Example #27
0
        // Returns a DynamoDB entry for the given JSON data
        private static DynamoDBEntry ToEntry(JsonData data, DynamoDBEntryConversion conversion)
        {
            if (data == null)
            {
                return(new DynamoDBNull());
            }

            if (data.IsObject)
            {
                var document = new Document();
                foreach (var propertyName in data.PropertyNames)
                {
                    var nestedData = data[propertyName];
                    var entry      = ToEntry(nestedData, conversion);
                    document[propertyName] = entry;
                }
                return(document);
            }

            if (data.IsArray)
            {
                var list = new DynamoDBList();
                for (int i = 0; i < data.Count; i++)
                {
                    var item  = data[i];
                    var entry = ToEntry(item, conversion);
                    list.Add(entry);
                }
                return(list);
            }

            if (data.IsBoolean)
            {
                return(new UnconvertedDynamoDBEntry((bool)data).Convert(conversion));
            }

            if (data.IsDouble)
            {
                return(new UnconvertedDynamoDBEntry((double)data).Convert(conversion));
            }

            if (data.IsInt)
            {
                return(new UnconvertedDynamoDBEntry((int)data).Convert(conversion));
            }

            if (data.IsUInt)
            {
                return(new UnconvertedDynamoDBEntry((uint)data).Convert(conversion));
            }

            if (data.IsLong)
            {
                return(new UnconvertedDynamoDBEntry((long)data).Convert(conversion));
            }

            if (data.IsULong)
            {
                return(new UnconvertedDynamoDBEntry((ulong)data).Convert(conversion));
            }

            if (data.IsString)
            {
                return(new UnconvertedDynamoDBEntry((string)data).Convert(conversion));
            }

            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                              "Unable to convert JSON data of type {0} to DynamoDB type.", data.GetJsonType()));
        }
Example #28
0
        internal static void ApplyExpression(QueryRequest request, DynamoDBEntryConversion conversion,
            Expression keyExpression, Expression filterExpression)
        {
            if (keyExpression == null)
                keyExpression = new Expression();
            if (filterExpression == null)
                filterExpression = new Expression();

            if (!keyExpression.IsSet && !filterExpression.IsSet)
                return;

            if (keyExpression.IsSet)
                request.KeyConditionExpression = keyExpression.ExpressionStatement;
            if (filterExpression.IsSet)
                request.FilterExpression = filterExpression.ExpressionStatement;

            var kean = keyExpression.ExpressionAttributeNames;
            var fean = filterExpression.ExpressionAttributeNames;
            var combinedEan = Common.Combine(kean, fean, StringComparer.Ordinal);
            request.ExpressionAttributeNames = combinedEan;

            var keav = new Document(keyExpression.ExpressionAttributeValues).ForceConversion(conversion);
            var feav = new Document(filterExpression.ExpressionAttributeValues).ForceConversion(conversion);
            var combinedEav = Common.Combine(keav, feav, null);
            request.ExpressionAttributeValues = ConvertToAttributeValues(combinedEav, conversion);
        }
Example #29
0
 internal void ApplyExpression(QueryRequest request, DynamoDBEntryConversion conversion)
 {
     request.FilterExpression = this.ExpressionStatement;
     request.ExpressionAttributeNames = new Dictionary<string, string>(this.ExpressionAttributeNames);
     request.ExpressionAttributeValues = this.ConvertToAttributeValues(conversion);
 }
Example #30
0
        internal static Dictionary<string, AttributeValue> ConvertToAttributeValues(
            Dictionary<string, DynamoDBEntry> valueMap, DynamoDBEntryConversion conversion)
        {
            var convertedValues = new Dictionary<string, AttributeValue>();
            if (valueMap != null)
            {
                foreach (var kvp in valueMap)
                {
                    if (kvp.Value == null)
                        convertedValues[kvp.Key] = new AttributeValue { NULL = true };
                    else
                        convertedValues[kvp.Key] = kvp.Value.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion));
                }
            }

            return convertedValues;
        }
Example #31
0
        /// <summary>
        /// Creates a Table object with the specified name, using the
        /// passed-in client to load the table definition.
        ///
        /// This method will return false if the table does not exist.
        /// </summary>
        /// <param name="ddbClient">Client to use to access DynamoDB.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
        /// <param name="table">Loaded table.</param>
        /// <returns>
        /// True if table was successfully loaded; otherwise false.
        /// </returns>
        public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, out Table table)
        {
            var config = new TableConfig(tableName, conversion, DynamoDBConsumer.DocumentModel, storeAsEpoch: null);

            return(TryLoadTable(ddbClient, config, out table));
        }
Example #32
0
 internal void ApplyExpression(PutItemRequest request, DynamoDBEntryConversion conversion)
 {
     request.ConditionExpression = this.ExpressionStatement;
     request.ExpressionAttributeNames = new Dictionary<string, string>(this.ExpressionAttributeNames);
     request.ExpressionAttributeValues = ConvertToAttributeValues(this.ExpressionAttributeValues, conversion);
 }
Example #33
0
 /// <summary>
 /// Creates a list of AttributeValues from a list of DynamoDBEntry items 
 /// </summary>
 /// <param name="conversion"></param>
 /// <param name="values"></param>
 /// <returns></returns>
 protected static List<AttributeValue> ConvertToAttributeValues(DynamoDBEntryConversion conversion, params DynamoDBEntry[] values)
 {
     List<AttributeValue> attributes = new List<AttributeValue>();
     foreach (DynamoDBEntry value in values)
     {
         AttributeValue nativeValue = value.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(conversion));
         if (nativeValue != null)
         {
             attributes.Add(nativeValue);
         }
     }
     return attributes;
 }
Example #34
0
        /// <summary>
        /// Perform conversion with the given converter.
        /// </summary>
        /// <param name="conversion"></param>
        /// <returns></returns>
        public DynamoDBEntry Convert(DynamoDBEntryConversion conversion)
        {
            var convertedEntry = conversion.ConvertToEntry(ValueType, Value);

            return(convertedEntry);
        }
Example #35
0
        /// <summary>
        /// Creates a map of attribute names mapped to ExpectedAttributeValue objects.
        /// </summary>
        /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
        /// <returns></returns>
        public Dictionary<string, ExpectedAttributeValue> ToExpectedAttributeMap(DynamoDBEntryConversion conversion)
        {
            Dictionary<string, ExpectedAttributeValue> ret = new Dictionary<string, ExpectedAttributeValue>();

            foreach (var kvp in ExpectedValues)
            {
                string attributeName = kvp.Key;
                ExpectedValue expectedValue = kvp.Value;
                ExpectedAttributeValue eav = expectedValue.ToExpectedAttributeValue(conversion);
                ret[attributeName] = eav;
            }

            return ret;
        }
Example #36
0
 public AttributeConversionConfig(DynamoDBEntryConversion conversion)
 {
     Conversion = conversion;
     CRT        = new CircularReferenceTracking();
 }
Example #37
0
        private Table(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion)
        {
#if PCL || UNITY
            DDBClient = ddbClient as AmazonDynamoDBClient;
#else
            DDBClient = ddbClient;
#endif
            TableInfoCache = SdkCache.GetCache <string, TableDescription>(ddbClient, TableInfoCacheIdentifier, StringComparer.Ordinal);
            LoggerInstance = Logger.GetLogger(typeof(SdkCache));

            TableConsumer = consumer;
            TableName     = tableName;
            Conversion    = conversion;
            ClearTableData();
        }
Example #38
0
        // Returns a DynamoDB entry for the given JSON data
        private static DynamoDBEntry ToEntry(JsonData data, DynamoDBEntryConversion conversion)
        {
            if (data == null)
                return new DynamoDBNull();

            if (data.IsObject)
            {
                var document = new Document();
                foreach (var propertyName in data.PropertyNames)
                {
                    var nestedData = data[propertyName];
                    var entry = ToEntry(nestedData, conversion);
                    document[propertyName] = entry;
                }
                return document;
            }

            if (data.IsArray)
            {
                var list = new DynamoDBList();
                for(int i=0;i<data.Count;i++)
                {
                    var item = data[i];
                    var entry = ToEntry(item, conversion);
                    list.Add(entry);
                }
                return list;
            }

            if (data.IsBoolean)
                return new UnconvertedDynamoDBEntry((bool)data).Convert(conversion);

            if (data.IsDouble)
                return new UnconvertedDynamoDBEntry((double)data).Convert(conversion);

            if (data.IsInt)
                return new UnconvertedDynamoDBEntry((int)data).Convert(conversion);

            if (data.IsLong)
                return new UnconvertedDynamoDBEntry((long)data).Convert(conversion);

            if (data.IsString)
                return new UnconvertedDynamoDBEntry((string)data).Convert(conversion);

            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                "Unable to convert JSON data of type {0} to DynamoDB type.", data.GetJsonType()));
        }
Example #39
0
 internal static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion, out Table table)
 {
     try
     {
         table = LoadTable(ddbClient, tableName, consumer, conversion);
         return(true);
     }
     catch
     {
         table = null;
         return(false);
     }
 }
Example #40
0
        // Writes a JSON representation of the given DynamoDBEntry
        private static void WriteJson(DynamoDBEntry entry, JsonWriter writer, DynamoDBEntryConversion conversion)
        {
            entry = entry.ToConvertedEntry(conversion);

            var document = entry as Document;
            if (document != null)
            {
                writer.WriteObjectStart();

                // Both item attributes and entries in M type are unordered, so sorting by key
                // http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html#DataModel.DataTypes
                foreach (var kvp in document)
                {
                    var name = kvp.Key;
                    var value = kvp.Value;

                    writer.WritePropertyName(name);
                    WriteJson(value, writer, conversion);
                }
                writer.WriteObjectEnd();
                return;
            }

            var primitive = entry as Primitive;
            if (primitive != null)
            {
                var type = primitive.Type;
                var value = primitive.Value;
                WritePrimitive(writer, type, value);
                return;
            }

            var primitiveList = entry as PrimitiveList;
            if (primitiveList != null)
            {
                var itemType = primitiveList.Type;

                writer.WriteArrayStart();
                foreach (var item in primitiveList.Entries)
                {
                    var itemValue = item.Value;
                    WritePrimitive(writer, itemType, itemValue);
                }
                writer.WriteArrayEnd();
                return;
            }

            var ddbList = entry as DynamoDBList;
            if (ddbList != null)
            {
                writer.WriteArrayStart();
                foreach(var item in ddbList.Entries)
                {
                    WriteJson(item, writer, conversion);
                }
                writer.WriteArrayEnd();
                return;
            }

            var ddbBool = entry as DynamoDBBool;
            if (ddbBool != null)
            {
                writer.Write(ddbBool.Value);
                return;
            }

            var ddbNull = entry as DynamoDBNull;
            if (ddbNull != null)
            {
                writer.Write(null);
                return;
            }

            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                "Unable to convert entry of type {0} to JSON", entry.GetType().FullName));
        }
Example #41
0
 internal Dictionary <string, AttributeValue> ToAttributeMap(Document doc, DynamoDBEntryConversion conversion)
 {
     return(doc.ToAttributeMap(conversion, this.StoreAsEpoch));
 }
Example #42
0
        private Table(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion)
        {
#if (WIN_RT || WINDOWS_PHONE)
            DDBClient = ddbClient as AmazonDynamoDBClient;
#else
            DDBClient = ddbClient;
#endif

            TableConsumer = consumer;
            TableName = tableName;
            Keys = new Dictionary<string, KeyDescription>();
            HashKeys = new List<string>();
            RangeKeys = new List<string>();
            LocalSecondaryIndexes = new Dictionary<string, LocalSecondaryIndexDescription>();
            LocalSecondaryIndexNames = new List<string>();
            GlobalSecondaryIndexes = new Dictionary<string, GlobalSecondaryIndexDescription>();
            GlobalSecondaryIndexNames = new List<string>();
            Attributes = new List<AttributeDefinition>();
            Conversion = conversion;
        }
Example #43
0
        private Table(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion)
        {
#if (WIN_RT || WINDOWS_PHONE || AWSSDK_UNITY)
            DDBClient = ddbClient as AmazonDynamoDBClient;
#else
            DDBClient = ddbClient;
#endif
            TableInfoCache = SdkCache.GetCache<string, TableDescription>(ddbClient, TableInfoCacheIdentifier, StringComparer.Ordinal);
            LoggerInstance = Logger.GetLogger(typeof(SdkCache));

            TableConsumer = consumer;
            TableName = tableName;
            Conversion = conversion;
            ClearTableData();
        }
Example #44
0
 /// <summary>
 /// 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.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
 /// <param name="callback">The callback that will be invoked when the asynchronous operation completes.</param>
 /// <param name="asyncOptions">An instance of AsyncOptions that specifies how the async method should be executed.</param>
 public static void LoadTableAsync(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, AmazonDynamoDBCallback<Table> callback, AsyncOptions asyncOptions = null)
 {
     LoadTableAsync(ddbClient,tableName, DynamoDBConsumer.DocumentModel, conversion,callback,asyncOptions);
 }
Example #45
0
        // Writes a JSON representation of the given DynamoDBEntry
        private static void WriteJson(DynamoDBEntry entry, JsonWriter writer, DynamoDBEntryConversion conversion)
        {
            entry = entry.ToConvertedEntry(conversion);

            var document = entry as Document;

            if (document != null)
            {
                writer.WriteObjectStart();

                // Both item attributes and entries in M type are unordered, so sorting by key
                // http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html#DataModel.DataTypes
                foreach (var kvp in document)
                {
                    var name  = kvp.Key;
                    var value = kvp.Value;

                    writer.WritePropertyName(name);
                    WriteJson(value, writer, conversion);
                }
                writer.WriteObjectEnd();
                return;
            }

            var primitive = entry as Primitive;

            if (primitive != null)
            {
                var type  = primitive.Type;
                var value = primitive.Value;
                WritePrimitive(writer, type, value);
                return;
            }

            var primitiveList = entry as PrimitiveList;

            if (primitiveList != null)
            {
                var itemType = primitiveList.Type;

                writer.WriteArrayStart();
                foreach (var item in primitiveList.Entries)
                {
                    var itemValue = item.Value;
                    WritePrimitive(writer, itemType, itemValue);
                }
                writer.WriteArrayEnd();
                return;
            }

            var ddbList = entry as DynamoDBList;

            if (ddbList != null)
            {
                writer.WriteArrayStart();
                foreach (var item in ddbList.Entries)
                {
                    WriteJson(item, writer, conversion);
                }
                writer.WriteArrayEnd();
                return;
            }

            var ddbBool = entry as DynamoDBBool;

            if (ddbBool != null)
            {
                writer.Write(ddbBool.Value);
                return;
            }

            var ddbNull = entry as DynamoDBNull;

            if (ddbNull != null)
            {
                writer.Write(null);
                return;
            }

            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                              "Unable to convert entry of type {0} to JSON", entry.GetType().FullName));
        }
Example #46
0
        private void TestHashTable(Table hashTable, DynamoDBEntryConversion conversion)
        {
            // Put an item
            Document doc = new Document();

            doc["Id"]       = 1;
            doc["Product"]  = "CloudSpotter";
            doc["Company"]  = "CloudsAreGrate";
            doc["IsPublic"] = true;
            doc["Price"]    = 1200;
            doc["Tags"]     = new HashSet <string> {
                "Prod", "1.0"
            };
            doc["Aliases"] = new List <string> {
                "CS", "Magic"
            };
            doc["Developers"] = new List <Document>
            {
                new Document(new Dictionary <string, DynamoDBEntry>
                {
                    { "Name", "Alan" },
                    { "Age", 29 }
                }),
                new Document(new Dictionary <string, DynamoDBEntry>
                {
                    { "Name", "Franco" },
                    { "Age", 32 }
                })
            };
            doc["Garbage"] = "asdf";
            Assert.AreEqual("asdf", doc["Garbage"].AsString());
            hashTable.PutItem(doc);

            // Get the item by hash key
            Document retrieved = hashTable.GetItem(1);

            Assert.IsFalse(AreValuesEqual(doc, retrieved));
            var convertedDoc = doc.ForceConversion(conversion);

            Assert.IsTrue(AreValuesEqual(convertedDoc, retrieved));

            // Get the item by document
            retrieved = hashTable.GetItem(doc);
            // Verify retrieved document
            Assert.IsTrue(AreValuesEqual(convertedDoc, retrieved, conversion));
            var tagsRetrieved = retrieved["Tags"];

            Assert.IsTrue(tagsRetrieved is PrimitiveList);
            Assert.AreEqual(2, tagsRetrieved.AsPrimitiveList().Entries.Count);
            // Test bool storage for different conversions
            var isPublicRetrieved = retrieved["IsPublic"];

            if (conversion == DynamoDBEntryConversion.V1)
            {
                Assert.AreEqual("1", isPublicRetrieved.AsPrimitive().Value as string);
            }
            else
            {
                Assert.IsTrue(isPublicRetrieved is DynamoDBBool);
            }
            // Test HashSet<string> storage for different conversions
            var aliasesRetrieved = retrieved["Aliases"];

            if (conversion == DynamoDBEntryConversion.V1)
            {
                Assert.AreEqual(2, aliasesRetrieved.AsPrimitiveList().Entries.Count);
            }
            else
            {
                Assert.AreEqual(2, aliasesRetrieved.AsDynamoDBList().Entries.Count);
            }
            List <Document> developers = retrieved["Developers"].AsListOfDocument();

            Assert.AreEqual(2, developers.Count);
            AssertExtensions.ExpectException(() => aliasesRetrieved.AsListOfDocument(), typeof(InvalidCastException));

            // Update the item
            doc["Tags"] = new List <string> {
                "Prod", "1.0", "2.0"
            };
            doc["Developers"] = new DynamoDBList(new List <DynamoDBEntry>
            {
                new Document(new Dictionary <string, DynamoDBEntry>
                {
                    { "Name", "Alan" },
                    { "Age", 29 }
                })
            });
            // Delete the Garbage attribute
            doc["Garbage"] = null;
            Assert.IsNull(doc["Garbage"].AsString());
            hashTable.UpdateItem(doc);
            retrieved = hashTable.GetItem(1);
            Assert.IsFalse(AreValuesEqual(doc, retrieved, conversion));
            doc.Remove("Garbage");
            Assert.IsTrue(AreValuesEqual(doc, retrieved, conversion));
            developers = retrieved["Developers"].AsListOfDocument();
            Assert.AreEqual(1, developers.Count);

            // Create new, circularly-referencing item
            Document doc2 = doc.ForceConversion(conversion);

            doc2["Id"]       = doc2["Id"].AsInt() + 1;
            doc2["Price"]    = 94;
            doc2["Tags"]     = null;
            doc2["IsPublic"] = false;
            doc2["Parent"]   = doc2;
            AssertExtensions.ExpectException(() => hashTable.UpdateItem(doc2));
            // Remove circular reference and save new item
            doc2.Remove("Parent");
            hashTable.UpdateItem(doc2);

            // Scan the hash-key table
            var items = hashTable.Scan(new ScanFilter()).GetRemaining();

            Assert.AreEqual(2, items.Count);

            // Scan by pages
            var search = hashTable.Scan(new ScanOperationConfig {
                Limit = 1
            });

            items.Clear();
            while (!search.IsDone)
            {
                var set = search.GetNextSet();
                items.AddRange(set);
            }
            Assert.AreEqual(2, items.Count);

            // Query against GlobalIndex
            var queryFilter = new QueryFilter("Company", QueryOperator.Equal, "CloudsAreGrate");

            queryFilter.AddCondition("Price", QueryOperator.GreaterThan, 100);
            search = hashTable.Query(new QueryOperationConfig
            {
                IndexName = "GlobalIndex",
                Filter    = queryFilter
            });
            items = search.GetRemaining();
            Assert.AreEqual(1, items.Count);

            // Scan for specific tag
            var scanFilter = new ScanFilter();

            scanFilter.AddCondition("Tags", ScanOperator.Contains, "2.0");
            search = hashTable.Scan(scanFilter);
            items  = search.GetRemaining();
            Assert.AreEqual(1, items.Count);

            // Delete the item by hash key
            hashTable.DeleteItem(1);
            Assert.IsNull(hashTable.GetItem(1));

            // Delete the item by document
            hashTable.DeleteItem(doc2);
            Assert.IsNull(hashTable.GetItem(doc2));

            // Scan the hash-key table to confirm it is empty
            items = hashTable.Scan(new ScanFilter()).GetRemaining();
            Assert.AreEqual(0, items.Count);

            // Batch-put items
            var batchWrite = hashTable.CreateBatchWrite();

            batchWrite.AddDocumentToPut(doc);
            batchWrite.AddDocumentToPut(doc2);
            batchWrite.Execute();

            // Batch-get items
            var batchGet = hashTable.CreateBatchGet();

            batchGet.AddKey(1);
            batchGet.AddKey(doc2);
            batchGet.Execute();
            Assert.AreEqual(2, batchGet.Results.Count);

            // Batch-delete items
            batchWrite = hashTable.CreateBatchWrite();
            batchWrite.AddItemToDelete(doc);
            batchWrite.AddKeyToDelete(2);
            batchWrite.Execute();

            // Batch-get non-existent items
            batchGet = hashTable.CreateBatchGet();
            batchGet.AddKey(1);
            batchGet.AddKey(doc2);
            batchGet.Execute();
            Assert.AreEqual(0, batchGet.Results.Count);

            // Scan the hash-key table to confirm it is empty
            items = hashTable.Scan(new ScanFilter()).GetRemaining();
            Assert.AreEqual(0, items.Count);
        }
Example #47
0
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 /// 
 /// This method will return false if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
 /// <param name="table">Loaded table.</param>
 /// <returns>
 /// True if table was successfully loaded; otherwise false.
 /// </returns>
 public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, out Table table)
 {
     try
     {
         table = LoadTable(ddbClient, tableName, conversion);
         return true;
     }
     catch
     {
         table = null;
         return false;
     }
 }
Example #48
-1
 internal static Table LoadTable(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion)
 {
     Table table = new Table(ddbClient, tableName, consumer, conversion);
     table.LoadTableInfo();
     return table;
 }
Example #49
-1
 /// <summary>
 /// Creates a Table object with the specified name, using the
 /// passed-in client to load the table definition.
 /// 
 /// This method will throw an exception if the table does not exist.
 /// </summary>
 /// <param name="ddbClient">Client to use to access DynamoDB.</param>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="conversion">Conversion to use for converting .NET values to DynamoDB values.</param>
 /// <returns>Table object representing the specified table.</returns>
 public static Table LoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion)
 {
     return LoadTable(ddbClient, tableName, DynamoDBConsumer.DocumentModel, conversion);
 }