protected override void DoExecuteBatch(IDbCommand ps)
        {
            CheckReaders();
            ProfiledPrepare(_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();
        }
Exemple #2
0
        public ProfiledSqlClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor) : base(connectionManager, interceptor)
        {
            _batchSize      = Factory.Settings.AdoBatchSize;
            _defaultTimeout = PropertiesHelper.GetInt32(global::NHibernate.Cfg.Environment.CommandTimeout, global::NHibernate.Cfg.Environment.Properties, -1);

            _currentBatch            = CreateConfiguredBatch();
            _currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
        }
            public ProfiledSqlClientBatchingBatcher(ConnectionManager connectionManager, IInterceptor interceptor)
                : base(connectionManager, interceptor)
            {
                batchSize      = Factory.Settings.AdoBatchSize;
                defaultTimeout = PropertiesHelper.GetInt32(global::NHibernate.Cfg.Environment.CommandTimeout, global::NHibernate.Cfg.Environment.Properties, -1);

                currentBatch = CreateConfiguredBatch();
                //we always create this, because we need to deal with a scenario in which
                //the user change the logging configuration at runtime. Trying to put this
                //behind an if(log.IsDebugEnabled) will cause a null reference exception
                //at that point.
                currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
            }
        private SqlClientSqlCommandSet CreateConfiguredBatch()
        {
            var result = new SqlClientSqlCommandSet();

            if (_defaultTimeout > 0)
            {
                try
                {
                    result.CommandTimeout = _defaultTimeout;
                }
                catch { }
            }

            return(result);
        }
            private SqlClientSqlCommandSet CreateConfiguredBatch()
            {
                var result = new SqlClientSqlCommandSet();

                if (defaultTimeout > 0)
                {
                    try
                    {
                        result.CommandTimeout = defaultTimeout;
                    }
                    catch (Exception e)
                    {
                        if (Log.IsWarnEnabled)
                        {
                            Log.Warn(e.ToString());
                        }
                    }
                }
                return(result);
            }
Exemple #6
0
        protected override void DoExecuteBatch(IDbCommand ps)
        {
            Log.DebugFormat("Executing batch");
            this.CheckReaders();
            this.Prepare(this.currentBatch.BatchCommand);
            if (Factory.Settings.SqlStatementLogger.IsDebugEnabled)
            {
                Factory.Settings.SqlStatementLogger.LogBatchCommand(this.currentBatchCommandsLog.ToString());
                this.currentBatchCommandsLog = new StringBuilder().AppendLine("Batch commands:");
            }

            if (this.profiler != null)
            {
                this.profiler.ExecuteStart(this.currentBatch.BatchCommand, SqlExecuteType.NonQuery);
            }

            int rowsAffected;

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

            if (this.profiler != null)
            {
                this.profiler.ExecuteFinish(this.currentBatch.BatchCommand, SqlExecuteType.NonQuery, null);
            }

            Expectations.VerifyOutcomeBatched(this.totalExpectedRowsAffected, rowsAffected);

            this.currentBatch.Dispose();
            this.totalExpectedRowsAffected = 0;
            this.currentBatch = this.CreateConfiguredBatch();
        }