Beispiel #1
0
        private T LoadHelper <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, bool isAsync)
        {
            ItemStorageConfig storageConfig = ItemStorageConfigCache.GetConfig <T>();
            Key key = MakeKey(hashKey, rangeKey, storageConfig);

            return(LoadHelper <T>(key, operationConfig, storageConfig, isAsync));
        }
Beispiel #2
0
        private T LoadHelper <T>(T keyObject, DynamoDBOperationConfig operationConfig, bool isAsync)
        {
            ItemStorageConfig storageConfig = ItemStorageConfigCache.GetConfig <T>();
            Key key = MakeKey <T>(keyObject, storageConfig);

            return(LoadHelper <T>(key, operationConfig, storageConfig, isAsync));
        }
        // Searching
        private IEnumerable <T> FromSearch <T>(Search search)
        {
            if (search == null)
            {
                throw new ArgumentNullException("search");
            }

            // Configure search to not collect results
            search.CollectResults = false;

            ItemStorageConfig storageConfig = ItemStorageConfigCache.GetConfig <T>();

            while (!search.IsDone)
            {
                List <Document> set = search.GetNextSetHelper(false);
                foreach (var document in set)
                {
                    ItemStorage storage = new ItemStorage(storageConfig);
                    storage.Document = document;
                    T instance = DocumentToObject <T>(storage);
                    yield return(instance);
                }
            }

            // Reset search to allow retrieving items more than once
            search.Reset();
        }
        private Search ConvertQueryByValue <T>(object hashKeyValue, QueryOperator op, IEnumerable <object> values, DynamoDBOperationConfig operationConfig)
        {
            ItemStorageConfig     storageConfig = ItemStorageConfigCache.GetConfig <T>();
            List <QueryCondition> conditions    = CreateQueryConditions(operationConfig, op, values, storageConfig);
            Search query = ConvertQueryByValue <T>(hashKeyValue, conditions, operationConfig, storageConfig);

            return(query);
        }
        /// <summary>
        /// Retrieves the target table for the specified type
        /// </summary>
        /// <typeparam name="T">Type to retrieve table for</typeparam>
        /// <returns>Table object</returns>
        public Table GetTargetTable <T>(DynamoDBOperationConfig operationConfig = null)
        {
            Type type = typeof(T);
            ItemStorageConfig storageConfig = ItemStorageConfigCache.GetConfig(type);
            Table             table         = GetTargetTable(storageConfig, new DynamoDBFlatConfig(operationConfig, this.config));
            Table             copy          = table.Copy(Table.DynamoDBConsumer.DocumentModel);

            return(table);
        }
Beispiel #6
0
        private void DeleteHelper <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, bool isAsync)
        {
            DynamoDBFlatConfig config        = new DynamoDBFlatConfig(operationConfig, this.config);
            ItemStorageConfig  storageConfig = ItemStorageConfigCache.GetConfig <T>();
            Key key = MakeKey(hashKey, rangeKey, storageConfig);

            Table table = GetTargetTable(storageConfig, config);

            table.DeleteHelper(key, null, isAsync);
        }
Beispiel #7
0
        /// <summary>
        /// Deserializes a document to an instance of type T.
        /// </summary>
        /// <typeparam name="T">Type to populate.</typeparam>
        /// <param name="document">Document with properties to use.</param>
        /// <returns>
        /// Object of type T, populated with properties from the document.
        /// </returns>
        public T FromDocument <T>(Document document)
        {
            ItemStorageConfig storageConfig = ItemStorageConfigCache.GetConfig <T>();
            ItemStorage       storage       = new ItemStorage(storageConfig);

            storage.Document = document;
            T instance = DocumentToObject <T>(storage);

            return(instance);
        }
        private Search ConvertQueryByValue <T>(object hashKeyValue, IEnumerable <QueryCondition> conditions, DynamoDBOperationConfig operationConfig, ItemStorageConfig storageConfig = null)
        {
            if (storageConfig == null)
            {
                storageConfig = ItemStorageConfigCache.GetConfig <T>();
            }

            List <string>      indexNames;
            DynamoDBFlatConfig currentConfig = new DynamoDBFlatConfig(operationConfig, this.config);
            QueryFilter        filter        = ComposeQueryFilter(currentConfig, hashKeyValue, conditions, storageConfig, out indexNames);

            return(ConvertQueryHelper <T>(currentConfig, storageConfig, filter, indexNames));
        }
Beispiel #9
0
        private DynamoDBContext(IAmazonDynamoDB client, bool ownClient, DynamoDBContextConfig config)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            this.client             = client;
            this.tablesMap          = new Dictionary <string, Table>();
            this.ownClient          = ownClient;
            this.Config             = config ?? new DynamoDBContextConfig();
            this.StorageConfigCache = new ItemStorageConfigCache(this);
        }
        private Search ConvertScan <T>(IEnumerable <ScanCondition> conditions, DynamoDBOperationConfig operationConfig)
        {
            ItemStorageConfig storageConfig = ItemStorageConfigCache.GetConfig <T>();
            ScanFilter        filter        = ComposeScanFilter(conditions, storageConfig);

            DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.config);
            Table table = GetTargetTable(storageConfig, config);
            ScanOperationConfig scanConfig = new ScanOperationConfig
            {
                AttributesToGet = storageConfig.AttributesToGet,
                Select          = SelectValues.SpecificAttributes,
                Filter          = filter
            };
            Search scan = table.Scan(scanConfig);

            return(scan);
        }
        // Serializing an object into a DynamoDB document
        private static ItemStorage ObjectToItemStorage <T>(T toStore, bool keysOnly, bool ignoreNullValues)
        {
            if (toStore == null)
            {
                return(null);
            }

            Type objectType          = typeof(T);
            ItemStorageConfig config = ItemStorageConfigCache.GetConfig(objectType);

            if (config == null)
            {
                return(null);
            }

            ItemStorage storage = ObjectToItemStorage <T>(toStore, keysOnly, ignoreNullValues, config);

            return(storage);
        }
Beispiel #12
0
        // Searching
        private IEnumerable <T> FromSearch <T>(Search search)
        {
            if (search == null)
            {
                throw new ArgumentNullException("search");
            }

            ItemStorageConfig storageConfig = ItemStorageConfigCache.GetConfig <T>();

            while (!search.IsDone)
            {
                List <Document> set = search.GetNextSet();
                foreach (var document in set)
                {
                    ItemStorage storage = new ItemStorage(storageConfig);
                    storage.Document = document;
                    T instance = DocumentToObject <T>(storage);
                    yield return(instance);
                }
            }
        }