Beispiel #1
0
        public override void AddToBatch(IExpectation expectation)
        {
            totalExpectedRowsAffected += expectation.ExpectedRowCount;
            IDbCommand batchUpdate = CurrentCommand;

            Prepare(batchUpdate);
            Driver.AdjustCommand(batchUpdate);
            string lineWithParameters = null;
            var    sqlStatementLogger = Factory.Settings.SqlStatementLogger;

            if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled)
            {
                lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
                var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
                lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
                currentBatchCommandsLog.Append("command ")
                .Append(currentBatch.CountOfCommands)
                .Append(":")
                .AppendLine(lineWithParameters);
            }
            if (Log.IsDebugEnabled)
            {
                Log.Debug("Adding to batch:" + lineWithParameters);
            }
            currentBatch.Append((MySqlCommand)batchUpdate);

            if (currentBatch.CountOfCommands >= batchSize)
            {
                DoExecuteBatch(batchUpdate);
            }
        }
        public override void AddToBatch(IExpectation expectation)
        {
            _totalExpectedRowsAffected += expectation.ExpectedRowCount;
            var batchUpdate = CurrentCommand;

            Driver.AdjustCommand(batchUpdate);
            string lineWithParameters = null;
            var    sqlStatementLogger = Factory.Settings.SqlStatementLogger;

            if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
            {
                lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
                var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
                lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
                _currentBatchCommandsLog.Append("command ")
                .Append(_currentBatch.CountOfCommands)
                .Append(":")
                .AppendLine(lineWithParameters);
            }
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Adding to batch:{0}", lineWithParameters);
            }
            _currentBatch.Append((System.Data.SqlClient.SqlCommand)Driver.UnwrapDbCommand(batchUpdate));

            if (_currentBatch.CountOfCommands >= _batchSize)
            {
                ExecuteBatchWithTiming(batchUpdate);
            }
        }
        public override void AddToBatch(IExpectation expectation)
        {
            _totalExpectedRowsAffected += expectation.ExpectedRowCount;
            var batchUpdate = CurrentCommand;

            Driver.AdjustCommand(batchUpdate);
            var sqlStatementLogger = Factory.Settings.SqlStatementLogger;

            if (sqlStatementLogger.IsDebugEnabled)
            {
                var lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
                var formatStyle        = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
                lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
                _currentBatchCommandsLog.Append("command ")
                .Append(_currentBatch.CountOfCommands)
                .Append(":")
                .AppendLine(lineWithParameters);
            }

            var update = batchUpdate as ProfiledSqlDbCommand;

            if (update != null)
            {
                _currentBatch.Append(update.SqlCommand);
            }
            else
            {
                _currentBatch.Append((SqlCommand)batchUpdate);
            }

            if (_currentBatch.CountOfCommands >= _batchSize)
            {
                ExecuteBatchWithTiming(batchUpdate);
            }
        }
