24
24
import java .sql .PreparedStatement ;
25
25
import java .sql .ResultSet ;
26
26
import java .sql .SQLException ;
27
+ import java .sql .Types ;
27
28
import java .util .Collection ;
28
29
import java .util .HashMap ;
29
30
import java .util .Iterator ;
43
44
import org .springframework .core .serializer .Serializer ;
44
45
import org .springframework .jdbc .core .BatchPreparedStatementSetter ;
45
46
import org .springframework .jdbc .core .RowMapper ;
47
+ import org .springframework .jdbc .core .simple .JdbcClient ;
46
48
import org .springframework .lang .NonNull ;
47
49
import org .springframework .util .Assert ;
48
50
@@ -65,7 +67,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
65
67
private static final String FIND_JOB_EXECUTION_CONTEXT = """
66
68
SELECT SHORT_CONTEXT, SERIALIZED_CONTEXT
67
69
FROM %PREFIX%JOB_EXECUTION_CONTEXT
68
- WHERE JOB_EXECUTION_ID = ?
70
+ WHERE JOB_EXECUTION_ID = :executionId
69
71
""" ;
70
72
71
73
private static final String INSERT_JOB_EXECUTION_CONTEXT = """
@@ -82,7 +84,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
82
84
private static final String FIND_STEP_EXECUTION_CONTEXT = """
83
85
SELECT SHORT_CONTEXT, SERIALIZED_CONTEXT
84
86
FROM %PREFIX%STEP_EXECUTION_CONTEXT
85
- WHERE STEP_EXECUTION_ID = ?
87
+ WHERE STEP_EXECUTION_ID = :executionId
86
88
""" ;
87
89
88
90
private static final String INSERT_STEP_EXECUTION_CONTEXT = """
@@ -98,12 +100,12 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
98
100
99
101
private static final String DELETE_STEP_EXECUTION_CONTEXT = """
100
102
DELETE FROM %PREFIX%STEP_EXECUTION_CONTEXT
101
- WHERE STEP_EXECUTION_ID = ?
103
+ WHERE STEP_EXECUTION_ID = :executionId
102
104
""" ;
103
105
104
106
private static final String DELETE_JOB_EXECUTION_CONTEXT = """
105
107
DELETE FROM %PREFIX%JOB_EXECUTION_CONTEXT
106
- WHERE JOB_EXECUTION_ID = ?
108
+ WHERE JOB_EXECUTION_ID = :executionId
107
109
""" ;
108
110
109
111
private Charset charset = StandardCharsets .UTF_8 ;
@@ -154,8 +156,10 @@ public ExecutionContext getExecutionContext(JobExecution jobExecution) {
154
156
Long executionId = jobExecution .getId ();
155
157
Assert .notNull (executionId , "ExecutionId must not be null." );
156
158
157
- try (Stream <ExecutionContext > stream = getJdbcTemplate ().queryForStream (getQuery (FIND_JOB_EXECUTION_CONTEXT ),
158
- new ExecutionContextRowMapper (), executionId )) {
159
+ try (Stream <ExecutionContext > stream = getJdbcClient ().sql (getQuery (FIND_JOB_EXECUTION_CONTEXT ))
160
+ .param ("executionId" , executionId )
161
+ .query (new ExecutionContextRowMapper ())
162
+ .stream ()) {
159
163
return stream .findFirst ().orElseGet (ExecutionContext ::new );
160
164
}
161
165
}
@@ -165,8 +169,10 @@ public ExecutionContext getExecutionContext(StepExecution stepExecution) {
165
169
Long executionId = stepExecution .getId ();
166
170
Assert .notNull (executionId , "ExecutionId must not be null." );
167
171
168
- try (Stream <ExecutionContext > stream = getJdbcTemplate ().queryForStream (getQuery (FIND_STEP_EXECUTION_CONTEXT ),
169
- new ExecutionContextRowMapper (), executionId )) {
172
+ try (Stream <ExecutionContext > stream = getJdbcClient ().sql (getQuery (FIND_STEP_EXECUTION_CONTEXT ))
173
+ .param ("executionId" , executionId )
174
+ .query (new ExecutionContextRowMapper ())
175
+ .stream ()) {
170
176
return stream .findFirst ().orElseGet (ExecutionContext ::new );
171
177
}
172
178
}
@@ -248,7 +254,7 @@ public void saveExecutionContexts(Collection<StepExecution> stepExecutions) {
248
254
*/
249
255
@ Override
250
256
public void deleteExecutionContext (JobExecution jobExecution ) {
251
- getJdbcTemplate ().update (getQuery (DELETE_JOB_EXECUTION_CONTEXT ), jobExecution .getId ());
257
+ getJdbcClient ().sql (getQuery (DELETE_JOB_EXECUTION_CONTEXT )). param ( "executionId" , jobExecution .getId ()). update ( );
252
258
}
253
259
254
260
/**
@@ -257,7 +263,9 @@ public void deleteExecutionContext(JobExecution jobExecution) {
257
263
*/
258
264
@ Override
259
265
public void deleteExecutionContext (StepExecution stepExecution ) {
260
- getJdbcTemplate ().update (getQuery (DELETE_STEP_EXECUTION_CONTEXT ), stepExecution .getId ());
266
+ getJdbcClient ().sql (getQuery (DELETE_STEP_EXECUTION_CONTEXT ))
267
+ .param ("executionId" , stepExecution .getId ())
268
+ .update ();
261
269
}
262
270
263
271
@ Override
@@ -286,16 +294,13 @@ private void persistSerializedContext(final Long executionId, String serializedC
286
294
longContext = null ;
287
295
}
288
296
289
- getJdbcTemplate ().update (getQuery (sql ), ps -> {
290
- ps .setString (1 , shortContext );
291
- if (longContext != null ) {
292
- ps .setString (2 , longContext );
293
- }
294
- else {
295
- ps .setNull (2 , getClobTypeToUse ());
296
- }
297
- ps .setLong (3 , executionId );
298
- });
297
+ getJdbcClient ().sql (getQuery (sql ))
298
+ // @formatter:off
299
+ .param (1 , shortContext , Types .VARCHAR )
300
+ .param (2 , longContext , getClobTypeToUse ())
301
+ .param (3 , executionId , Types .BIGINT )
302
+ // @formatter:on
303
+ .update ();
299
304
}
300
305
301
306
/**
0 commit comments