Enhance switch statements

Issue #4365
This commit is contained in:
Minsoo Kim
2023-05-03 14:05:03 +09:00
committed by Mahmoud Ben Hassine
parent 7460c5f9a1
commit 4a971a0764
5 changed files with 53 additions and 119 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -169,6 +169,7 @@ import org.springframework.util.StringUtils;
* @author Dave Syer
* @author Lucas Ward
* @author Mahmoud Ben Hassine
* @author Minsoo Kim
* @since 1.0
*/
public class CommandLineJobRunner {
@@ -538,15 +539,9 @@ public class CommandLineJobRunner {
}
else {
switch (count) {
case 0:
jobPath = arg;
break;
case 1:
jobIdentifier = arg;
break;
default:
params.add(arg);
break;
case 0 -> jobPath = arg;
case 1 -> jobIdentifier = arg;
default -> params.add(arg);
}
count++;
}

View File

@@ -62,6 +62,7 @@ import org.springframework.util.Assert;
* @author David Turanski
* @author Mahmoud Ben Hassine
* @author Baris Cubukcuoglu
* @author Minsoo Kim
* @see StepExecutionDao
*/
public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implements StepExecutionDao, InitializingBean {
@@ -183,21 +184,12 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
Integer[] parameterTypes = (Integer[]) parameters.get(1);
for (int indx = 0; indx < parameterValues.length; indx++) {
switch (parameterTypes[indx]) {
case Types.INTEGER:
ps.setInt(indx + 1, (Integer) parameterValues[indx]);
break;
case Types.VARCHAR:
ps.setString(indx + 1, (String) parameterValues[indx]);
break;
case Types.TIMESTAMP:
ps.setTimestamp(indx + 1, (Timestamp) parameterValues[indx]);
break;
case Types.BIGINT:
ps.setLong(indx + 1, (Long) parameterValues[indx]);
break;
default:
throw new IllegalArgumentException(
"unsupported SQL parameter type for step execution field index " + i);
case Types.INTEGER -> ps.setInt(indx + 1, (Integer) parameterValues[indx]);
case Types.VARCHAR -> ps.setString(indx + 1, (String) parameterValues[indx]);
case Types.TIMESTAMP -> ps.setTimestamp(indx + 1, (Timestamp) parameterValues[indx]);
case Types.BIGINT -> ps.setLong(indx + 1, (Long) parameterValues[indx]);
default -> throw new IllegalArgumentException(
"unsupported SQL parameter type for step execution field index " + i);
}
}
}