Beispiel #4
0
        /// <inheritdoc />
        public override async Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)
        {
            var entityInfo = ExtractEntityInfo();

            var cmd = CurrentCommand;

            Driver.AdjustCommand(cmd);

            if (entityInfo == null)
            {
                //Выполняем текущий батч
                await ExecuteBatchWithTimingAsync(CurrentCommand, cancellationToken);

                //Исполняем команду
                LogCommand(cmd);
                var rowCount = await ExecuteNonQueryAsync(cmd, cancellationToken);

                expectation.VerifyOutcomeNonBatched(rowCount, cmd);
                return;
            }

            mCurrentEntites.Add(entityInfo);

            if (mCurrentEntites.Count >= BatchSize)
            {
                await ExecuteBatchWithTimingAsync(CurrentCommand, cancellationToken);
            }
        }
		public override async Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)
		{
			cancellationToken.ThrowIfCancellationRequested();
			totalExpectedRowsAffected += expectation.ExpectedRowCount;
			var batchUpdate = CurrentCommand;
			await (PrepareAsync(batchUpdate, cancellationToken)).ConfigureAwait(false);
			Driver.AdjustCommand(batchUpdate);
			string lineWithParameters = null;
			var sqlStatementLogger = Factory.Settings.SqlStatementLogger;
			if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
			{
				lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
				var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
				lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
				currentBatchCommandsLog.Append("command ")
					.Append(currentBatch.CountOfCommands)
					.Append(":")
					.AppendLine(lineWithParameters);
			}
			if (Log.IsDebugEnabled())
			{
				Log.Debug("Adding to batch:{0}", lineWithParameters);
			}
			currentBatch.Append(batchUpdate);

			if (currentBatch.CountOfCommands >= batchSize)
			{
				await (DoExecuteBatchAsync(batchUpdate, cancellationToken)).ConfigureAwait(false);
			}
		}
        /// <inheritdoc />
        public override void AddToBatch(IExpectation expectation)
        {
            var entityInfo = ExtractEntityInfo();

            var cmd = CurrentCommand;

            if (entityInfo == null)
            {
                //Выполняем текущий батч
                ExecuteBatchWithTiming(CurrentCommand);

                //Исполняем команду
                Driver.AdjustCommand(cmd);
                LogCommand(cmd);
                var rowCount = ExecuteNonQuery(cmd);
                expectation.VerifyOutcomeNonBatched(rowCount, cmd);
                return;
            }

            mCurrentEntites.Add(entityInfo);

            if (mCurrentEntites.Count >= BatchSize)
            {
                ExecuteBatchWithTiming(CurrentCommand);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Executes the current <see cref="DbCommand"/> and compares the row Count
        /// to the <c>expectedRowCount</c>.
        /// </summary>
        /// <param name="expectation">
        /// The expected number of rows affected by the query.  A value of less than <c>0</c>
        /// indicates that the number of rows to expect is unknown or should not be a factor.
        /// </param>
        /// <exception cref="HibernateException">
        /// Thrown when there is an expected number of rows to be affected and the
        /// actual number of rows is different.
        /// </exception>
        public override void AddToBatch(IExpectation expectation)
        {
            var cmd = CurrentCommand;

            Driver.AdjustCommand(cmd);
            int rowCount = ExecuteNonQuery(cmd);

            expectation.VerifyOutcomeNonBatched(rowCount, cmd);
        }
Beispiel #8
0
        /// <summary>
        /// Executes the current <see cref="DbCommand"/> and compares the row Count
        /// to the <c>expectedRowCount</c>.
        /// </summary>
        /// <param name="expectation">
        /// The expected number of rows affected by the query.  A value of less than <c>0</c>
        /// indicates that the number of rows to expect is unknown or should not be a factor.
        /// </param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        /// <exception cref="HibernateException">
        /// Thrown when there is an expected number of rows to be affected and the
        /// actual number of rows is different.
        /// </exception>
        public override async Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var cmd = CurrentCommand;

            Driver.AdjustCommand(cmd);
            int rowCount = await(ExecuteNonQueryAsync(cmd, cancellationToken)).ConfigureAwait(false);

            expectation.VerifyOutcomeNonBatched(rowCount, cmd);
        }
Beispiel #9
0
        public override Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)
        {
            // HanaCommands are cloneable
            if (!(Driver.UnwrapDbCommand(CurrentCommand) is ICloneable cloneableCurrentCommand))
            {
                throw new InvalidOperationException("Current command is not an ICloneable");
            }
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <object>(cancellationToken));
            }
            return(InternalAddToBatchAsync());

            async Task InternalAddToBatchAsync()
            {
                var batchUpdate = CurrentCommand;

                await(PrepareAsync(batchUpdate, cancellationToken)).ConfigureAwait(false);
                Driver.AdjustCommand(batchUpdate);

                _totalExpectedRowsAffected += expectation.ExpectedRowCount;
                string lineWithParameters = null;
                var    sqlStatementLogger = Factory.Settings.SqlStatementLogger;

                if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
                {
                    lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
                    var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
                    lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
                    _currentBatchCommandsLog.Append("command ")
                    .Append(_countOfCommands)
                    .Append(":")
                    .AppendLine(lineWithParameters);
                }
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Adding to batch:{0}", lineWithParameters);
                }

                if (_currentBatch == null)
                {
                    // use first command as the batching command
                    _currentBatch = cloneableCurrentCommand.Clone() as DbCommand;
                }

                _currentBatchCommands.Add(cloneableCurrentCommand.Clone() as DbCommand);

                _countOfCommands++;

                if (_countOfCommands >= _batchSize)
                {
                    await(DoExecuteBatchAsync(batchUpdate, cancellationToken)).ConfigureAwait(false);
                }
            }
        }
        public override void AddToBatch(IExpectation expectation)
        {
            // HanaCommands are cloneable
            if (!(CurrentCommand is ICloneable cloneableCurrentCommand))
            {
                throw new InvalidOperationException("Current command is not an ICloneable");
            }

            var batchUpdate = CurrentCommand;

            Prepare(batchUpdate);
            Driver.AdjustCommand(batchUpdate);

            _totalExpectedRowsAffected += expectation.ExpectedRowCount;
            string lineWithParameters = null;
            var    sqlStatementLogger = Factory.Settings.SqlStatementLogger;

            if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
            {
                lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
                var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
                lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
                _currentBatchCommandsLog.Append("command ")
                .Append(_countOfCommands)
                .Append(":")
                .AppendLine(lineWithParameters);
            }
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Adding to batch:{0}", lineWithParameters);
            }

            if (_currentBatch == null)
            {
                // use first command as the batching command
                _currentBatch = cloneableCurrentCommand.Clone() as DbCommand;
            }

            _currentBatchCommands.Add(cloneableCurrentCommand.Clone() as DbCommand);

            _countOfCommands++;

            if (_countOfCommands >= _batchSize)
            {
                DoExecuteBatch(batchUpdate);
            }
        }
