2727import java .util .Collection ;
2828import java .util .HashMap ;
2929import java .util .Iterator ;
30- import java .util .List ;
3130import java .util .Map ;
3231import java .util .Map .Entry ;
3332import java .util .concurrent .locks .Lock ;
@@ -65,7 +64,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
6564 private static final String FIND_JOB_EXECUTION_CONTEXT = """
6665 SELECT SHORT_CONTEXT, SERIALIZED_CONTEXT
6766 FROM %PREFIX%JOB_EXECUTION_CONTEXT
68- WHERE JOB_EXECUTION_ID = ?
67+ WHERE JOB_EXECUTION_ID = :jobExecutionId
6968 """ ;
7069
7170 private static final String INSERT_JOB_EXECUTION_CONTEXT = """
@@ -82,7 +81,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
8281 private static final String FIND_STEP_EXECUTION_CONTEXT = """
8382 SELECT SHORT_CONTEXT, SERIALIZED_CONTEXT
8483 FROM %PREFIX%STEP_EXECUTION_CONTEXT
85- WHERE STEP_EXECUTION_ID = ?
84+ WHERE STEP_EXECUTION_ID = :stepExecutionId
8685 """ ;
8786
8887 private static final String INSERT_STEP_EXECUTION_CONTEXT = """
@@ -98,12 +97,12 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
9897
9998 private static final String DELETE_STEP_EXECUTION_CONTEXT = """
10099 DELETE FROM %PREFIX%STEP_EXECUTION_CONTEXT
101- WHERE STEP_EXECUTION_ID = ?
100+ WHERE STEP_EXECUTION_ID = :stepExecutionId
102101 """ ;
103102
104103 private static final String DELETE_JOB_EXECUTION_CONTEXT = """
105104 DELETE FROM %PREFIX%JOB_EXECUTION_CONTEXT
106- WHERE JOB_EXECUTION_ID = ?
105+ WHERE JOB_EXECUTION_ID = :jobExecutionId
107106 """ ;
108107
109108 private Charset charset = StandardCharsets .UTF_8 ;
@@ -154,29 +153,24 @@ public ExecutionContext getExecutionContext(JobExecution jobExecution) {
154153 Long executionId = jobExecution .getId ();
155154 Assert .notNull (executionId , "ExecutionId must not be null." );
156155
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- }
156+ return getJdbcClient ().sql (getQuery (FIND_JOB_EXECUTION_CONTEXT ))
157+ .param ("jobExecutionId" , executionId )
158+ .query (new ExecutionContextRowMapper ())
159+ .optional ()
160+ .orElseGet (ExecutionContext ::new );
161+
165162 }
166163
167164 @ Override
168165 public ExecutionContext getExecutionContext (StepExecution stepExecution ) {
169166 Long executionId = stepExecution .getId ();
170167 Assert .notNull (executionId , "ExecutionId must not be null." );
171168
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- }
169+ return getJdbcClient ().sql (getQuery (FIND_STEP_EXECUTION_CONTEXT ))
170+ .param ("stepExecutionId" , executionId )
171+ .query (new ExecutionContextRowMapper ())
172+ .optional ()
173+ .orElseGet (ExecutionContext ::new );
180174 }
181175
182176 @ Override
@@ -256,7 +250,9 @@ public void saveExecutionContexts(Collection<StepExecution> stepExecutions) {
256250 */
257251 @ Override
258252 public void deleteExecutionContext (JobExecution jobExecution ) {
259- getJdbcTemplate ().update (getQuery (DELETE_JOB_EXECUTION_CONTEXT ), jobExecution .getId ());
253+ getJdbcClient ().sql (getQuery (DELETE_JOB_EXECUTION_CONTEXT ))
254+ .param ("jobExecutionId" , jobExecution .getId ())
255+ .update ();
260256 }
261257
262258 /**
@@ -265,7 +261,9 @@ public void deleteExecutionContext(JobExecution jobExecution) {
265261 */
266262 @ Override
267263 public void deleteExecutionContext (StepExecution stepExecution ) {
268- getJdbcTemplate ().update (getQuery (DELETE_STEP_EXECUTION_CONTEXT ), stepExecution .getId ());
264+ getJdbcClient ().sql (getQuery (DELETE_STEP_EXECUTION_CONTEXT ))
265+ .param ("stepExecutionId" , stepExecution .getId ())
266+ .update ();
269267 }
270268
271269 @ Override
@@ -294,16 +292,13 @@ private void persistSerializedContext(Long executionId, String serializedContext
294292 longContext = null ;
295293 }
296294
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- });
295+ getJdbcClient ().sql (getQuery (sql ))
296+ // @formatter:off
297+ .param (1 , shortContext )
298+ .param (2 , longContext , getClobTypeToUse ())
299+ .param (3 , executionId )
300+ // @formatter:on
301+ .update ();
307302 }
308303
309304 /**
0 commit comments