Example #1
0
            public async Task <bool> MoveNext(CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                try
                {
                    await _queryingEnumerable._relationalQueryContext.Semaphore.WaitAsync(cancellationToken);

                    if (_buffer == null)
                    {
                        if (_dataReader == null)
                        {
                            await _queryingEnumerable._relationalQueryContext.Connection
                            .OpenAsync(cancellationToken);

                            var relationalCommand
                                = _queryingEnumerable._shaperCommandContext
                                  .GetRelationalCommand(_queryingEnumerable._relationalQueryContext.ParameterValues);

                            await _queryingEnumerable._relationalQueryContext
                            .RegisterValueBufferCursorAsync(this, _queryingEnumerable._queryIndex, cancellationToken);

                            _dataReader
                                = await relationalCommand.ExecuteReaderAsync(
                                      _queryingEnumerable._relationalQueryContext.Connection,
                                      _queryingEnumerable._relationalQueryContext.ParameterValues,
                                      manageConnection : false,
                                      cancellationToken : cancellationToken);

                            _dbDataReader = _dataReader.DbDataReader;
                            _queryingEnumerable._shaperCommandContext.NotifyReaderCreated(_dbDataReader);
                            _valueBufferFactory = _queryingEnumerable._shaperCommandContext.ValueBufferFactory;
                        }

                        var hasNext = await _dbDataReader.ReadAsync(cancellationToken);

                        _current
                            = hasNext
                                ? _valueBufferFactory.Create(_dbDataReader)
                                : default(ValueBuffer);

                        return(hasNext);
                    }

                    if (_buffer.Count > 0)
                    {
                        _current = _buffer.Dequeue();

                        return(true);
                    }

                    return(false);
                }
                finally
                {
                    _queryingEnumerable._relationalQueryContext.Semaphore.Release();
                }
            }
            private async Task <bool> BufferlessMoveNext(bool buffer, CancellationToken cancellationToken)
            {
                try
                {
                    if (_dataReader == null)
                    {
                        await _queryingEnumerable._relationalQueryContext.Connection
                        .OpenAsync(cancellationToken);

                        var relationalCommand
                            = _queryingEnumerable._shaperCommandContext
                              .GetRelationalCommand(_queryingEnumerable._relationalQueryContext.ParameterValues);

                        await _queryingEnumerable._relationalQueryContext
                        .RegisterValueBufferCursorAsync(this, cancellationToken);

                        _dataReader
                            = await relationalCommand.ExecuteReaderAsync(
                                  _queryingEnumerable._relationalQueryContext.Connection,
                                  _queryingEnumerable._relationalQueryContext.ParameterValues,
                                  cancellationToken);

                        _dbDataReader = _dataReader.DbDataReader;
                        _queryingEnumerable._shaperCommandContext.NotifyReaderCreated(_dbDataReader);
                        _valueBufferFactory = _queryingEnumerable._shaperCommandContext.ValueBufferFactory;
                    }

                    var hasNext = await _dbDataReader.ReadAsync(cancellationToken);

                    _current
                        = hasNext
                            ? _valueBufferFactory.Create(_dbDataReader)
                            : default(ValueBuffer);

                    if (buffer)
                    {
                        await BufferAllAsync(cancellationToken);
                    }

                    return(hasNext);
                }
                catch (Exception)
                {
                    _queryingEnumerable._relationalQueryContext.DeregisterValueBufferCursor(this);
                    _dataReader   = null;
                    _dbDataReader = null;

                    throw;
                }
            }
