public async Task <SampleTableEntry> SaveAsync(SampleTableEntry sampleTableEntry) { var context = new Amazon.DynamoDBv2.DataModel.DynamoDBContext(_dynamoDbClient); await context.SaveAsync(new SampleTable { PartitionKey = sampleTableEntry.PartitionKey, SortKey = sampleTableEntry.SortKey }); return(sampleTableEntry); }
public void Denormalize(DynamoDBContext context) { // analyze all PropertyStorage configs and denormalize data into other properties // all data must exist in PropertyStorage objects prior to denormalization foreach (var property in Properties) { // only add non-ignored properties if (property.IsIgnored) { continue; } property.Validate(context); AddPropertyStorage(property); string propertyName = property.PropertyName; foreach (var index in property.Indexes) { var gsi = index as PropertyStorage.GSI; if (gsi != null) { AddGSIConfigs(gsi.IndexNames, propertyName, gsi.IsHashKey); } var lsi = index as PropertyStorage.LSI; if (lsi != null) { AddLSIConfigs(lsi.IndexNames, propertyName); } } } if (this.HashKeyPropertyNames.Count == 0) { throw new InvalidOperationException("No hash key configured for type " + TargetTypeInfo.FullName); } }
/// <summary> /// Validates configurations and sets required fields /// </summary> public void Validate(DynamoDBContext context) { if (IsVersion) { Utils.ValidateVersionType(MemberType); // no conversion is possible, so type must be a nullable primitive } if (IsHashKey && IsRangeKey) { throw new InvalidOperationException("Property " + PropertyName + " cannot be both hash and range key"); } if (ConverterType != null) { if (StoreAsEpoch) { throw new InvalidOperationException("Converter for " + PropertyName + " must not be set at the same time as StoreAsEpoch is set to true"); } if (!Utils.CanInstantiateConverter(ConverterType) || !Utils.ImplementsInterface(ConverterType, typeof(IPropertyConverter))) { throw new InvalidOperationException("Converter for " + PropertyName + " must be instantiable with no parameters and must implement IPropertyConverter"); } this.Converter = Utils.InstantiateConverter(ConverterType, context) as IPropertyConverter; } IPropertyConverter converter; if (context.ConverterCache.TryGetValue(MemberType, out converter) && converter != null) { this.Converter = converter; } foreach (var index in Indexes) { IndexNames.AddRange(index.IndexNames); } }
public ItemStorageConfig GetConfig(Type type, DynamoDBFlatConfig flatConfig) { lock (Cache) { ConfigTableCache tableCache; if (!Cache.TryGetValue(type, out tableCache)) { var baseStorageConfig = CreateStorageConfig(type, null); tableCache = new ConfigTableCache(baseStorageConfig); Cache[type] = tableCache; } string actualTableName = DynamoDBContext.GetTableName(tableCache.BaseTableName, flatConfig); ItemStorageConfig config; if (!tableCache.Cache.TryGetValue(actualTableName, out config)) { config = CreateStorageConfig(type, actualTableName); tableCache.Cache[actualTableName] = config; } return(config); } }
internal BatchGet(DynamoDBContext context, DynamoDBFlatConfig config) { Context = context; Config = config; Keys = new List <Key>(); }
public S3LinkConverter(DynamoDBContext context) { this.context = context; }
internal BatchWrite(DynamoDBContext context, DynamoDBFlatConfig config) { Context = context; Config = config; }
internal AsyncSearch(DynamoDBContext source, DynamoDBContext.ContextSearch contextSearch) { SourceContext = source; DocumentSearch = contextSearch.Search; Config = contextSearch.FlatConfig; }
public ItemStorageConfigCache(DynamoDBContext context) { Cache = new Dictionary <Type, ConfigTableCache>(); Context = context; }
public ItemStorageConfig GetConfig(Type type, DynamoDBFlatConfig flatConfig, bool conversionOnly = false) { ConfigTableCache tableCache = null; ItemStorageConfig config; string actualTableName = null; try { _readerWriterLockSlim.EnterReadLock(); Cache.TryGetValue(type, out tableCache); if (tableCache != null) { // If this type is only used for conversion, do not attempt to populate the config from the table if (conversionOnly) { return(tableCache.BaseTypeConfig); } actualTableName = DynamoDBContext.GetTableName(tableCache.BaseTableName, flatConfig); if (tableCache.Cache.TryGetValue(actualTableName, out config)) { return(config); } } } finally { if (_readerWriterLockSlim.IsReadLockHeld) { _readerWriterLockSlim.ExitReadLock(); } } try { _readerWriterLockSlim.EnterWriteLock(); if (tableCache == null) { // Check to see if another thread go the write lock before this thread and filled the cache. Cache.TryGetValue(type, out tableCache); if (tableCache == null) { var baseStorageConfig = CreateStorageConfig(type, actualTableName: null); tableCache = new ConfigTableCache(baseStorageConfig); Cache[type] = tableCache; } } // If this type is only used for conversion, do not attempt to populate the config from the table if (conversionOnly) { return(tableCache.BaseTypeConfig); } if (actualTableName == null) { actualTableName = DynamoDBContext.GetTableName(tableCache.BaseTableName, flatConfig); } // Check to see if another thread go the write lock before this thread and filled the cache. if (tableCache.Cache.TryGetValue(actualTableName, out config)) { return(config); } config = CreateStorageConfig(type, actualTableName); tableCache.Cache[actualTableName] = config; return(config); } finally { if (_readerWriterLockSlim.IsWriteLockHeld) { _readerWriterLockSlim.ExitWriteLock(); } } }
internal AsyncSearch(DynamoDBContext source, Search documentSearch) { SourceContext = source; DocumentSearch = documentSearch; }