예제 #1
0
        internal static Key MakeKey(object hashKeyValue, object rangeKeyValue, ItemStorageConfig storageConfig)
        {
            if (hashKeyValue == null)
            {
                throw new ArgumentNullException("hashKeyValue");
            }
            if (storageConfig.HasRangeKey && rangeKeyValue == null)
            {
                throw new ArgumentNullException("rangeKeyValue");
            }

            Key key = new Key();

            DynamoDBEntry hashKeyEntry = ValueToDynamoDBEntry(storageConfig.HashKeyPropertyName, hashKeyValue, storageConfig);

            if (hashKeyEntry == null)
            {
                throw new InvalidOperationException("Unable to convert hash key value for property " + storageConfig.HashKeyPropertyName);
            }
            key.HashKeyElement = hashKeyEntry.ConvertToAttributeValue();

            if (storageConfig.HasRangeKey)
            {
                DynamoDBEntry rangeKeyEntry = ValueToDynamoDBEntry(storageConfig.RangeKeyPropertyName, rangeKeyValue, storageConfig);
                if (rangeKeyEntry == null)
                {
                    throw new InvalidOperationException("Unable to convert range key value for property " + storageConfig.RangeKeyPropertyName);
                }
                key.RangeKeyElement = rangeKeyEntry.ConvertToAttributeValue();
            }

            return(key);
        }
예제 #2
0
        private List <AttributeValue> ConvertConditionValues(object[] conditionValues, PropertyStorage conditionProperty, DynamoDBFlatConfig flatConfig, bool canReturnScalarInsteadOfList = false)
        {
            List <AttributeValue> attributeValues = new List <AttributeValue>();

            foreach (var conditionValue in conditionValues)
            {
                DynamoDBEntry  entry          = ToDynamoDBEntry(conditionProperty, conditionValue, flatConfig, canReturnScalarInsteadOfList);
                AttributeValue attributeValue = entry.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(flatConfig.Conversion));
                attributeValues.Add(attributeValue);
            }
            return(attributeValues);
        }
예제 #3
0
        private static List <AttributeValue> ConvertConditionValues(object[] conditionValues, PropertyStorage conditionProperty, bool canReturnPrimitiveInsteadOfList = false)
        {
            List <AttributeValue> attributeValues = new List <AttributeValue>();

            foreach (var conditionValue in conditionValues)
            {
                DynamoDBEntry  entry          = ToDynamoDBEntry(conditionProperty, conditionValue, canReturnPrimitiveInsteadOfList);
                AttributeValue attributeValue = entry.ConvertToAttributeValue();
                attributeValues.Add(attributeValue);
            }
            return(attributeValues);
        }
예제 #4
0
        private static QueryFilter ComposeQueryFilterHelper(Document hashKey, IEnumerable <QueryCondition> conditions, ItemStorageConfig storageConfig, DynamoDBFlatConfig currentConfig, out List <string> indexNames)
        {
            if (hashKey == null)
            {
                throw new ArgumentNullException("hashKey");
            }

            if (storageConfig.HashKeyPropertyNames.Count != 1)
            {
                throw new InvalidOperationException("Must have one hash key defined for the table " + storageConfig.TableName);
            }
            if (storageConfig.RangeKeyPropertyNames.Count != 1 && storageConfig.IndexNameToGSIMapping.Count == 0)
            {
                throw new InvalidOperationException("Must have one range key or a GSI index defined for the table " + storageConfig.TableName);
            }

            QueryFilter filter = new QueryFilter();

            // Configure hash-key equality condition
            string hashKeyProperty = storageConfig.HashKeyPropertyNames[0];

            hashKeyProperty = storageConfig.GetCorrectHashKeyProperty(currentConfig, hashKeyProperty);
            PropertyStorage propertyStorage = storageConfig.GetPropertyStorage(hashKeyProperty);
            string          attributeName   = propertyStorage.AttributeName;
            DynamoDBEntry   hashValue       = hashKey[attributeName];

            filter.AddCondition(attributeName, QueryOperator.Equal, hashValue);

            indexNames = new List <string>();
            if (conditions != null)
            {
                foreach (QueryCondition condition in conditions)
                {
                    object[]        conditionValues   = condition.Values;
                    PropertyStorage conditionProperty = storageConfig.GetPropertyStorage(condition.PropertyName);
                    if (conditionProperty.IsLSIRangeKey || conditionProperty.IsGSIKey)
                    {
                        indexNames.AddRange(conditionProperty.Indexes);
                    }
                    List <AttributeValue> attributeValues = new List <AttributeValue>();
                    foreach (var conditionValue in conditionValues)
                    {
                        DynamoDBEntry  entry          = ToDynamoDBEntry(conditionProperty, conditionValue);
                        AttributeValue attributeValue = entry.ConvertToAttributeValue();
                        attributeValues.Add(attributeValue);
                    }
                    filter.AddCondition(conditionProperty.AttributeName, condition.Operator, attributeValues);
                }
            }
            return(filter);
        }
예제 #5
0
        internal Key MakeKey(object hashKey, object rangeKey, ItemStorageConfig storageConfig, DynamoDBFlatConfig flatConfig)
        {
            if (storageConfig.HashKeyPropertyNames.Count != 1)
            {
                throw new InvalidOperationException("Must have one hash key defined for the table " + storageConfig.TableName);
            }

            Key key = new Key();

            string          hashKeyPropertyName = storageConfig.HashKeyPropertyNames[0];
            PropertyStorage hashKeyProperty     = storageConfig.GetPropertyStorage(hashKeyPropertyName);

            DynamoDBEntry hashKeyEntry = ValueToDynamoDBEntry(hashKeyProperty, hashKey, flatConfig);

            if (hashKeyEntry == null)
            {
                throw new InvalidOperationException("Unable to convert hash key value for property " + hashKeyPropertyName);
            }
            key[hashKeyProperty.AttributeName] = hashKeyEntry.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(flatConfig.Conversion));

            if (storageConfig.RangeKeyPropertyNames.Count > 0)
            {
                if (storageConfig.RangeKeyPropertyNames.Count != 1)
                {
                    throw new InvalidOperationException("Must have one range key defined for the table");
                }

                string          rangeKeyPropertyName = storageConfig.RangeKeyPropertyNames[0];
                PropertyStorage rangeKeyProperty     = storageConfig.GetPropertyStorage(rangeKeyPropertyName);

                DynamoDBEntry rangeKeyEntry = ValueToDynamoDBEntry(rangeKeyProperty, rangeKey, flatConfig);
                if (rangeKeyEntry == null)
                {
                    throw new InvalidOperationException("Unable to convert range key value for property " + rangeKeyPropertyName);
                }
                key[rangeKeyProperty.AttributeName] = rangeKeyEntry.ConvertToAttributeValue(new DynamoDBEntry.AttributeConversionConfig(flatConfig.Conversion));
            }

            ValidateKey(key, storageConfig);
            return(key);
        }