Example #3
0
            private async Task <bool> BufferlessMoveNext(DbContext _, bool buffer, CancellationToken cancellationToken)
            {
                if (_dataReader == null)
                {
                    await _relationalQueryContext.Connection.OpenAsync(cancellationToken);

                    try
                    {
                        var relationalCommand
                            = _shaperCommandContext
                              .GetRelationalCommand(_relationalQueryContext.ParameterValues, _relationalQueryContext);

                        await _relationalQueryContext.Connection
                        .RegisterBufferableAsync(this, cancellationToken);

                        _dataReader
                            = await relationalCommand.ExecuteReaderAsync(
                                  _relationalQueryContext.Connection,
                                  _relationalQueryContext.ParameterValues,
                                  _relationalQueryContext.CommandLogger,
                                  cancellationToken);
                    }
                    catch
                    {
                        // If failure happens creating the data reader, then it won't be available to
                        // handle closing the connection, so do it explicitly here to preserve ref counting.
                        _relationalQueryContext.Connection.Close();

                        throw;
                    }

                    _dbDataReader = _dataReader.DbDataReader;
                    _shaperCommandContext.NotifyReaderCreated(_dbDataReader);
                    _valueBufferFactory = _shaperCommandContext.ValueBufferFactory;
                }

                var hasNext = await _dataReader.ReadAsync(cancellationToken);

                Current
                    = hasNext
                        ? _shaper.Shape(_relationalQueryContext, _valueBufferFactory.Create(_dbDataReader))
                        : default;

                if (buffer)
                {
                    await BufferAllAsync(cancellationToken);
                }

                return(hasNext);
            }
            private bool BufferlessMoveNext(bool buffer)
            {
                try
                {
                    if (_dataReader == null)
                    {
                        _queryingEnumerable._relationalQueryContext.Connection.Open();

                        var relationalCommand
                            = _queryingEnumerable._shaperCommandContext
                              .GetRelationalCommand(_queryingEnumerable._relationalQueryContext.ParameterValues);

                        _queryingEnumerable._relationalQueryContext
                        .RegisterValueBufferCursor(this, _queryingEnumerable._queryIndex);

                        _dataReader
                            = relationalCommand.ExecuteReader(
                                  _queryingEnumerable._relationalQueryContext.Connection,
                                  _queryingEnumerable._relationalQueryContext.ParameterValues);

                        _dbDataReader = _dataReader.DbDataReader;
                        _queryingEnumerable._shaperCommandContext.NotifyReaderCreated(_dbDataReader);
                        _valueBufferFactory = _queryingEnumerable._shaperCommandContext.ValueBufferFactory;
                    }

                    var hasNext = _dbDataReader.Read();

                    _current
                        = hasNext
                            ? _valueBufferFactory.Create(_dbDataReader)
                            : default(ValueBuffer);

                    if (buffer)
                    {
                        BufferAll();
                    }

                    return(hasNext);
                }
                catch (Exception)
                {
                    _queryingEnumerable._relationalQueryContext.DeregisterValueBufferCursor(this);
                    _dataReader   = null;
                    _dbDataReader = null;

                    throw;
                }
            }
            private bool BufferlessMoveNext(DbContext _, bool buffer)
            {
                if (_dataReader == null)
                {
                    _relationalQueryContext.Connection.Open();

                    try
                    {
                        var relationalCommand
                            = _shaperCommandContext
                              .GetRelationalCommand(_relationalQueryContext.ParameterValues);

                        _relationalQueryContext.Connection.RegisterBufferable(this);

                        _dataReader
                            = relationalCommand.ExecuteReader(
                                  _relationalQueryContext.Connection,
                                  _relationalQueryContext.ParameterValues);
                    }
                    catch
                    {
                        // If failure happens creating the data reader, then it won't be available to
                        // handle closing the connection, so do it explicitly here to preserve ref counting.
                        _relationalQueryContext.Connection.Close();

                        throw;
                    }

                    _dbDataReader = _dataReader.DbDataReader;
                    _shaperCommandContext.NotifyReaderCreated(_dbDataReader);
                    _valueBufferFactory = _shaperCommandContext.ValueBufferFactory;
                }

                var hasNext = _dataReader.Read();

                Current
                    = hasNext
                        ? _shaper.Shape(_relationalQueryContext, _valueBufferFactory.Create(_dbDataReader))
                        : default;

                if (buffer)
                {
                    BufferAll();
                }

                return(hasNext);
            }
            public bool MoveNext()
            {
                if (_buffer == null)
                {
                    if (_dataReader == null)
                    {
                        _queryingEnumerable._relationalQueryContext.Connection.Open();

                        var relationalCommand
                            = _queryingEnumerable._shaperCommandContext
                              .GetRelationalCommand(_queryingEnumerable._relationalQueryContext.ParameterValues);

                        _queryingEnumerable._relationalQueryContext
                        .RegisterValueBufferCursor(this, _queryingEnumerable._queryIndex);

                        _dataReader
                            = relationalCommand.ExecuteReader(
                                  _queryingEnumerable._relationalQueryContext.Connection,
                                  _queryingEnumerable._relationalQueryContext.ParameterValues,
                                  manageConnection: false);

                        _dbDataReader = _dataReader.DbDataReader;
                        _queryingEnumerable._shaperCommandContext.NotifyReaderCreated(_dbDataReader);
                        _valueBufferFactory = _queryingEnumerable._shaperCommandContext.ValueBufferFactory;
                    }

                    var hasNext = _dbDataReader.Read();

                    _current
                        = hasNext
                            ? _valueBufferFactory.Create(_dbDataReader)
                            : default(ValueBuffer);

                    return(hasNext);
                }

                if (_buffer.Count > 0)
                {
                    _current = _buffer.Dequeue();

                    return(true);
                }

                return(false);
            }
