/// <summary>
        /// The primary factory method to produce the BridgeDataReader; given a store data
        /// reader and a column map, create the BridgeDataReader, hooking up the IteratorSources
        /// and ResultColumn Hierarchy.  All construction of top level data readers go through
        /// this method.
        /// </summary>
        /// <param name="storeDataReader"></param>
        /// <param name="columnMap">column map of the first result set</param>
        /// <param name="nextResultColumnMaps">enumerable of the column maps for NextResult() calls.</param>
        /// <returns></returns>
        static internal DbDataReader Create(DbDataReader storeDataReader, ColumnMap columnMap, MetadataWorkspace workspace, IEnumerable <ColumnMap> nextResultColumnMaps)
        {
            Debug.Assert(storeDataReader != null, "null storeDataReaders?");
            Debug.Assert(columnMap != null, "null columnMap?");
            Debug.Assert(workspace != null, "null workspace?");

            var          shaperInfo = CreateShaperInfo(storeDataReader, columnMap, workspace);
            DbDataReader result     = new BridgeDataReader(shaperInfo.Key, shaperInfo.Value, /*depth:*/ 0, GetNextResultShaperInfo(storeDataReader, workspace, nextResultColumnMaps).GetEnumerator());

            return(result);
        }
        /// <summary>
        /// The primary factory method to produce the BridgeDataReader; given a store data 
        /// reader and a column map, create the BridgeDataReader, hooking up the IteratorSources  
        /// and ResultColumn Hierarchy.  All construction of top level data readers go through
        /// this method.
        /// </summary>
        /// <param name="storeDataReader"></param>
        /// <param name="columnMap">column map of the first result set</param>
        /// <param name="nextResultColumnMaps">enumerable of the column maps for NextResult() calls.</param>
        /// <returns></returns>
        public virtual DbDataReader Create(
            DbDataReader storeDataReader, ColumnMap columnMap, MetadataWorkspace workspace, IEnumerable<ColumnMap> nextResultColumnMaps)
        {
            //Contract.Requires(storeDataReader != null);
            //Contract.Requires(columnMap != null);
            //Contract.Requires(workspace != null);
            //Contract.Requires(nextResultColumnMaps != null);

            var shaperInfo = CreateShaperInfo(storeDataReader, columnMap, workspace);
            DbDataReader result = new BridgeDataReader(
                shaperInfo.Key, shaperInfo.Value, /*depth:*/ 0,
                GetNextResultShaperInfo(storeDataReader, workspace, nextResultColumnMaps).GetEnumerator());
            return result;
        }
Exemplo 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();
            }
        }
Exemplo 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);
 }
Exemplo n.º 5
0
 /// <summary>
 /// implementation of DbDataRecord.GetFieldType() method
 /// </summary>
 /// <param name="ordinal"></param>
 /// <returns></returns>
 override public Type GetFieldType(int ordinal)
 {
     AssertReaderIsOpenWithData();
     return(BridgeDataReader.GetClrTypeFromTypeMetadata(GetTypeUsage(ordinal)));
 }
 /// <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();
     }
 }
        /// <summary>
        /// The primary factory method to produce the BridgeDataReader; given a store data 
        /// reader and a column map, create the BridgeDataReader, hooking up the IteratorSources  
        /// and ResultColumn Hierarchy.  All construction of top level data readers go through
        /// this method.
        /// </summary>
        /// <param name="storeDataReader"></param>
        /// <param name="columnMap">column map of the first result set</param>
        /// <param name="nextResultColumnMaps">enumerable of the column maps for NextResult() calls.</param>
        /// <returns></returns>
        static internal DbDataReader Create(DbDataReader storeDataReader, ColumnMap columnMap, MetadataWorkspace workspace, IEnumerable<ColumnMap> nextResultColumnMaps) {
            Debug.Assert(storeDataReader != null, "null storeDataReaders?");
            Debug.Assert(columnMap != null, "null columnMap?");
            Debug.Assert(workspace != null, "null workspace?");

            var shaperInfo = CreateShaperInfo(storeDataReader, columnMap, workspace);
            DbDataReader result = new BridgeDataReader(shaperInfo.Key, shaperInfo.Value, /*depth:*/ 0, GetNextResultShaperInfo(storeDataReader, workspace, nextResultColumnMaps).GetEnumerator());
            return result;
        }