26
26
import org .hibernate .resource .jdbc .spi .JdbcEventHandler ;
27
27
import org .hibernate .resource .jdbc .spi .JdbcSessionOwner ;
28
28
29
+ import static java .util .Objects .requireNonNull ;
29
30
import static org .hibernate .engine .jdbc .JdbcLogging .JDBC_MESSAGE_LOGGER ;
30
31
import static org .hibernate .engine .jdbc .batch .JdbcBatchLogging .BATCH_LOGGER ;
31
32
import static org .hibernate .engine .jdbc .batch .JdbcBatchLogging .BATCH_MESSAGE_LOGGER ;
@@ -56,21 +57,18 @@ public BatchImpl(
56
57
PreparedStatementGroup statementGroup ,
57
58
int batchSizeToUse ,
58
59
JdbcCoordinator jdbcCoordinator ) {
59
- if ( key == null ) {
60
- throw new IllegalArgumentException ( "Batch key cannot be null" );
61
- }
62
- if ( jdbcCoordinator == null ) {
63
- throw new IllegalArgumentException ( "JDBC coordinator cannot be null" );
64
- }
60
+ requireNonNull ( key , "Batch key cannot be null" );
61
+ requireNonNull ( jdbcCoordinator , "JDBC coordinator cannot be null" );
65
62
66
63
this .batchSizeToUse = batchSizeToUse ;
67
64
this .key = key ;
68
65
this .jdbcCoordinator = jdbcCoordinator ;
69
66
this .statementGroup = statementGroup ;
70
67
71
- final JdbcServices jdbcServices = jdbcCoordinator .getJdbcSessionOwner ().getJdbcSessionContext ().getJdbcServices ();
72
- this .sqlStatementLogger = jdbcServices .getSqlStatementLogger ();
73
- this .sqlExceptionHelper = jdbcServices .getSqlExceptionHelper ();
68
+ final JdbcServices jdbcServices =
69
+ jdbcCoordinator .getJdbcSessionOwner ().getJdbcSessionContext ().getJdbcServices ();
70
+ sqlStatementLogger = jdbcServices .getSqlStatementLogger ();
71
+ sqlExceptionHelper = jdbcServices .getSqlExceptionHelper ();
74
72
75
73
if ( BATCH_LOGGER .isTraceEnabled () ) {
76
74
BATCH_MESSAGE_LOGGER .createBatch (
@@ -134,7 +132,8 @@ public void addToBatch(JdbcValueBindings jdbcValueBindings, TableInclusionChecke
134
132
else {
135
133
//noinspection resource
136
134
final PreparedStatement statement = statementDetails .resolveStatement ();
137
- sqlStatementLogger .logStatement ( statementDetails .getSqlString () );
135
+ final String sqlString = statementDetails .getSqlString ();
136
+ sqlStatementLogger .logStatement ( sqlString );
138
137
jdbcValueBindings .beforeStatement ( statementDetails );
139
138
try {
140
139
statement .addBatch ();
@@ -144,7 +143,7 @@ public void addToBatch(JdbcValueBindings jdbcValueBindings, TableInclusionChecke
144
143
throw sqlExceptionHelper .convert (
145
144
e ,
146
145
"Could not perform addBatch" ,
147
- statementDetails . getSqlString ()
146
+ sqlString
148
147
);
149
148
}
150
149
finally {
@@ -303,10 +302,11 @@ private void checkRowCounts(int[] rowCounts, PreparedStatementDetails statementD
303
302
);
304
303
}
305
304
305
+ final String sql = statementDetails .getSqlString ();
306
306
for ( int i = 0 ; i < numberOfRowCounts ; i ++ ) {
307
307
try {
308
308
statementDetails .getExpectation ()
309
- .verifyOutcome ( rowCounts [i ], statementDetails .getStatement (), i , statementDetails . getSqlString () );
309
+ .verifyOutcome ( rowCounts [i ], statementDetails .getStatement (), i , sql );
310
310
}
311
311
catch ( StaleStateException staleStateException ) {
312
312
if ( staleStateMappers != null ) {
0 commit comments