Example #7
0
        /// <summary>
        /// 异步恢复
        /// </summary>
        /// <param name="relationalReader">关系DataReader</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns></returns>
        protected override async Task ConsumeAsync(RelationalDataReader relationalReader, CancellationToken cancellationToken = default(CancellationToken))
        {
            int commandPosition = 0;

            try
            {
                if (Check.IsTraceEnabled(m_oracleLogger?.Logger))
                {
                    Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Trace, OracleTraceTag.Entry, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.ConsumeAsync);
                }

                while (true)
                {
                    if (commandPosition < CommandResultSet.Count && CommandResultSet[commandPosition] == ResultSetMapping.NoResultSet)
                    {
                        commandPosition++;
                    }
                    else
                    {
                        if (commandPosition < CommandResultSet.Count)
                        {
                            if (ModificationCommands[commandPosition].RequiresResultPropagation)
                            {
                                int rowsAffected = 0;
                                int num          = 0;
                                do
                                {
                                    ModificationCommand tableModification = ModificationCommands[commandPosition];
                                    if (!(await relationalReader.ReadAsync(cancellationToken)))
                                    {
                                        throw new DbUpdateConcurrencyException(RelationalStrings.UpdateConcurrencyException(ModificationCommands.Count((ModificationCommand m) => m.RequiresResultPropagation), rowsAffected), ModificationCommands[commandPosition].Entries);
                                    }
                                    IRelationalValueBufferFactory relationalValueBufferFactory = CreateValueBufferFactory(tableModification.ColumnModifications);
                                    tableModification.PropagateResults(relationalValueBufferFactory.Create(relationalReader.DbDataReader));
                                    rowsAffected++;
                                    num             = commandPosition + 1;
                                    commandPosition = num;
                                }while (num < CommandResultSet.Count && CommandResultSet[commandPosition - 1] == ResultSetMapping.NotLastInResultSet);
                            }
                            else
                            {
                                int expectedRowsAffected = 1;
                                while (true)
                                {
                                    int num = commandPosition + 1;
                                    commandPosition = num;
                                    if (num >= CommandResultSet.Count || CommandResultSet[commandPosition - 1] != ResultSetMapping.NotLastInResultSet)
                                    {
                                        break;
                                    }
                                    expectedRowsAffected++;
                                }
                                if (!relationalReader.Read())
                                {
                                    break;
                                }
                                int rowsAffected = relationalReader.DbDataReader.GetInt32(0);
                                if (rowsAffected != expectedRowsAffected)
                                {
                                    throw new DbUpdateConcurrencyException(RelationalStrings.UpdateConcurrencyException(expectedRowsAffected, rowsAffected), ModificationCommands[commandPosition - 1].Entries);
                                }
                            }
                        }
                        bool flag = commandPosition < CommandResultSet.Count;
                        if (flag)
                        {
                            flag = await relationalReader.DbDataReader.NextResultAsync(cancellationToken);
                        }
                        if (!flag)
                        {
                            return;
                        }
                    }
                }
                throw new DbUpdateConcurrencyException(RelationalStrings.UpdateConcurrencyException(1, 0), ModificationCommands[commandPosition - 1].Entries);
            }
            catch (DbUpdateException dbEx)
            {
                if (Check.IsErrorEnabled(m_oracleLogger?.Logger))
                {
                    Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Error, OracleTraceTag.Error, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.ConsumeAsync, dbEx.ToString());
                }
                throw;
            }
            catch (Exception ex)
            {
                if (Check.IsErrorEnabled(m_oracleLogger?.Logger))
                {
                    Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Error, OracleTraceTag.Error, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.ConsumeAsync, ex.ToString());
                }
                throw new DbUpdateException(RelationalStrings.UpdateStoreException, ex, ModificationCommands[commandPosition].Entries);
            }
        }
