Skip to content

Enhance switch statements #4365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -169,6 +169,7 @@
* @author Dave Syer
* @author Lucas Ward
* @author Mahmoud Ben Hassine
* @author Minsoo Kim
* @since 1.0
*/
public class CommandLineJobRunner {
Expand Down Expand Up @@ -538,15 +539,9 @@ public static void main(String[] args) throws Exception {
}
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++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
* @author David Turanski
* @author Mahmoud Ben Hassine
* @author Baris Cubukcuoglu
* @author Minsoo Kim
* @see StepExecutionDao
*/
public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implements StepExecutionDao, InitializingBean {
Expand Down Expand Up @@ -182,23 +183,14 @@ public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] parameterValues = parameters.get(0);
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);
}
switch (parameterTypes[indx]) {
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);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 the original author or authors.
* Copyright 2017-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.
Expand Down Expand Up @@ -51,6 +51,7 @@
* @author Glenn Renfro
* @author Drummond Dawson
* @author Mahmoud Ben Hassine
* @author Minsoo Kim
* @since 4.0
* @see JdbcPagingItemReader
*/
Expand Down Expand Up @@ -334,53 +335,22 @@ private PagingQueryProvider determineQueryProvider(DataSource dataSource) {
try {
DatabaseType databaseType = DatabaseType.fromMetaData(dataSource);

AbstractSqlPagingQueryProvider provider;

switch (databaseType) {

case DERBY:
provider = new DerbyPagingQueryProvider();
break;
case DB2:
case DB2VSE:
case DB2ZOS:
case DB2AS400:
provider = new Db2PagingQueryProvider();
break;
case H2:
provider = new H2PagingQueryProvider();
break;
case HANA:
provider = new HanaPagingQueryProvider();
break;
case HSQL:
provider = new HsqlPagingQueryProvider();
break;
case SQLSERVER:
provider = new SqlServerPagingQueryProvider();
break;
case MYSQL:
provider = new MySqlPagingQueryProvider();
break;
case MARIADB:
provider = new MariaDBPagingQueryProvider();
break;
case ORACLE:
provider = new OraclePagingQueryProvider();
break;
case POSTGRES:
provider = new PostgresPagingQueryProvider();
break;
case SYBASE:
provider = new SybasePagingQueryProvider();
break;
case SQLITE:
provider = new SqlitePagingQueryProvider();
break;
default:
throw new IllegalArgumentException(
"Unable to determine PagingQueryProvider type " + "from database type: " + databaseType);
}
AbstractSqlPagingQueryProvider provider = switch (databaseType) {
case DERBY -> new DerbyPagingQueryProvider();
case DB2, DB2VSE, DB2ZOS, DB2AS400 -> new Db2PagingQueryProvider();
case H2 -> new H2PagingQueryProvider();
case HANA -> new HanaPagingQueryProvider();
case HSQL -> new HsqlPagingQueryProvider();
case SQLSERVER -> new SqlServerPagingQueryProvider();
case MYSQL -> new MySqlPagingQueryProvider();
case MARIADB -> new MariaDBPagingQueryProvider();
case ORACLE -> new OraclePagingQueryProvider();
case POSTGRES -> new PostgresPagingQueryProvider();
case SYBASE -> new SybasePagingQueryProvider();
case SQLITE -> new SqlitePagingQueryProvider();
default -> throw new IllegalArgumentException(
"Unable to determine PagingQueryProvider type " + "from database type: " + databaseType);
};

provider.setSelectClause(this.selectClause);
provider.setFromClause(this.fromClause);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-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.
Expand Down Expand Up @@ -129,33 +129,22 @@ public org.apache.avro.Schema getSchema() {

// Used by DatumWriter. Applications should not call.
public Object get(int field$) {
switch (field$) {
case 0:
return name;
case 1:
return favorite_number;
case 2:
return favorite_color;
default:
throw new org.apache.avro.AvroRuntimeException("Bad index");
}
return switch (field$) {
case 0 -> name;
case 1 -> favorite_number;
case 2 -> favorite_color;
default -> throw new org.apache.avro.AvroRuntimeException("Bad index");
};
}

// Used by DatumReader. Applications should not call.
@SuppressWarnings(value = "unchecked")
public void put(int field$, Object value$) {
switch (field$) {
case 0:
name = (CharSequence) value$;
break;
case 1:
favorite_number = (Integer) value$;
break;
case 2:
favorite_color = (CharSequence) value$;
break;
default:
throw new org.apache.avro.AvroRuntimeException("Bad index");
case 0 -> name = (CharSequence) value$;
case 1 -> favorite_number = (Integer) value$;
case 2 -> favorite_color = (CharSequence) value$;
default -> throw new org.apache.avro.AvroRuntimeException("Bad index");
}
}

Expand Down Expand Up @@ -510,21 +499,17 @@ public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.
else {
for (int i = 0; i < 3; i++) {
switch (fieldOrder[i].pos()) {
case 0:
this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
break;

case 1:
case 0 -> this.name = in.readString(this.name instanceof Utf8 ? (Utf8) this.name : null);
case 1 -> {
if (in.readIndex() != 0) {
in.readNull();
this.favorite_number = null;
}
else {
this.favorite_number = in.readInt();
}
break;

case 2:
}
case 2 -> {
if (in.readIndex() != 0) {
in.readNull();
this.favorite_color = null;
Expand All @@ -533,10 +518,8 @@ public void customDecode(org.apache.avro.io.ResolvingDecoder in) throws java.io.
this.favorite_color = in.readString(
this.favorite_color instanceof Utf8 ? (Utf8) this.favorite_color : null);
}
break;

default:
throw new java.io.IOException("Corrupt ResolvingDecoder.");
}
default -> throw new java.io.IOException("Corrupt ResolvingDecoder.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 the original author or authors.
* Copyright 2008-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.
Expand Down Expand Up @@ -39,18 +39,12 @@ void setUp() {
@Nullable
@Override
public AggregateItem<String> read() {
switch (count++) {
case 0:
return AggregateItem.getHeader();
case 1:
case 2:
case 3:
return new AggregateItem<>("line");
case 4:
return AggregateItem.getFooter();
default:
return null;
}
return switch (count++) {
case 0 -> AggregateItem.getHeader();
case 1, 2, 3 -> new AggregateItem<>("line");
case 4 -> AggregateItem.getFooter();
default -> null;
};
}

};
Expand Down