Example #1
0
 internal RecordState(RecordStateFactory recordStateFactory, CoordinatorFactory coordinatorFactory)
 {
     RecordStateFactory  = recordStateFactory;
     CoordinatorFactory  = coordinatorFactory;
     CurrentColumnValues = new object[RecordStateFactory.ColumnCount];
     PendingColumnValues = new object[RecordStateFactory.ColumnCount];
 }
        private void SetShaper(Shaper<RecordState> shaper, CoordinatorFactory<RecordState> coordinatorFactory, int depth)
        {
            _shaper = shaper;
            _coordinatorFactory = coordinatorFactory;
            _dataRecord = new BridgeDataRecord(shaper, depth);

            // To determine whether there are any rows for this coordinator at this place in 
            // the root enumerator, we pretty much just look at it's current record (we'll read 
            // one if there isn't one waiting) and if it matches our coordinator, we've got rows.
            _hasRows = false;

            if (!_shaper.DataWaiting)
            {
                _shaper.DataWaiting = _shaper.RootEnumerator.MoveNext();
            }

            if (_shaper.DataWaiting)
            {
                var currentRecord = _shaper.RootEnumerator.Current;

                if (null != currentRecord)
                {
                    _hasRows = (currentRecord.CoordinatorFactory == _coordinatorFactory);
                }
            }

            // Once we've created the root enumerator, we can get the default record state
            _defaultRecordState = coordinatorFactory.GetDefaultRecordState(_shaper);
            Debug.Assert(null != _defaultRecordState, "no default?");
        }
Example #3
0
        internal CoordinatorFactory Compile()
        {
            RecordStateFactory[] recordStateFactoryArray;
            if (this._recordStateScratchpads != null)
            {
                recordStateFactoryArray = new RecordStateFactory[this._recordStateScratchpads.Count];
                for (int index = 0; index < recordStateFactoryArray.Length; ++index)
                {
                    recordStateFactoryArray[index] = this._recordStateScratchpads[index].Compile();
                }
            }
            else
            {
                recordStateFactoryArray = new RecordStateFactory[0];
            }
            CoordinatorFactory[] coordinatorFactoryArray = new CoordinatorFactory[this._nestedCoordinatorScratchpads.Count];
            for (int index = 0; index < coordinatorFactoryArray.Length; ++index)
            {
                coordinatorFactoryArray[index] = this._nestedCoordinatorScratchpads[index].Compile();
            }
            Expression expression1 = new CoordinatorScratchpad.ReplacementExpressionVisitor((Dictionary <Expression, Expression>)null, this._inlineDelegates).Visit(this.Element);
            Expression expression2 = new CoordinatorScratchpad.ReplacementExpressionVisitor(this._expressionWithErrorHandlingMap, this._inlineDelegates).Visit(this.Element);

            return((CoordinatorFactory)Activator.CreateInstance(typeof(CoordinatorFactory <>).MakeGenericType(this._elementType), (object)this.Depth, (object)this.StateSlotNumber, (object)this.HasData, (object)this.SetKeys, (object)this.CheckKeys, (object)coordinatorFactoryArray, (object)expression1, (object)expression2, (object)this.InitializeCollection, (object)recordStateFactoryArray));
        }
 internal RecordState(RecordStateFactory recordStateFactory, CoordinatorFactory coordinatorFactory)
 {
     RecordStateFactory = recordStateFactory;
     CoordinatorFactory = coordinatorFactory;
     CurrentColumnValues = new object[RecordStateFactory.ColumnCount];
     PendingColumnValues = new object[RecordStateFactory.ColumnCount];
 }
 internal ShaperFactory(
     int stateCount, CoordinatorFactory <T> rootCoordinatorFactory, MergeOption mergeOption)
 {
     _stateCount             = stateCount;
     _rootCoordinatorFactory = rootCoordinatorFactory;
     _mergeOption            = mergeOption;
 }
Example #6
0
 internal ShaperFactory(
     int stateCount, CoordinatorFactory <T> rootCoordinatorFactory, Action checkPermissions, MergeOption mergeOption)
 {
     _stateCount             = stateCount;
     _rootCoordinatorFactory = rootCoordinatorFactory;
     _checkPermissions       = checkPermissions;
     _mergeOption            = mergeOption;
 }
