Ejemplo n.º 1
0
        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?");
        }
        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)
            {
                RecordState 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?");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Ensure that whatever column we're currently processing is implicitly closed;
        /// </summary>
        private void CloseNestedObjectImplicitly()
        {
            // it would be nice to use Interlocked.Exchange to avoid multi-thread `race condition risk
            // when the the bridge is being misused by the user accessing it with multiple threads.
            // but this is called frequently enough to have a performance impact
            BridgeDataRecord currentNestedRecord = _currentNestedRecord;

            if (null != currentNestedRecord)
            {
                _currentNestedRecord = null;
                currentNestedRecord.CloseImplicitly();
            }
            BridgeDataReader currentNestedReader = _currentNestedReader;

            if (null != currentNestedReader)
            {
                _currentNestedReader = null;
                currentNestedReader.CloseImplicitly();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// For nested objects (records/readers) we have a bit more work to do; this
 /// method extracts it all out from the main GetValue method so it doesn't
 /// have to be so big.
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 private object GetNestedObjectValue(object result)
 {
     if (result != DBNull.Value)
     {
         RecordState recordState = result as RecordState;
         if (null != recordState)
         {
             if (recordState.IsNull)
             {
                 result = DBNull.Value;
             }
             else
             {
                 BridgeDataRecord nestedRecord = new BridgeDataRecord(Shaper, Depth + 1);
                 nestedRecord.SetRecordSource(recordState, true);
                 result = nestedRecord;
                 _currentNestedRecord = nestedRecord;
                 _currentNestedReader = null;
             }
         }
         else
         {
             Coordinator <RecordState> coordinator = result as Coordinator <RecordState>;
             if (null != coordinator)
             {
                 BridgeDataReader nestedReader = new BridgeDataReader(Shaper, coordinator.TypedCoordinatorFactory, Depth + 1, nextResultShaperInfos: null);
                 result = nestedReader;
                 _currentNestedRecord = null;
                 _currentNestedReader = nestedReader;
             }
             else
             {
                 Debug.Fail("unexpected type of nested object result: " + result.GetType().ToString());
             }
         }
     }
     return(result);
 }
 /// <summary>
 /// For nested objects (records/readers) we have a bit more work to do; this
 /// method extracts it all out from the main GetValue method so it doesn't 
 /// have to be so big.
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 private object GetNestedObjectValue(object result) {
     if (result != DBNull.Value) {
         RecordState recordState = result as RecordState;
         if (null != recordState) {
             if (recordState.IsNull) {
                 result = DBNull.Value;
             }
             else {
                 BridgeDataRecord nestedRecord = new BridgeDataRecord(Shaper, Depth + 1);
                 nestedRecord.SetRecordSource(recordState, true);
                 result = nestedRecord;
                 _currentNestedRecord = nestedRecord;
                 _currentNestedReader = null;
             }
         }
         else {
             Coordinator<RecordState> coordinator = result as Coordinator<RecordState>;
             if (null != coordinator) {
                 BridgeDataReader nestedReader = new BridgeDataReader(Shaper, coordinator.TypedCoordinatorFactory, Depth + 1, nextResultShaperInfos: null);
                 result = nestedReader;
                 _currentNestedRecord = null;
                 _currentNestedReader = nestedReader;
             }
             else {
                 Debug.Fail("unexpected type of nested object result: " + result.GetType().ToString());
             }
         }
     }
     return result;
 }
 /// <summary>
 /// Ensure that whatever column we're currently processing is implicitly closed;
 /// </summary>
 private void CloseNestedObjectImplicitly() {
     // it would be nice to use Interlocked.Exchange to avoid multi-thread `race condition risk
     // when the the bridge is being misused by the user accessing it with multiple threads.
     // but this is called frequently enough to have a performance impact
     BridgeDataRecord currentNestedRecord = _currentNestedRecord;
     if (null != currentNestedRecord) {
         _currentNestedRecord = null;
         currentNestedRecord.CloseImplicitly();
     }
     BridgeDataReader currentNestedReader = _currentNestedReader;
     if (null != currentNestedReader) {
         _currentNestedReader = null;
         currentNestedReader.CloseImplicitly();
     }
 }