Example #8
0
        /// <summary>
        /// 恢复
        /// </summary>
        /// <param name="relationalReader">关系DataReader</param>
        protected override void Consume(RelationalDataReader relationalReader)
        {
            int commandPosition = 0;
            int rowsAffected    = 0;

            try
            {
                if (Check.IsTraceEnabled(m_oracleLogger?.Logger))
                {
                    Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Trace, OracleTraceTag.Entry, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.Consume);
                }

                while (true)
                {
                    if (commandPosition < CommandResultSet.Count && CommandResultSet[commandPosition] == ResultSetMapping.NoResultSet)
                    {
                        commandPosition++;
                    }
                    else
                    {
                        if (commandPosition < CommandResultSet.Count)
                        {
                            if (ModificationCommands[commandPosition].RequiresResultPropagation)
                            {
                                rowsAffected = 0;
                                do
                                {
                                    ModificationCommand modificationCommand = ModificationCommands[commandPosition];
                                    if (!relationalReader.Read())
                                    {
                                        throw new DbUpdateConcurrencyException(RelationalStrings.UpdateConcurrencyException(ModificationCommands.Count((ModificationCommand m) => m.RequiresResultPropagation), rowsAffected), ModificationCommands[commandPosition].Entries);
                                    }
                                    IRelationalValueBufferFactory relationalValueBufferFactory = CreateValueBufferFactory(modificationCommand.ColumnModifications);
                                    modificationCommand.PropagateResults(relationalValueBufferFactory.Create(relationalReader.DbDataReader));
                                    rowsAffected++;
                                    foreach (ColumnModification columnModification in modificationCommand.ColumnModifications)
                                    {
                                        if (Check.IsTraceEnabled(m_oracleLogger?.Logger))
                                        {
                                            Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Trace, OracleTraceTag.SQL, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.Consume, $"Column Name: {columnModification.ColumnName}");
                                        }
                                    }
                                }while (++commandPosition < CommandResultSet.Count && CommandResultSet[commandPosition - 1] == ResultSetMapping.NotLastInResultSet);
                            }
                            else
                            {
                                int expectedRowsAffected = 1;
                                while (++commandPosition < CommandResultSet.Count && CommandResultSet[commandPosition - 1] == ResultSetMapping.NotLastInResultSet)
                                {
                                    expectedRowsAffected++;
                                }
                                if (!relationalReader.Read())
                                {
                                    break;
                                }
                                rowsAffected = relationalReader.DbDataReader.GetInt32(0);
                                if (rowsAffected != expectedRowsAffected)
                                {
                                    throw new DbUpdateConcurrencyException(RelationalStrings.UpdateConcurrencyException(expectedRowsAffected, rowsAffected), ModificationCommands[commandPosition - 1].Entries);
                                }
                            }
                        }
                        if (commandPosition >= CommandResultSet.Count || !relationalReader.DbDataReader.NextResult())
                        {
                            return;
                        }
                    }
                }
                throw new DbUpdateConcurrencyException(RelationalStrings.UpdateConcurrencyException(1, 0), ModificationCommands[commandPosition - 1].Entries);
            }
            catch (DbUpdateException dbEx)
            {
                if (Check.IsErrorEnabled(m_oracleLogger?.Logger))
                {
                    Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Error, OracleTraceTag.Error, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.Consume, dbEx.ToString());
                }
                throw;
            }
            catch (Exception ex)
            {
                if (Check.IsErrorEnabled(m_oracleLogger?.Logger))
                {
                    Trace <DbLoggerCategory.Update> .Write(m_oracleLogger, LogLevel.Error, OracleTraceTag.Error, OracleTraceClassName.OracleModificationCommandBatch, OracleTraceFuncName.Consume, ex.ToString());
                }
                throw new DbUpdateException(RelationalStrings.UpdateStoreException, ex, ModificationCommands[commandPosition - 1].Entries);
            }
        }