private ItemStorage ObjectToItemStorage(object toStore, Type objectType, bool keysOnly, DynamoDBFlatConfig flatConfig) { ItemStorageConfig config = StorageConfigCache.GetConfig(objectType, flatConfig); ItemStorage storage = ObjectToItemStorageHelper(toStore, config, flatConfig, keysOnly, flatConfig.IgnoreNullValues.Value); return(storage); }
private IEnumerable <T> FromSearch <T>(ContextSearch cs) { if (cs == null) { throw new ArgumentNullException("cs"); } // Configure search to not collect results cs.Search.CollectResults = false; ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(cs.FlatConfig); while (!cs.Search.IsDone) { List <Document> set = cs.Search.GetNextSetHelper(false); foreach (var document in set) { ItemStorage storage = new ItemStorage(storageConfig); storage.Document = document; T instance = DocumentToObject <T>(storage, cs.FlatConfig); yield return(instance); } } // Reset search to allow retrieving items more than once cs.Search.Reset(); }
// Serializes a given value to Document // Use only for property conversions, not for full item conversion private Document SerializeToDocument(object value, Type type, DynamoDBFlatConfig flatConfig) { ItemStorageConfig config = StorageConfigCache.GetConfig(type, flatConfig, conversionOnly: true); var itemStorage = ObjectToItemStorageHelper(value, config, flatConfig, keysOnly: false, ignoreNullValues: flatConfig.IgnoreNullValues.Value); var doc = itemStorage.Document; return(doc); }
private Task <T> LoadHelperAsync <T>(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(flatConfig); Key key = MakeKey <T>(keyObject, storageConfig, flatConfig); return(LoadHelperAsync <T>(key, flatConfig, storageConfig, cancellationToken)); }
private T LoadHelper <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(flatConfig); Key key = MakeKey(hashKey, rangeKey, storageConfig, flatConfig); return(LoadHelper <T>(key, flatConfig, storageConfig)); }
private T LoadHelper <T>(T keyObject, DynamoDBOperationConfig operationConfig, bool isAsync) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(flatConfig); Key key = MakeKey <T>(keyObject, storageConfig, flatConfig); return(LoadHelper <T>(key, flatConfig, storageConfig, isAsync)); }
private ContextSearch ConvertQueryByValue <T>(object hashKeyValue, QueryOperator op, IEnumerable <object> values, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(flatConfig); List <QueryCondition> conditions = CreateQueryConditions(flatConfig, op, values, storageConfig); ContextSearch query = ConvertQueryByValue <T>(hashKeyValue, conditions, operationConfig, storageConfig); return(query); }
internal Table GetTargetTableInternal <T>(DynamoDBOperationConfig operationConfig) { Type type = typeof(T); DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(type, flatConfig); Table table = GetTargetTable(storageConfig, flatConfig); return(table); }
internal Table GetTargetTableInternal <T>(DynamoDBOperationConfig operationConfig) { Type type = typeof(T); DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(type, flatConfig); Table table = GetTargetTable(storageConfig, flatConfig); //Table copy = table.Copy(Table.DynamoDBConsumer.DocumentModel); return(table); }
private Task DeleteHelperAsync <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(config); Key key = MakeKey(hashKey, rangeKey, storageConfig, config); Table table = GetTargetTable(storageConfig, config); return(table.DeleteHelperAsync(key, null, cancellationToken)); }
private void DeleteHelper <T>(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, bool isAsync) { DynamoDBFlatConfig config = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(config); Key key = MakeKey(hashKey, rangeKey, storageConfig, config); Table table = GetTargetTable(storageConfig, config); table.DeleteHelper(key, null, isAsync); }
internal T FromDocumentHelper <T>(Document document, DynamoDBFlatConfig flatConfig) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(flatConfig); ItemStorage storage = new ItemStorage(storageConfig); storage.Document = document; T instance = DocumentToObject <T>(storage, flatConfig); return(instance); }
// Deserializes a given Document to instance of targetType // Use only for property conversions, not for full item conversion private object DeserializeFromDocument(Document document, Type targetType, DynamoDBFlatConfig flatConfig) { ItemStorageConfig storageConfig = StorageConfigCache.GetConfig(targetType, flatConfig, conversionOnly: true); ItemStorage storage = new ItemStorage(storageConfig); storage.Document = document; object value = DocumentToObject(targetType, storage, flatConfig); return(value); }
private ContextSearch ConvertQueryByValue <T>(object hashKeyValue, IEnumerable <QueryCondition> conditions, DynamoDBOperationConfig operationConfig, ItemStorageConfig storageConfig = null) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, Config); if (storageConfig == null) { storageConfig = StorageConfigCache.GetConfig <T>(flatConfig); } List <string> indexNames; QueryFilter filter = ComposeQueryFilter(flatConfig, hashKeyValue, conditions, storageConfig, out indexNames); return(ConvertQueryHelper <T>(flatConfig, storageConfig, filter, indexNames)); }
/// <summary> /// Implements the Dispose pattern /// </summary> /// <param name="disposing">Whether this object is being disposed via a call to Dispose /// or garbage collected.</param> protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing && Client != null) { if (ownClient) { StorageConfigCache.Dispose(); Client.Dispose(); } Client = null; } this.disposed = true; } }
private ContextSearch ConvertScan <T>(IEnumerable <ScanCondition> conditions, DynamoDBOperationConfig operationConfig) { DynamoDBFlatConfig flatConfig = new DynamoDBFlatConfig(operationConfig, this.Config); ItemStorageConfig storageConfig = StorageConfigCache.GetConfig <T>(flatConfig); ScanFilter filter = ComposeScanFilter(conditions, storageConfig, flatConfig); Table table = GetTargetTable(storageConfig, flatConfig); var scanConfig = new ScanOperationConfig { AttributesToGet = storageConfig.AttributesToGet, Select = SelectValues.SpecificAttributes, Filter = filter, ConditionalOperator = flatConfig.ConditionalOperator }; Search scan = table.Scan(scanConfig); return(new ContextSearch(scan, flatConfig)); }
// Serializing an object into a DynamoDB document private ItemStorage ObjectToItemStorage <T>(T toStore, bool keysOnly, DynamoDBFlatConfig flatConfig) { if (toStore == null) { return(null); } Type objectType = typeof(T); ItemStorageConfig config = StorageConfigCache.GetConfig(objectType, flatConfig); if (config == null) { return(null); } ItemStorage storage = ObjectToItemStorage <T>(toStore, keysOnly, flatConfig.IgnoreNullValues.Value, config); return(storage); }