1 //------------------------------------------------------------------------------
2 // <copyright file="ShaperFactory.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">[....]</owner>
6 // <owner current="true" primary="false">[....]</owner>
7 //------------------------------------------------------------------------------
9 using System.Data.Common.QueryCache;
10 using System.Data.Metadata.Edm;
11 using System.Data.Objects;
12 using System.Data.Objects.Internal;
13 using System.Data.Query.InternalTrees;
14 using System.Diagnostics;
15 using System.Runtime.CompilerServices;
17 namespace System.Data.Common.Internal.Materialization
20 /// An immutable type used to generate Shaper instances.
22 internal abstract class ShaperFactory
24 [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
25 internal static ShaperFactory Create(Type elementType, QueryCacheManager cacheManager, ColumnMap columnMap, MetadataWorkspace metadata, SpanIndex spanInfo, MergeOption mergeOption, bool valueLayer)
27 ShaperFactoryCreator creator = (ShaperFactoryCreator)Activator.CreateInstance(typeof(TypedShaperFactoryCreator<>).MakeGenericType(elementType));
28 return creator.TypedCreate(cacheManager, columnMap, metadata, spanInfo, mergeOption, valueLayer);
31 private abstract class ShaperFactoryCreator
33 internal abstract ShaperFactory TypedCreate(QueryCacheManager cacheManager, ColumnMap columnMap, MetadataWorkspace metadata, SpanIndex spanInfo, MergeOption mergeOption, bool valueLayer);
36 private sealed class TypedShaperFactoryCreator<T> : ShaperFactoryCreator
38 public TypedShaperFactoryCreator() {}
39 internal override ShaperFactory TypedCreate(QueryCacheManager cacheManager, ColumnMap columnMap, MetadataWorkspace metadata, SpanIndex spanInfo, MergeOption mergeOption, bool valueLayer)
41 return Translator.TranslateColumnMap<T>(cacheManager, columnMap, metadata, spanInfo, mergeOption, valueLayer);
47 /// Typed ShaperFactory
49 internal class ShaperFactory<T> : ShaperFactory
51 private readonly int _stateCount;
52 private readonly CoordinatorFactory<T> _rootCoordinatorFactory;
53 private readonly Action _checkPermissions;
54 private readonly MergeOption _mergeOption;
56 internal ShaperFactory(int stateCount, CoordinatorFactory<T> rootCoordinatorFactory, Action checkPermissions, MergeOption mergeOption)
58 _stateCount = stateCount;
59 _rootCoordinatorFactory = rootCoordinatorFactory;
60 _checkPermissions = checkPermissions;
61 _mergeOption = mergeOption;
65 /// Factory method to create the Shaper for Object Layer queries.
67 internal Shaper<T> Create(DbDataReader reader, ObjectContext context, MetadataWorkspace workspace, MergeOption mergeOption, bool readerOwned)
69 Debug.Assert(mergeOption == _mergeOption, "executing a query with a different mergeOption than was used to compile the delegate");
70 return new Shaper<T>(reader, context, workspace, mergeOption, _stateCount, _rootCoordinatorFactory, _checkPermissions, readerOwned);