Example #1
0
        protected override void DoExecuteBatch(IDbCommand ps)
        {
            Log.DebugFormat("Executing batch");
            CheckReaders();
            if (Factory.Settings.SqlStatementLogger.IsDebugEnabled)
            {
                Factory.Settings.SqlStatementLogger.LogBatchCommand(currentBatchCommandsLog.ToString());
                currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
            }

            int rowsAffected;

            try {
                rowsAffected = currentBatch.ExecuteNonQuery();
            }
            catch (DbException e) {
                throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command.");
            }

            Expectations.VerifyOutcomeBatched(totalExpectedRowsAffected, rowsAffected);

            currentBatch.Dispose();
            totalExpectedRowsAffected = 0;
            currentBatch = CreateConfiguredBatch();
        }
Example #2
0
        /// <inheritdoc />
        protected override async Task DoExecuteBatchAsync(DbCommand ps, CancellationToken cancellationToken)
        {
            try
            {
                if (mCurrentEntites.Any())
                {
                    Prepare(ps);
#if DEBUG
                    Debug.WriteLine($"Начата обработка {mCurrentEntites.Count} записей.");
                    var sw = Stopwatch.StartNew();
#endif
                    var result = await mBulkMerger.MergeAsync(mCurrentEntites, Driver, ps.Connection, ps.Transaction, cancellationToken);

#if DEBUG
                    sw.Stop();
                    Debug.WriteLine($"Обработка {mCurrentEntites.Count} записей завершена. Прошло {sw.ElapsedMilliseconds} мс.");
#endif
                    Expectations.VerifyOutcomeBatched(mCurrentEntites.Count, result, ps);
                }
            }
            finally
            {
                mCurrentEntites.Clear();
            }
        }
Example #3
0
        // Need this method call in this class rather than the base class to ensure Prepare is called... if only it was virtual :(
        protected void ExecuteBatch(IDbCommand ps)
        {
            #region NHibernate code
            Log.Debug("Executing batch");
            CheckReaders();
            Prepare(_currentBatch.BatchCommand);
            if (Factory.Settings.SqlStatementLogger.IsDebugEnabled)
            {
                Factory.Settings.SqlStatementLogger.LogBatchCommand(_currentBatchCommandsLog.ToString());
                _currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
            }

            int rowsAffected;
            try
            {
                rowsAffected = _currentBatch.ExecuteNonQuery();
            }
            catch (DbException e)
            {
                throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command.");
            }

            Expectations.VerifyOutcomeBatched(_totalExpectedRowsAffected, rowsAffected);

            _currentBatch.Dispose();
            _totalExpectedRowsAffected = 0;
            _currentBatch = CreateConfiguredBatch();
            #endregion
        }
        protected override void DoExecuteBatch(IDbCommand ps)
        {
            CheckReaders();
            Prepare(_currentBatch.BatchCommand);
            if (Factory.Settings.SqlStatementLogger.IsDebugEnabled)
            {
                Factory.Settings.SqlStatementLogger.LogBatchCommand(_currentBatchCommandsLog.ToString());
                _currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
            }

            int rowsAffected;

            try
            {
                var dbProfiler = ((IDbProfiler)MiniProfiler.Current);
                if (MiniProfiler.Current == null)
                {
                    rowsAffected = _currentBatch.ExecuteNonQuery();
                }
                else
                {
                    dbProfiler.ExecuteStart(_currentBatch.BatchCommand, SqlExecuteType.NonQuery);
                    try
                    {
                        rowsAffected = _currentBatch.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        dbProfiler.OnError(_currentBatch.BatchCommand, SqlExecuteType.NonQuery, ex);
                        throw;
                    }
                    finally
                    {
                        dbProfiler.ExecuteFinish(_currentBatch.BatchCommand, SqlExecuteType.NonQuery, (DbDataReader)null);
                    }
                }
            }
            catch (DbException e)
            {
                throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command.");
            }

            Expectations.VerifyOutcomeBatched(_totalExpectedRowsAffected, rowsAffected);

            _currentBatch.Dispose();
            _totalExpectedRowsAffected = 0;
            _currentBatch = CreateConfiguredBatch();
        }
Example #5
0
        protected override void DoExecuteBatch(DbCommand ps)
        {
            if (_currentBatch != null)
            {
                int arraySize = 0;
                _countOfCommands = 0;

                Log.Info("Executing batch");
                CheckReaders();
                Prepare(_currentBatch);

                if (Factory.Settings.SqlStatementLogger.IsDebugEnabled)
                {
                    Factory.Settings.SqlStatementLogger.LogBatchCommand(_currentBatchCommandsLog.ToString());
                    _currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
                }

                foreach (OracleParameter currentParameter in _currentBatch.Parameters)
                {
                    var parameterValueArray = _parameterValueListHashTable[currentParameter.ParameterName];
                    currentParameter.Value = parameterValueArray.ToArray();
                    arraySize = parameterValueArray.Count;
                }

                _currentBatch.ArrayBindCount = arraySize;
                int rowsAffected;
                try
                {
                    rowsAffected = _currentBatch.ExecuteNonQuery();
                }
                catch (DbException e)
                {
                    throw ADOExceptionHelper.Convert(Factory.SQLExceptionConverter, e, "could not execute batch command.");
                }

                Expectations.VerifyOutcomeBatched(_totalExpectedRowsAffected, rowsAffected);

                _totalExpectedRowsAffected = 0;
                _currentBatch = null;
                _parameterValueListHashTable = null;
            }
        }