Exemple #1
0
        /// <summary>
        /// Creates a NDataReader from a <see cref="DbDataReader" />
        /// </summary>
        /// <param name="reader">The <see cref="DbDataReader" /> to get the records from the Database.</param>
        /// <param name="isMidstream"><see langword="true" /> if we are loading the <see cref="DbDataReader" /> in the middle of reading it.</param>
        /// <remarks>
        /// NHibernate attempts to not have to read the contents of an <see cref="DbDataReader"/> into memory until it absolutely
        /// has to.  What that means is that it might have processed some records from the <see cref="DbDataReader"/> and will
        /// pick up the <see cref="DbDataReader"/> midstream so that the underlying <see cref="DbDataReader"/> can be closed
        /// so a new one can be opened.
        /// </remarks>
        public static NDataReader Create(DbDataReader reader, bool isMidstream)
        {
            var dataReader = new NDataReader();
            var resultList = new List <NResult>(2);

            try
            {
                // if we are in midstream of processing a DataReader then we are already
                // positioned on the first row (index=0)
                if (isMidstream)
                {
                    dataReader.currentRowIndex = 0;
                }

                // there will be atleast one result
                resultList.Add(NResult.Create(reader, isMidstream));

                while (reader.NextResult())
                {
                    // the second, third, nth result is not processed midstream
                    resultList.Add(NResult.Create(reader, false));
                }

                dataReader.results = resultList.ToArray();
            }
            catch (Exception e)
            {
                throw new ADOException("There was a problem converting an DbDataReader to NDataReader", e);
            }
            finally
            {
                reader.Close();
            }
            return(dataReader);
        }
Exemple #2
0
 /// <summary>
 /// Reads all of the contents into memory because another <see cref="DbDataReader"/>
 /// needs to be opened.
 /// </summary>
 /// <remarks>
 /// This will result in a no op if the reader is closed or is already in memory.
 /// </remarks>
 public void ReadIntoMemory()
 {
     if (_reader.IsClosed == false && _reader.GetType() != typeof(NDataReader))
     {
         if (log.IsDebugEnabled)
         {
             log.Debug("Moving DbDataReader into an NDataReader.  It was converted in midstream " + _isMidstream.ToString());
         }
         _reader = NDataReader.Create(_reader, _isMidstream);
     }
 }
Exemple #3
0
 /// <summary>
 /// Reads all of the contents into memory because another <see cref="DbDataReader"/>
 /// needs to be opened.
 /// </summary>
 /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
 /// <remarks>
 /// This will result in a no op if the reader is closed or is already in memory.
 /// </remarks>
 public async Task ReadIntoMemoryAsync(CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     if (_reader.IsClosed == false && _reader.GetType() != typeof(NDataReader))
     {
         if (log.IsDebugEnabled)
         {
             log.Debug("Moving DbDataReader into an NDataReader.  It was converted in midstream " + _isMidstream.ToString());
         }
         _reader = await(NDataReader.CreateAsync(_reader, _isMidstream, cancellationToken)).ConfigureAwait(false);
     }
 }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the NHybridDataReader class.
        /// </summary>
        /// <param name="reader">The underlying DbDataReader to use.</param>
        /// <param name="inMemory"><see langword="true" /> if the contents of the DbDataReader should be read into memory right away.</param>
        public static NHybridDataReader Create(DbDataReader reader, bool inMemory)
        {
            var dataReader = new NHybridDataReader();

            if (inMemory)
            {
                dataReader._reader = NDataReader.Create(reader, false);
            }
            else
            {
                dataReader._reader = reader;
            }
            return(dataReader);
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the NHybridDataReader class.
        /// </summary>
        /// <param name="reader">The underlying DbDataReader to use.</param>
        /// <param name="inMemory"><see langword="true" /> if the contents of the DbDataReader should be read into memory right away.</param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        public static async Task <NHybridDataReader> CreateAsync(DbDataReader reader, bool inMemory, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var dataReader = new NHybridDataReader();

            if (inMemory)
            {
                dataReader._reader = await(NDataReader.CreateAsync(reader, false, cancellationToken)).ConfigureAwait(false);
            }
            else
            {
                dataReader._reader = reader;
            }
            return(dataReader);
        }
        /// <summary>
        /// Creates a NDataReader from a <see cref="DbDataReader" />
        /// </summary>
        /// <param name="reader">The <see cref="DbDataReader" /> to get the records from the Database.</param>
        /// <param name="isMidstream"><see langword="true" /> if we are loading the <see cref="DbDataReader" /> in the middle of reading it.</param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        /// <remarks>
        /// NHibernate attempts to not have to read the contents of an <see cref="DbDataReader"/> into memory until it absolutely
        /// has to.  What that means is that it might have processed some records from the <see cref="DbDataReader"/> and will
        /// pick up the <see cref="DbDataReader"/> midstream so that the underlying <see cref="DbDataReader"/> can be closed
        /// so a new one can be opened.
        /// </remarks>
        public static async Task <NDataReader> CreateAsync(DbDataReader reader, bool isMidstream, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var dataReader = new NDataReader();
            var resultList = new List <NResult>(2);

            try
            {
                // if we are in midstream of processing a DataReader then we are already
                // positioned on the first row (index=0)
                if (isMidstream)
                {
                    dataReader.currentRowIndex = 0;
                }

                // there will be atleast one result
                resultList.Add(await(NResult.CreateAsync(reader, isMidstream, cancellationToken)).ConfigureAwait(false));

                while (await(reader.NextResultAsync(cancellationToken)).ConfigureAwait(false))
                {
                    // the second, third, nth result is not processed midstream
                    resultList.Add(await(NResult.CreateAsync(reader, false, cancellationToken)).ConfigureAwait(false));
                }

                dataReader.results = resultList.ToArray();
            }

            catch (OperationCanceledException) { throw; }
            catch (Exception e)
            {
                throw new ADOException("There was a problem converting an DbDataReader to NDataReader", e);
            }
            finally
            {
                reader.Close();
            }
            return(dataReader);
        }