2424import java .sql .PreparedStatement ;
2525import java .sql .ResultSet ;
2626import java .sql .SQLException ;
27+ import java .sql .Types ;
2728import java .util .Collection ;
2829import java .util .HashMap ;
2930import java .util .Iterator ;
30- import java .util .List ;
3131import java .util .Map ;
3232import java .util .Map .Entry ;
3333import java .util .concurrent .locks .Lock ;
@@ -65,7 +65,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
6565 private static final String FIND_JOB_EXECUTION_CONTEXT = """
6666 SELECT SHORT_CONTEXT, SERIALIZED_CONTEXT
6767 FROM %PREFIX%JOB_EXECUTION_CONTEXT
68- WHERE JOB_EXECUTION_ID = ?
68+ WHERE JOB_EXECUTION_ID = :jobExecutionId
6969 """ ;
7070
7171 private static final String INSERT_JOB_EXECUTION_CONTEXT = """
@@ -82,7 +82,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
8282 private static final String FIND_STEP_EXECUTION_CONTEXT = """
8383 SELECT SHORT_CONTEXT, SERIALIZED_CONTEXT
8484 FROM %PREFIX%STEP_EXECUTION_CONTEXT
85- WHERE STEP_EXECUTION_ID = ?
85+ WHERE STEP_EXECUTION_ID = :stepExecutionId
8686 """ ;
8787
8888 private static final String INSERT_STEP_EXECUTION_CONTEXT = """
@@ -98,12 +98,12 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
9898
9999 private static final String DELETE_STEP_EXECUTION_CONTEXT = """
100100 DELETE FROM %PREFIX%STEP_EXECUTION_CONTEXT
101- WHERE STEP_EXECUTION_ID = ?
101+ WHERE STEP_EXECUTION_ID = :stepExecutionId
102102 """ ;
103103
104104 private static final String DELETE_JOB_EXECUTION_CONTEXT = """
105105 DELETE FROM %PREFIX%JOB_EXECUTION_CONTEXT
106- WHERE JOB_EXECUTION_ID = ?
106+ WHERE JOB_EXECUTION_ID = :jobExecutionId
107107 """ ;
108108
109109 private Charset charset = StandardCharsets .UTF_8 ;
@@ -154,29 +154,24 @@ public ExecutionContext getExecutionContext(JobExecution jobExecution) {
154154 Long executionId = jobExecution .getId ();
155155 Assert .notNull (executionId , "ExecutionId must not be null." );
156156
157- List <ExecutionContext > results = getJdbcTemplate ().query (getQuery (FIND_JOB_EXECUTION_CONTEXT ),
158- new ExecutionContextRowMapper (), executionId );
159- if (!results .isEmpty ()) {
160- return results .get (0 );
161- }
162- else {
163- return new ExecutionContext ();
164- }
157+ return getJdbcClient ().sql (getQuery (FIND_JOB_EXECUTION_CONTEXT ))
158+ .param ("jobExecutionId" , executionId )
159+ .query (new ExecutionContextRowMapper ())
160+ .optional ()
161+ .orElseGet (ExecutionContext ::new );
162+
165163 }
166164
167165 @ Override
168166 public ExecutionContext getExecutionContext (StepExecution stepExecution ) {
169167 Long executionId = stepExecution .getId ();
170168 Assert .notNull (executionId , "ExecutionId must not be null." );
171169
172- List <ExecutionContext > results = getJdbcTemplate ().query (getQuery (FIND_STEP_EXECUTION_CONTEXT ),
173- new ExecutionContextRowMapper (), executionId );
174- if (results .size () > 0 ) {
175- return results .get (0 );
176- }
177- else {
178- return new ExecutionContext ();
179- }
170+ return getJdbcClient ().sql (getQuery (FIND_STEP_EXECUTION_CONTEXT ))
171+ .param ("stepExecutionId" , executionId )
172+ .query (new ExecutionContextRowMapper ())
173+ .optional ()
174+ .orElseGet (ExecutionContext ::new );
180175 }
181176
182177 @ Override
@@ -256,7 +251,9 @@ public void saveExecutionContexts(Collection<StepExecution> stepExecutions) {
256251 */
257252 @ Override
258253 public void deleteExecutionContext (JobExecution jobExecution ) {
259- getJdbcTemplate ().update (getQuery (DELETE_JOB_EXECUTION_CONTEXT ), jobExecution .getId ());
254+ getJdbcClient ().sql (getQuery (DELETE_JOB_EXECUTION_CONTEXT ))
255+ .param ("jobExecutionId" , jobExecution .getId ())
256+ .update ();
260257 }
261258
262259 /**
@@ -265,7 +262,9 @@ public void deleteExecutionContext(JobExecution jobExecution) {
265262 */
266263 @ Override
267264 public void deleteExecutionContext (StepExecution stepExecution ) {
268- getJdbcTemplate ().update (getQuery (DELETE_STEP_EXECUTION_CONTEXT ), stepExecution .getId ());
265+ getJdbcClient ().sql (getQuery (DELETE_STEP_EXECUTION_CONTEXT ))
266+ .param ("stepExecutionId" , stepExecution .getId ())
267+ .update ();
269268 }
270269
271270 @ Override
@@ -294,16 +293,13 @@ private void persistSerializedContext(Long executionId, String serializedContext
294293 longContext = null ;
295294 }
296295
297- getJdbcTemplate ().update (getQuery (sql ), ps -> {
298- ps .setString (1 , shortContext );
299- if (longContext != null ) {
300- ps .setString (2 , longContext );
301- }
302- else {
303- ps .setNull (2 , getClobTypeToUse ());
304- }
305- ps .setLong (3 , executionId );
306- });
296+ getJdbcClient ().sql (getQuery (sql ))
297+ // @formatter:off
298+ .param (1 , shortContext , Types .VARCHAR )
299+ .param (2 , longContext , getClobTypeToUse ())
300+ .param (3 , executionId , Types .BIGINT )
301+ // @formatter:on
302+ .update ();
307303 }
308304
309305 /**
0 commit comments