@@ -25,12 +25,11 @@ public partial class GenericBatchingBatcher : AbstractBatcher
25
25
private int _totalExpectedRowsAffected ;
26
26
private StringBuilder _currentBatchCommandsLog ;
27
27
28
- public GenericBatchingBatcher ( ConnectionManager connectionManager , IInterceptor interceptor , char statementTerminator )
28
+ public GenericBatchingBatcher ( ConnectionManager connectionManager , IInterceptor interceptor )
29
29
: base ( connectionManager , interceptor )
30
30
{
31
31
BatchSize = Factory . Settings . AdoBatchSize ;
32
- StatementTerminator = statementTerminator ;
33
- _currentBatch = new BatchingCommandSet ( this ) ;
32
+ _currentBatch = new BatchingCommandSet ( this , Factory . Dialect . StatementTerminator ) ;
34
33
_maxNumberOfParameters = Factory . Dialect . MaxNumberOfParameters ;
35
34
36
35
// We always create this, because we need to deal with a scenario in which
@@ -40,44 +39,26 @@ public GenericBatchingBatcher(ConnectionManager connectionManager, IInterceptor
40
39
_currentBatchCommandsLog = new StringBuilder ( ) . AppendLine ( "Batch commands:" ) ;
41
40
}
42
41
43
- public char StatementTerminator { get ; }
44
-
45
42
public sealed override int BatchSize { get ; set ; }
46
43
47
44
protected override int CountOfStatementsInCurrentBatch => _currentBatch . CountOfCommands ;
48
45
49
46
public override void AddToBatch ( IExpectation expectation )
50
47
{
51
- var batchUpdate = CurrentCommand ;
48
+ var batchCommand = CurrentCommand ;
52
49
if ( _maxNumberOfParameters . HasValue &&
53
- _currentBatch . CountOfParameters + CurrentCommand . Parameters . Count > _maxNumberOfParameters )
50
+ _currentBatch . CountOfParameters + batchCommand . Parameters . Count > _maxNumberOfParameters )
54
51
{
55
- ExecuteBatchWithTiming ( batchUpdate ) ;
52
+ ExecuteBatchWithTiming ( batchCommand ) ;
56
53
}
57
54
_totalExpectedRowsAffected += expectation . ExpectedRowCount ;
58
- Driver . AdjustCommand ( batchUpdate ) ;
59
- string lineWithParameters = null ;
60
- var sqlStatementLogger = Factory . Settings . SqlStatementLogger ;
61
- if ( sqlStatementLogger . IsDebugEnabled || Log . IsDebugEnabled ( ) )
62
- {
63
- lineWithParameters = sqlStatementLogger . GetCommandLineWithParameters ( batchUpdate ) ;
64
- var formatStyle = sqlStatementLogger . DetermineActualStyle ( FormatStyle . Basic ) ;
65
- lineWithParameters = formatStyle . Formatter . Format ( lineWithParameters ) ;
66
- _currentBatchCommandsLog . Append ( "command " )
67
- . Append ( _currentBatch . CountOfCommands )
68
- . Append ( ":" )
69
- . AppendLine ( lineWithParameters ) ;
70
- }
71
- if ( Log . IsDebugEnabled ( ) )
72
- {
73
- Log . Debug ( "Adding to batch:{0}" , lineWithParameters ) ;
74
- }
75
-
76
- _currentBatch . Append ( CurrentCommand . Parameters ) ;
55
+ Driver . AdjustCommand ( batchCommand ) ;
56
+ LogBatchCommand ( batchCommand ) ;
57
+ _currentBatch . Append ( batchCommand . Parameters ) ;
77
58
78
59
if ( _currentBatch . CountOfCommands >= BatchSize )
79
60
{
80
- ExecuteBatchWithTiming ( batchUpdate ) ;
61
+ ExecuteBatchWithTiming ( batchCommand ) ;
81
62
}
82
63
}
83
64
@@ -115,6 +96,26 @@ protected override void DoExecuteBatch(DbCommand ps)
115
96
}
116
97
}
117
98
99
+ private void LogBatchCommand ( DbCommand batchCommand )
100
+ {
101
+ string lineWithParameters = null ;
102
+ var sqlStatementLogger = Factory . Settings . SqlStatementLogger ;
103
+ if ( sqlStatementLogger . IsDebugEnabled || Log . IsDebugEnabled ( ) )
104
+ {
105
+ lineWithParameters = sqlStatementLogger . GetCommandLineWithParameters ( batchCommand ) ;
106
+ var formatStyle = sqlStatementLogger . DetermineActualStyle ( FormatStyle . Basic ) ;
107
+ lineWithParameters = formatStyle . Formatter . Format ( lineWithParameters ) ;
108
+ _currentBatchCommandsLog . Append ( "command " )
109
+ . Append ( _currentBatch . CountOfCommands )
110
+ . Append ( ":" )
111
+ . AppendLine ( lineWithParameters ) ;
112
+ }
113
+ if ( Log . IsDebugEnabled ( ) )
114
+ {
115
+ Log . Debug ( "Adding to batch:{0}" , lineWithParameters ) ;
116
+ }
117
+ }
118
+
118
119
private void ClearCurrentBatch ( )
119
120
{
120
121
_currentBatch . Clear ( ) ;
@@ -140,6 +141,7 @@ protected override void Dispose(bool isDisposing)
140
141
141
142
private partial class BatchingCommandSet
142
143
{
144
+ private readonly string _statementTerminator ;
143
145
private readonly GenericBatchingBatcher _batcher ;
144
146
private readonly SqlStringBuilder _sql = new SqlStringBuilder ( ) ;
145
147
private readonly List < SqlTypes . SqlType > _sqlTypes = new List < SqlTypes . SqlType > ( ) ;
@@ -159,9 +161,10 @@ private class BatchParameter
159
161
public object Value { get ; set ; }
160
162
}
161
163
162
- public BatchingCommandSet ( GenericBatchingBatcher batcher )
164
+ public BatchingCommandSet ( GenericBatchingBatcher batcher , char statementTerminator )
163
165
{
164
166
_batcher = batcher ;
167
+ _statementTerminator = statementTerminator . ToString ( ) ;
165
168
}
166
169
167
170
public int CountOfCommands { get ; private set ; }
@@ -172,7 +175,7 @@ public void Append(DbParameterCollection parameters)
172
175
{
173
176
if ( CountOfCommands > 0 )
174
177
{
175
- _sql . Add ( _batcher . StatementTerminator . ToString ( ) ) ;
178
+ _sql . Add ( _statementTerminator ) ;
176
179
}
177
180
else
178
181
{
0 commit comments