Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

Commit b827787

Browse files
committed
refactor: Move data source initialization exception handling outside cli
1 parent 67bbe86 commit b827787

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

plugins/riot/src/main/java/com/redis/riot/DataSourceArgs.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
66
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
77

8-
import com.redis.riot.core.RiotExecutionException;
9-
108
import lombok.ToString;
119
import picocli.CommandLine.Option;
1210

@@ -25,18 +23,14 @@ public class DataSourceArgs {
2523
@Option(names = "--jdbc-pass", arity = "0..1", interactive = true, description = "Login password of the database.", paramLabel = "<pwd>")
2624
private String password;
2725

28-
public DataSource dataSource() throws RiotExecutionException {
26+
public DataSource dataSource() throws Exception {
2927
DataSourceProperties properties = new DataSourceProperties();
3028
properties.setUrl(url);
3129
properties.setDriverClassName(driver);
3230
properties.setUsername(username);
3331
properties.setPassword(password);
3432
properties.setEmbeddedDatabaseConnection(EmbeddedDatabaseConnection.NONE);
35-
try {
36-
properties.afterPropertiesSet();
37-
} catch (Exception e) {
38-
throw new RiotExecutionException("Could not initialize datasource", e);
39-
}
33+
properties.afterPropertiesSet();
4034
return properties.initializeDataSourceBuilder().build();
4135
}
4236

plugins/riot/src/main/java/com/redis/riot/DatabaseExport.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ protected Job job() throws RiotExecutionException {
4040
private JdbcBatchItemWriter<Map<String, Object>> writer() throws RiotExecutionException {
4141
Assert.hasLength(sql, "No SQL statement specified");
4242
log.info("Creating data source with {}", dataSourceArgs);
43-
DataSource dataSource = dataSourceArgs.dataSource();
43+
DataSource dataSource;
44+
try {
45+
dataSource = dataSourceArgs.dataSource();
46+
} catch (Exception e) {
47+
throw new RiotExecutionException("Could not initialize data source", e);
48+
}
4449
log.info("Creating JDBC writer with sql=\"{}\" assertUpdates={}", sql, assertUpdates);
4550
JdbcBatchItemWriterBuilder<Map<String, Object>> builder = new JdbcBatchItemWriterBuilder<>();
4651
builder.itemSqlParameterSourceProvider(NullableSqlParameterSource::new);

plugins/riot/src/main/java/com/redis/riot/DatabaseImport.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ protected Job job() throws RiotExecutionException {
3636
protected JdbcCursorItemReader<Map<String, Object>> reader() throws RiotExecutionException {
3737
Assert.hasLength(sql, "No SQL statement specified");
3838
log.info("Creating data source with {}", dataSourceArgs);
39-
DataSource dataSource = dataSourceArgs.dataSource();
39+
DataSource dataSource;
40+
try {
41+
dataSource = dataSourceArgs.dataSource();
42+
} catch (Exception e) {
43+
throw new RiotExecutionException("Could not initialize data source", e);
44+
}
4045
log.info("Creating JDBC reader with sql=\"{}\" {}", sql, readerArgs);
4146
JdbcCursorItemReaderBuilder<Map<String, Object>> reader = new JdbcCursorItemReaderBuilder<>();
4247
reader.dataSource(dataSource);

0 commit comments

Comments
 (0)