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:"); }
private SqlClientSqlProperBatchingCommandSet CreateConfiguredBatch() { var result = new SqlClientSqlProperBatchingCommandSet(); if (_defaultTimeout > 0) { try { result.CommandTimeout = _defaultTimeout; } catch { } } return(result); }
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(); }
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(); }
private SqlClientSqlProperBatchingCommandSet CreateConfiguredBatch() { var result = new SqlClientSqlProperBatchingCommandSet(); if (_defaultTimeout > 0) { try { result.CommandTimeout = _defaultTimeout; } catch { } } return result; }