private void generateIdentityMapAndTrackingCode(GeneratedMethod sync, GeneratedMethod @async, StorageStyle storageStyle) { if (storageStyle == StorageStyle.QueryOnly) { return; } sync.Frames.MarkAsLoaded(); async.Frames.MarkAsLoaded(); if (storageStyle == StorageStyle.Lightweight) { return; } sync.Frames.StoreInIdentityMap(_mapping); async.Frames.StoreInIdentityMap(_mapping); if (storageStyle == StorageStyle.DirtyTracking) { sync.Frames.StoreTracker(); async.Frames.StoreTracker(); } }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { sync.Frames.DeserializeDocument(mapping, index); async.Frames.DeserializeDocumentAsync(mapping, index); }
public void select_columns_with_hierarchy(StorageStyle style, string[] expected) { theMapping.SubClasses.AddHierarchy(); theTable.SelectColumns(style) .Select(x => x.Name) .ShouldHaveTheSameElementsAs(expected); }
public void basic_select_columns_with_optimistic_versioning(StorageStyle style, string[] expected) { theMapping.UseOptimisticConcurrency = true; theTable.SelectColumns(style) .Select(x => x.Name) .ShouldHaveTheSameElementsAs(expected); }
public bool ShouldSelect(DocumentMapping mapping, StorageStyle storageStyle) { if (Member != null) { return(true); } return(storageStyle != StorageStyle.QueryOnly && mapping.UseOptimisticConcurrency); }
public DocumentStorageBuilder(DocumentMapping mapping, StorageStyle style, Func <DocumentOperations, GeneratedType> selectorTypeSource) { _mapping = mapping; _selectorTypeSource = selectorTypeSource; _typeName = $"{style}{mapping.DocumentType.NameInCode()}DocumentStorage"; _baseType = determineOpenDocumentStorageType(style).MakeGenericType(mapping.DocumentType, mapping.IdType); }
public bool ShouldSelect(DocumentMapping mapping, StorageStyle storageStyle) { if (Member != null) { return(true); } return(storageStyle != StorageStyle.QueryOnly); }
public ICacheImplementation Select(TimeSpan durationToCacheItemFor, StorageStyle cacheStorageStyle, ExpirationType expirationType) { Ensure.That(durationToCacheItemFor.IsGreaterThanZero(), "durationToCacheItemFor"); return _selectorDelegate(durationToCacheItemFor, cacheStorageStyle, expirationType, _implementations); }
/// <summary> /// Made public to make API more intuitive, even though it opens up /// two routes to do the same thing (this plus the "ICacheKeyCreator.Create" /// method. /// </summary> public Key(TimeSpan durationToStore, StorageStyle cacheStorageStyle, ExpirationType cacheExpirationType, string friendlyName) { Ensure.That(durationToStore.IsGreaterThan(TimeSpan.Zero), "durationToStore must be greater than zero") .And(friendlyName.IsNotNullOrWhiteSpace(), "friendlyName not supplied") .And(friendlyName.Length.IsLessThan(MaxFriendlyNameLength), "friendlyName too long"); DurationToStore = durationToStore; StorageStyle = cacheStorageStyle; CacheExpirationType = cacheExpirationType; FriendlyName = friendlyName; }
/// <summary> /// This is the method to be supplied to the constructor of /// the base type as the delegate to use for cache selection. /// Selects a cache based on the heuristic of duration to /// store for, followed by the availability of the requested /// caching functionality. This logic serves as a workable /// example, rather than a recommended strategy. For example, /// the fallback case is handled without error or warning. /// Public rather than protected for testing purposes. /// </summary> /// <remarks> /// NOTE: BA; should we throw an exception if the user requests /// a storage strategy that cannot be fulfilled due to /// limitations of the underlying cache? /// NOTE: BA; Potentially have a flag to indicate strictness of /// choice of cache - i.e. does the cache really need to /// support all the desired features, or can we substitute /// them? /// "narrow down choice of caches to those that can be used, /// then choose the enabled one according to priority". /// </remarks> /// <param name = "implementations">Ordered by preference of use /// with highest pref first.</param> public static ICacheImplementation SelectCacheImplementation(TimeSpan durationToCacheItemFor, StorageStyle cacheStorageStyle, ExpirationType cacheExpirationType, Dictionary<string, ICacheImplementation> implementations) { Ensure.That<FriendlyExceptions.ArgumentOutOfRangeException>(durationToCacheItemFor.IsGreaterThanZero(), "durationToCacheFor") .And<FriendlyExceptions.ArgumentNullException>(implementations.IsNotNull(), "implementations") .And<FriendlyExceptions.ArgumentException>(implementations.Count.Is(2), "implementations") .And<MissingCacheImplementationArgumentException>( implementations.ContainsKey(MemcachedImplementationTypeName), "memcached missing") .And<MissingCacheImplementationArgumentException>( implementations.ContainsKey(AspDotNetImplementationTypeName), "asp.net data cache missing"); ICacheImplementation cacheToUse = null; //simply tries to select memcached if an extended caching period is requested //otherwise attempts to fallback to ASP.NET data cache. This might occur because //the caching expiration type is not supported by memcached. if (durationToCacheItemFor >= LongTermBoundary) { if (implementations[MemcachedImplementationTypeName].Supports((cacheExpirationType)) && implementations[MemcachedImplementationTypeName].IsEnabled) cacheToUse = implementations[MemcachedImplementationTypeName]; if (cacheToUse == null && implementations[AspDotNetImplementationTypeName].Supports((cacheExpirationType)) && implementations[AspDotNetImplementationTypeName].IsEnabled) cacheToUse = implementations[AspDotNetImplementationTypeName]; Ensure.That(cacheToUse.IsNotNull(), () => { throw new CacheSelectionException(implementations); }); } else { if (implementations[AspDotNetImplementationTypeName].Supports((cacheExpirationType)) && implementations[AspDotNetImplementationTypeName].IsEnabled) cacheToUse = implementations[AspDotNetImplementationTypeName]; if (cacheToUse == null && implementations[MemcachedImplementationTypeName].Supports((cacheExpirationType)) && implementations[MemcachedImplementationTypeName].IsEnabled) cacheToUse = implementations[MemcachedImplementationTypeName]; Ensure.That(cacheToUse.IsNotNull(), () => { throw new CacheSelectionException(implementations); }); } return cacheToUse; }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { var variableName = "tenantId"; var memberType = typeof(string); if (Member == null) { return; } sync.Frames.Code($"var {variableName} = reader.GetFieldValue<{memberType.FullNameInCode()}>({index});"); async.Frames.CodeAsync($"var {variableName} = await reader.GetFieldValueAsync<{memberType.FullNameInCode()}>({index}, token);"); sync.Frames.SetMemberValue(Member, variableName, mapping.DocumentType, generatedType); async.Frames.SetMemberValue(Member, variableName, mapping.DocumentType, generatedType); }
public CacheAspect(Type cacheType, Type keyCreationStrategyType, int durationToStoreInSeconds, StorageStyle storageStyle, ExpirationType expirationType) { Ensure.That<ArgumentNullException>(cacheType.IsNotNull(), "cacheType") .And<ArgumentNullException>(keyCreationStrategyType.IsNotNull(), "keyCreationStrategyType") .And<ArgumentException>(durationToStoreInSeconds.IsBetween(0, OneYearInSeconds), "durationToStoreInSeconds"); _cacheType = cacheType; _keyCreationStrategyType = keyCreationStrategyType; _durationToStore = TimeSpan.FromSeconds(durationToStoreInSeconds); _storageStyle = storageStyle; _expirationType = expirationType; }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { var variableName = "correlationId"; var memberType = typeof(string); if (Member == null) { return; } generateIfValueIsNotNull(async, sync, index); generateCodeToSetValuesOnDocumentFromReader(generatedType, async, sync, index, mapping, variableName, memberType, Member); generateCloseScope(async, sync); }
public DocumentStorage(StorageStyle storageStyle, DocumentMapping document) { _mapping = document; Fields = document; TableName = document.TableName; determineDefaultWhereFragment(); _idType = PostgresqlProvider.Instance.ToParameterType(typeof(TId)); var table = _mapping.Schema.Table; _selectFields = table.SelectColumns(storageStyle).Select(x => $"d.{x.Name}").ToArray(); var fieldSelector = _selectFields.Join(", "); _selectClause = $"select {fieldSelector} from {document.TableName.QualifiedName} as d"; _loaderSql = $"select {fieldSelector} from {document.TableName.QualifiedName} as d where id = :id"; _loadArraySql = $"select {fieldSelector} from {document.TableName.QualifiedName} as d where id = ANY(:ids)"; if (document.TenancyStyle == TenancyStyle.Conjoined) { _loaderSql += $" and {CurrentTenantFilter.Filter}"; _loadArraySql += $" and {CurrentTenantFilter.Filter}"; } UseOptimisticConcurrency = document.UseOptimisticConcurrency; _setter = LambdaBuilder.Setter <T, TId>(document.IdMember) !; DeleteFragment = _mapping.DeleteStyle == DeleteStyle.Remove ? (IOperationFragment) new HardDelete(this) : new SoftDelete(this); HardDeleteFragment = new HardDelete(this); DuplicatedFields = _mapping.DuplicatedFields; }
private Type determineOpenDocumentStorageType(StorageStyle style) { switch (style) { case StorageStyle.Lightweight: return(typeof(LightweightDocumentStorage <,>)); case StorageStyle.IdentityMap: return(typeof(IdentityMapDocumentStorage <,>)); case StorageStyle.QueryOnly: return(typeof(QueryOnlyDocumentStorage <,>)); case StorageStyle.DirtyTracking: return(typeof(DirtyTrackingDocumentStorage <,>)); } throw new NotSupportedException(); }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { if (storageStyle == StorageStyle.QueryOnly) { return; } sync.Frames.Code($"var id = reader.GetFieldValue<{mapping.IdType.FullNameInCode()}>({index});"); async.Frames.CodeAsync($"var id = await reader.GetFieldValueAsync<{mapping.IdType.FullNameInCode()}>({index}, token);"); if (storageStyle != StorageStyle.Lightweight) { sync.Frames.Code(IdentityMapCode); async.Frames.Code(IdentityMapCode); } }
internal ISelectableColumn[] SelectColumns(StorageStyle style) { // There's some hokey stuff going here, but older code assumes that the // order of the selection is data, id, everything else var columns = Columns.OfType <ISelectableColumn>().Where(x => x.ShouldSelect(_mapping, style)).ToList(); var id = columns.OfType <IdColumn>().SingleOrDefault(); var data = columns.OfType <DataColumn>().Single(); var type = columns.OfType <DocumentTypeColumn>().SingleOrDefault(); var version = columns.OfType <VersionColumn>().SingleOrDefault(); var answer = new List <ISelectableColumn>(); if (id != null) { columns.Remove(id); answer.Add(id); } columns.Remove(data); answer.Add(data); if (type != null) { columns.Remove(type); // Old code might depend on this exact ordering answer.Add(type); } if (version != null) { columns.Remove(version); answer.Add(version); } answer.AddRange(columns); return(answer.ToArray()); }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { var versionPosition = index;//mapping.IsHierarchy() ? 3 : 2; async.Frames.CodeAsync($"var version = await reader.GetFieldValueAsync<System.Guid>({versionPosition}, token);"); sync.Frames.Code($"var version = reader.GetFieldValue<System.Guid>({versionPosition});"); if (storageStyle != StorageStyle.QueryOnly) { // Store it sync.Frames.Code("_versions[id] = version;"); async.Frames.Code("_versions[id] = version;"); } if (Member != null) { sync.Frames.SetMemberValue(Member, "version", mapping.DocumentType, generatedType); async.Frames.SetMemberValue(Member, "version", mapping.DocumentType, generatedType); } }
protected IdentityMapDocumentStorage(StorageStyle storageStyle, DocumentMapping document) : base(storageStyle, document) { }
public static string DeriveTypeName(DocumentMapping mapping, StorageStyle style) { return($"{style}{mapping.DocumentType.ToSuffixedTypeName("DocumentStorage")}"); }
public static string DeriveTypeName(DocumentMapping mapping, StorageStyle style) { return($"{style}{mapping.DocumentType.Name.Sanitize()}DocumentStorage"); }
public bool ShouldSelect(DocumentMapping mapping, StorageStyle storageStyle) { return(mapping.Metadata.LastModifiedBy.EnabledWithMember()); }
public void GenerateCode(StorageStyle storageStyle, GeneratedType generatedType, GeneratedMethod async, GeneratedMethod sync, int index, DocumentMapping mapping) { setMemberFromReader(generatedType, async, sync, index, mapping); }
public bool ShouldSelect(DocumentMapping mapping, StorageStyle storageStyle) { return(storageStyle != StorageStyle.QueryOnly); }
public void basic_select_columns(StorageStyle style, string[] expected) { theTable.SelectColumns(style) .Select(x => x.Name) .ShouldHaveTheSameElementsAs(expected); }
public bool ShouldSelect(DocumentMapping mapping, StorageStyle storageStyle) { return(true); }
public SelectorBuilder(DocumentMapping mapping, StorageStyle style) { _mapping = mapping; _style = style; }
public bool ShouldSelect(DocumentMapping mapping, StorageStyle storageStyle) { return(mapping.Metadata.CorrelationId.EnabledWithMember()); }
public bool ShouldSelect(DocumentMapping mapping, StorageStyle storageStyle) { return(Member != null); }
/// <summary> /// Enables the ICacheKeyCreator to be injected into /// types (constructors cannot be constrained by interfaces). /// </summary> public Key Create(TimeSpan durationToStore, StorageStyle cacheStorageStyle, ExpirationType cacheExpirationType, string friendlyName) { return new Key(durationToStore, cacheStorageStyle, cacheExpirationType, friendlyName); }