Example #7
0
 internal ShaperFactory(
     int stateCount, CoordinatorFactory <T> rootCoordinatorFactory, Type[] columnTypes, bool[] nullableColumns, MergeOption mergeOption)
 {
     _stateCount             = stateCount;
     _rootCoordinatorFactory = rootCoordinatorFactory;
     ColumnTypes             = columnTypes;
     NullableColumns         = nullableColumns;
     _mergeOption            = mergeOption;
 }
 internal RecordState(
     RecordStateFactory recordStateFactory,
     CoordinatorFactory coordinatorFactory)
 {
     this.RecordStateFactory  = recordStateFactory;
     this.CoordinatorFactory  = coordinatorFactory;
     this.CurrentColumnValues = new object[this.RecordStateFactory.ColumnCount];
     this.PendingColumnValues = new object[this.RecordStateFactory.ColumnCount];
 }
        protected CoordinatorFactory(
            int depth, int stateSlot, Func<Shaper, bool> hasData, Func<Shaper, bool> setKeys, Func<Shaper, bool> checkKeys,
            CoordinatorFactory[] nestedCoordinators, RecordStateFactory[] recordStateFactories)
        {
            Depth = depth;
            StateSlot = stateSlot;

            // figure out if there are any nested coordinators
            IsLeafResult = 0 == nestedCoordinators.Length;

            // if there is no explicit 'has data' discriminator, it means all rows contain data for the coordinator
            if (hasData == null)
            {
                HasData = _alwaysTrue;
            }
            else
            {
                HasData = hasData;
            }

            // if there is no explicit set key delegate, just return true (the value is not used anyways)
            if (setKeys == null)
            {
                SetKeys = _alwaysTrue;
            }
            else
            {
                SetKeys = setKeys;
            }

            // If there are no keys, it means different things depending on whether we are a leaf
            // coordinator or an inner (or 'driving') coordinator. For a leaf coordinator, it means
            // that every row is a new result. For an inner coordinator, it means that there is no
            // key to check. This should only occur where there is a SingleRowTable (in other words,
            // all rows are elements of a single child collection).
            if (checkKeys == null)
            {
                if (IsLeafResult)
                {
                    CheckKeys = _alwaysFalse; // every row is a new result (the keys don't match)
                }
                else
                {
                    CheckKeys = _alwaysTrue; // every row belongs to a single child collection
                }
            }
            else
            {
                CheckKeys = checkKeys;
            }
            NestedCoordinators = new ReadOnlyCollection<CoordinatorFactory>(nestedCoordinators);
            RecordStateFactories = new ReadOnlyCollection<RecordStateFactory>(recordStateFactories);

            // Determines whether this coordinator can be handled by a 'simple' enumerator. See IsSimple for details.
            IsSimple = IsLeafResult && null == checkKeys && null == hasData;
        }
        internal BridgeDataReader(
            Shaper<RecordState> shaper, CoordinatorFactory<RecordState> coordinatorFactory, int depth,
            IEnumerator<KeyValuePair<Shaper<RecordState>, CoordinatorFactory<RecordState>>> nextResultShaperInfos)
        {
            Contract.Requires(null != shaper);
            Contract.Requires(null != coordinatorFactory);
            Contract.Requires(depth == 0 || nextResultShaperInfos == null, "Nested data readers should not have multiple result sets.");

            _nextResultShaperInfoEnumerator = nextResultShaperInfos;
            SetShaper(shaper, coordinatorFactory, depth);
        }
 private void InitializeRecordStates(CoordinatorFactory coordinatorFactory)
 {
     foreach (RecordStateFactory recordStateFactory in coordinatorFactory.RecordStateFactories)
     {
         this.State[recordStateFactory.StateSlotNumber] = (object)recordStateFactory.Create(coordinatorFactory);
     }
     foreach (CoordinatorFactory nestedCoordinator in coordinatorFactory.NestedCoordinators)
     {
         this.InitializeRecordStates(nestedCoordinator);
     }
 }
        // <summary>
        // Initialize the RecordStateFactory objects in their StateSlots.
        // </summary>
        private void InitializeRecordStates(CoordinatorFactory coordinatorFactory)
        {
            foreach (var recordStateFactory in coordinatorFactory.RecordStateFactories)
            {
                State[recordStateFactory.StateSlotNumber] = recordStateFactory.Create(coordinatorFactory);
            }

            foreach (var nestedCoordinatorFactory in coordinatorFactory.NestedCoordinators)
            {
                InitializeRecordStates(nestedCoordinatorFactory);
            }
        }
        internal Shaper(
            DbDataReader reader, ObjectContext context, MetadataWorkspace workspace, MergeOption mergeOption,
            int stateCount, CoordinatorFactory <T> rootCoordinatorFactory, bool readerOwned, bool streaming)
            : base(reader, context, workspace, mergeOption, stateCount, streaming)
        {
            DebugCheck.NotNull(rootCoordinatorFactory);

            RootCoordinator = (Coordinator <T>)rootCoordinatorFactory.CreateCoordinator(parent: null, next: null);
            _isObjectQuery  = !(typeof(T) == typeof(RecordState));
            _isActive       = true;
            RootCoordinator.Initialize(this);
            _readerOwned = readerOwned;
        }
        // <summary>
        // Use the information stored on the scratchpad to compile an immutable factory used
        // to construct the coordinators used at runtime when materializing results.
        // </summary>
        internal CoordinatorFactory Compile()
        {
            RecordStateFactory[] recordStateFactories;
            if (null != _recordStateScratchpads)
            {
                recordStateFactories = new RecordStateFactory[_recordStateScratchpads.Count];
                for (var i = 0; i < recordStateFactories.Length; i++)
                {
                    recordStateFactories[i] = _recordStateScratchpads[i].Compile();
                }
            }
            else
            {
                recordStateFactories = new RecordStateFactory[0];
            }

            var nestedCoordinators = new CoordinatorFactory[_nestedCoordinatorScratchpads.Count];

            for (var i = 0; i < nestedCoordinators.Length; i++)
            {
                nestedCoordinators[i] = _nestedCoordinatorScratchpads[i].Compile();
            }

            // compile inline delegates
            var replacementVisitor = new ReplacementExpressionVisitor(null, _inlineDelegates);
            var element            = replacementVisitor.Visit(Element);

            // substitute expressions that have error handlers into a new expression (used
            // when a more detailed exception message is needed)
            replacementVisitor = new ReplacementExpressionVisitor(_expressionWithErrorHandlingMap, _inlineDelegates);
            var elementWithErrorHandling = replacementVisitor.Visit(Element);

            var result =
                (CoordinatorFactory)Activator.CreateInstance(
                    typeof(CoordinatorFactory <>).MakeGenericType(_elementType), new object[]
            {
                Depth,
                StateSlotNumber,
                HasData,
                SetKeys,
                CheckKeys,
                nestedCoordinators,
                element,
                elementWithErrorHandling,
                InitializeCollection,
                recordStateFactories
            });

            return(result);
        }