Beispiel #11
0
        public override void AddToBatch(IExpectation expectation)
        {
            this.totalExpectedRowsAffected += expectation.ExpectedRowCount;
            IDbCommand batchUpdate = CurrentCommand;

            Driver.AdjustCommand(batchUpdate);
            string lineWithParameters = null;
            var    sqlStatementLogger = Factory.Settings.SqlStatementLogger;

            if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled)
            {
                lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
                var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
                lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
                this.currentBatchCommandsLog.Append("command ")
                .Append(this.currentBatch.CountOfCommands)
                .Append(":")
                .AppendLine(lineWithParameters);
            }
            if (Log.IsDebugEnabled)
            {
                Log.Debug("Adding to batch:" + lineWithParameters);
            }

            if (batchUpdate is ProfiledSqlCommand)
            {
                var sqlCommand = ((ProfiledSqlCommand)batchUpdate).SqlCommand;
                this.currentBatch.Append(sqlCommand);
                if (this.profiler != null)
                {
                    this.profiler.ExecuteStart(sqlCommand, SqlExecuteType.NonQuery);
                }
            }
            else
            {
                this.currentBatch.Append((System.Data.SqlClient.SqlCommand)batchUpdate);
            }

            if (this.currentBatch.CountOfCommands >= this.batchSize)
            {
                this.ExecuteBatchWithTiming(batchUpdate);
            }
        }
        public override void AddToBatch(IExpectation expectation)
        {
            var batchCommand = CurrentCommand;

            if (_maxNumberOfParameters.HasValue &&
                _currentBatch.CountOfParameters + batchCommand.Parameters.Count > _maxNumberOfParameters)
            {
                ExecuteBatchWithTiming(batchCommand);
            }
            _totalExpectedRowsAffected += expectation.ExpectedRowCount;
            Driver.AdjustCommand(batchCommand);
            LogBatchCommand(batchCommand);
            _currentBatch.Append(batchCommand.Parameters);

            if (_currentBatch.CountOfCommands >= BatchSize)
            {
                ExecuteBatchWithTiming(batchCommand);
            }
        }
Beispiel #13
0
        public override async Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var batchCommand = CurrentCommand;

            if (_maxNumberOfParameters.HasValue &&
                _currentBatch.CountOfParameters + batchCommand.Parameters.Count > _maxNumberOfParameters)
            {
                await(ExecuteBatchWithTimingAsync(batchCommand, cancellationToken)).ConfigureAwait(false);
            }
            _totalExpectedRowsAffected += expectation.ExpectedRowCount;
            Driver.AdjustCommand(batchCommand);
            LogBatchCommand(batchCommand);
            _currentBatch.Append(batchCommand.Parameters);

            if (_currentBatch.CountOfCommands >= BatchSize)
            {
                await(ExecuteBatchWithTimingAsync(batchCommand, cancellationToken)).ConfigureAwait(false);
            }
        }
        public override Task AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <object>(cancellationToken));
            }
            try
            {
                _totalExpectedRowsAffected += expectation.ExpectedRowCount;
                var batchUpdate = CurrentCommand;
                Driver.AdjustCommand(batchUpdate);
                string lineWithParameters = null;
                var    sqlStatementLogger = Factory.Settings.SqlStatementLogger;
                if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
                {
                    lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
                    var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
                    lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
                    _currentBatchCommandsLog.Append("command ")
                    .Append(_currentBatch.CountOfCommands)
                    .Append(":")
                    .AppendLine(lineWithParameters);
                }
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Adding to batch:{0}", lineWithParameters);
                }
                _currentBatch.Append((System.Data.SqlClient.SqlCommand)Driver.UnwrapDbCommand(batchUpdate));

                if (_currentBatch.CountOfCommands >= _batchSize)
                {
                    return(ExecuteBatchWithTimingAsync(batchUpdate, cancellationToken));
                }
                return(Task.CompletedTask);
            }
            catch (Exception ex)
            {
                return(Task.FromException <object>(ex));
            }
        }
Beispiel #15
0
        public override void AddToBatch(IExpectation expectation)
        {
            // MySql batcher cannot be initiated if a data reader is still open: check them.
            if (CountOfStatementsInCurrentBatch == 0)
            {
                CheckReaders();
            }

            totalExpectedRowsAffected += expectation.ExpectedRowCount;
            var batchUpdate = CurrentCommand;

            Prepare(batchUpdate);
            Driver.AdjustCommand(batchUpdate);
            string lineWithParameters = null;
            var    sqlStatementLogger = Factory.Settings.SqlStatementLogger;

            if (sqlStatementLogger.IsDebugEnabled || Log.IsDebugEnabled())
            {
                lineWithParameters = sqlStatementLogger.GetCommandLineWithParameters(batchUpdate);
                var formatStyle = sqlStatementLogger.DetermineActualStyle(FormatStyle.Basic);
                lineWithParameters = formatStyle.Formatter.Format(lineWithParameters);
                currentBatchCommandsLog.Append("command ")
                .Append(currentBatch.CountOfCommands)
                .Append(":")
                .AppendLine(lineWithParameters);
            }
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Adding to batch:{0}", lineWithParameters);
            }
            currentBatch.Append(batchUpdate);

            if (currentBatch.CountOfCommands >= batchSize)
            {
                DoExecuteBatch(batchUpdate);
            }
        }