Example #15
0
        internal Coordinator(
            CoordinatorFactory <T> coordinatorFactory,
            Coordinator parent,
            Coordinator next)
            : base((CoordinatorFactory)coordinatorFactory, parent, next)
        {
            this.TypedCoordinatorFactory = coordinatorFactory;
            Coordinator next1 = (Coordinator)null;

            foreach (CoordinatorFactory coordinatorFactory1 in coordinatorFactory.NestedCoordinators.Reverse <CoordinatorFactory>())
            {
                this.Child = coordinatorFactory1.CreateCoordinator((Coordinator)this, next1);
                next1      = this.Child;
            }
            this.IsUsingElementCollection = !this.IsRoot && typeof(T) != typeof(RecordState);
        }
Example #16
0
        internal Coordinator(CoordinatorFactory <T> coordinatorFactory, Coordinator parent, Coordinator next)
            : base(coordinatorFactory, parent, next)
        {
            TypedCoordinatorFactory = coordinatorFactory;

            // generate all children
            Coordinator nextChild = null;

            foreach (var nestedCoordinator in coordinatorFactory.NestedCoordinators.Reverse())
            {
                // last child processed is first child...
                Child     = nestedCoordinator.CreateCoordinator(this, nextChild);
                nextChild = Child;
            }

            IsUsingElementCollection = !IsRoot && (typeof(T) != typeof(RecordState));
        }
 internal Shaper(
     DbDataReader reader,
     ObjectContext context,
     MetadataWorkspace workspace,
     MergeOption mergeOption,
     int stateCount,
     CoordinatorFactory <T> rootCoordinatorFactory,
     bool readerOwned,
     bool streaming)
     : base(reader, context, workspace, mergeOption, stateCount, streaming)
 {
     this.RootCoordinator = (Coordinator <T>)rootCoordinatorFactory.CreateCoordinator((Coordinator)null, (Coordinator)null);
     this._isObjectQuery  = !(typeof(T) == typeof(RecordState));
     this._isActive       = true;
     this.RootCoordinator.Initialize((Shaper)this);
     this._readerOwned = readerOwned;
 }
 internal CoordinatorFactory(
     int depth,
     int stateSlot,
     Expression <Func <Shaper, bool> > hasData,
     Expression <Func <Shaper, bool> > setKeys,
     Expression <Func <Shaper, bool> > checkKeys,
     CoordinatorFactory[] nestedCoordinators,
     Expression <Func <Shaper, TElement> > element,
     Expression <Func <Shaper, IEntityWrapper> > wrappedElement,
     Expression <Func <Shaper, TElement> > elementWithErrorHandling,
     Expression <Func <Shaper, ICollection <TElement> > > initializeCollection,
     RecordStateFactory[] recordStateFactories)
     : base(depth, stateSlot, CoordinatorFactory <TElement> .CompilePredicate(hasData), CoordinatorFactory <TElement> .CompilePredicate(setKeys), CoordinatorFactory <TElement> .CompilePredicate(checkKeys), nestedCoordinators, recordStateFactories)
 {
     this.WrappedElement           = wrappedElement == null ? (Func <Shaper, IEntityWrapper>)null : wrappedElement.Compile();
     this.Element                  = element == null ? (Func <Shaper, TElement>)null : element.Compile();
     this.ElementWithErrorHandling = elementWithErrorHandling.Compile();
     this.InitializeCollection     = initializeCollection == null ? (Func <Shaper, ICollection <TElement> >)(s => (ICollection <TElement>) new List <TElement>()) : initializeCollection.Compile();
     this.Description              = new StringBuilder().Append("HasData: ").AppendLine(CoordinatorFactory <TElement> .DescribeExpression((Expression)hasData)).Append("SetKeys: ").AppendLine(CoordinatorFactory <TElement> .DescribeExpression((Expression)setKeys)).Append("CheckKeys: ").AppendLine(CoordinatorFactory <TElement> .DescribeExpression((Expression)checkKeys)).Append("Element: ").AppendLine(element == null ? CoordinatorFactory <TElement> .DescribeExpression((Expression)wrappedElement) : CoordinatorFactory <TElement> .DescribeExpression((Expression)element)).Append("ElementWithExceptionHandling: ").AppendLine(CoordinatorFactory <TElement> .DescribeExpression((Expression)elementWithErrorHandling)).Append("InitializeCollection: ").AppendLine(CoordinatorFactory <TElement> .DescribeExpression((Expression)initializeCollection)).ToString();
 }
        /// <summary>
        ///     Use the information stored on the scratchpad to compile an immutable factory used
        ///     to construct the coordinators used at runtime when materializing results.
        /// </summary>
        internal CoordinatorFactory Compile()
        {
            RecordStateFactory[] recordStateFactories;
            if (null != _recordStateScratchpads)
            {
                recordStateFactories = new RecordStateFactory[_recordStateScratchpads.Count];
                for (var i = 0; i < recordStateFactories.Length; i++)
                {
                    recordStateFactories[i] = _recordStateScratchpads[i].Compile();
                }
            }
            else
            {
                recordStateFactories = new RecordStateFactory[0];
            }

            var nestedCoordinators = new CoordinatorFactory[_nestedCoordinatorScratchpads.Count];
            for (var i = 0; i < nestedCoordinators.Length; i++)
            {
                nestedCoordinators[i] = _nestedCoordinatorScratchpads[i].Compile();
            }

            // compile inline delegates
            var replacementVisitor = new ReplacementExpressionVisitor(null, _inlineDelegates);
            var element = replacementVisitor.Visit(Element);

            // substitute expressions that have error handlers into a new expression (used
            // when a more detailed exception message is needed)
            replacementVisitor = new ReplacementExpressionVisitor(_expressionWithErrorHandlingMap, _inlineDelegates);
            var elementWithErrorHandling = replacementVisitor.Visit(Element);

            var result =
                (CoordinatorFactory)Activator.CreateInstance(
                    typeof(CoordinatorFactory<>).MakeGenericType(_elementType), new object[]
                        {
                            Depth,
                            StateSlotNumber,
                            HasData,
                            SetKeys,
                            CheckKeys,
                            nestedCoordinators,
                            element,
                            elementWithErrorHandling,
                            InitializeCollection,
                            recordStateFactories
                        });
            return result;
        }
 /// <summary>
 ///     It's GO time, create the record state.
 /// </summary>
 internal RecordState Create(CoordinatorFactory coordinatorFactory)
 {
     return new RecordState(this, coordinatorFactory);
 }
Example #21
0
 // <summary>
 // It's GO time, create the record state.
 // </summary>
 internal RecordState Create(CoordinatorFactory coordinatorFactory)
 {
     return(new RecordState(this, coordinatorFactory));
 }
 protected Coordinator(CoordinatorFactory coordinatorFactory, Coordinator parent, Coordinator next)
 {
     CoordinatorFactory = coordinatorFactory;
     Parent             = parent;
     Next = next;
 }