Skip to content

Commit

Permalink
refactor!: Consolidated cli and core modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed May 24, 2024
1 parent 9e5543d commit 870d10d
Show file tree
Hide file tree
Showing 249 changed files with 7,302 additions and 10,351 deletions.
4 changes: 3 additions & 1 deletion connectors/riot-db/riot-db.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* limitations under the License.
*/
dependencies {
implementation project(':riot-core')
api group: 'info.picocli', name: 'picocli', version: picocliVersion
annotationProcessor group: 'info.picocli', name: 'picocli-codegen', version: picocliVersion
implementation 'org.springframework.batch:spring-batch-infrastructure'
implementation 'org.springframework.boot:spring-boot-autoconfigure'
implementation 'org.springframework:spring-jdbc'
implementation 'com.zaxxer:HikariCP'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.redis.riot.cli;
package com.redis.riot.db;

import com.redis.riot.db.DataSourceOptions;
import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;

import picocli.CommandLine.Option;

public class DbArgs {
public class DatabaseArgs {

@Option(names = "--driver", description = "Fully qualified name of the JDBC driver.", paramLabel = "<class>")
private String driver;
Expand All @@ -18,15 +20,6 @@ public class DbArgs {
@Option(names = "--password", arity = "0..1", interactive = true, description = "Login password of the database.", paramLabel = "<pwd>")
private String password;

public DataSourceOptions dataSourceOptions() {
DataSourceOptions options = new DataSourceOptions();
options.setDriver(driver);
options.setUrl(url);
options.setUsername(username);
options.setPassword(password);
return options;
}

public String getDriver() {
return driver;
}
Expand Down Expand Up @@ -59,4 +52,13 @@ public void setPassword(String password) {
this.password = password;
}

public DataSource dataSource() {
DataSourceProperties properties = new DataSourceProperties();
properties.setUrl(url);
properties.setDriverClassName(driver);
properties.setUsername(username);
properties.setPassword(password);
return properties.initializeDataSourceBuilder().build();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,113 +2,101 @@

import java.util.Map;

import org.springframework.batch.core.Job;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.database.AbstractCursorItemReader;
import org.springframework.batch.item.database.JdbcCursorItemReader;
import org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder;
import org.springframework.jdbc.core.ColumnMapRowMapper;

import com.redis.riot.core.AbstractImport;
import picocli.CommandLine.Option;

public class DatabaseImport extends AbstractImport {
public class DatabaseReaderArgs extends DatabaseArgs {

public static final int DEFAULT_FETCH_SIZE = AbstractCursorItemReader.VALUE_NOT_SET;
public static final int DEFAULT_MAX_RESULT_SET_ROWS = AbstractCursorItemReader.VALUE_NOT_SET;
public static final int DEFAULT_QUERY_TIMEOUT = AbstractCursorItemReader.VALUE_NOT_SET;

private String sql;
private DataSourceOptions dataSourceOptions = new DataSourceOptions();
@Option(names = "--max", description = "Max number of rows to import.", paramLabel = "<count>")
private int maxItemCount;

@Option(names = "--fetch", description = "Number of rows to return with each fetch.", paramLabel = "<size>")
private int fetchSize = DEFAULT_FETCH_SIZE;
private int maxResultSetRows = DEFAULT_MAX_RESULT_SET_ROWS;

@Option(names = "--rows", description = "Max number of rows the ResultSet can contain.", paramLabel = "<count>")
private int maxRows = DEFAULT_MAX_RESULT_SET_ROWS;

@Option(names = "--query-timeout", description = "The time in milliseconds for the query to timeout.", paramLabel = "<ms>")
private int queryTimeout = DEFAULT_QUERY_TIMEOUT;

@Option(names = "--shared-connection", description = "Use same connection for cursor and other processing.", hidden = true)
private boolean useSharedExtendedConnection;

@Option(names = "--verify", description = "Verify position of result set after row mapper.", hidden = true)
private boolean verifyCursorPosition;

@Override
protected Job job() {
public JdbcCursorItemReaderBuilder<Map<String, Object>> reader() {
JdbcCursorItemReaderBuilder<Map<String, Object>> builder = new JdbcCursorItemReaderBuilder<>();
builder.name(sql);
builder.saveState(false);
builder.dataSource(dataSourceOptions.dataSource());
builder.dataSource(dataSource());
builder.rowMapper(new ColumnMapRowMapper());
builder.sql(sql);
builder.fetchSize(fetchSize);
builder.maxRows(maxResultSetRows);
builder.maxRows(maxRows);
builder.queryTimeout(queryTimeout);
builder.useSharedExtendedConnection(useSharedExtendedConnection);
builder.verifyCursorPosition(verifyCursorPosition);
if (maxItemCount > 0) {
builder.maxItemCount(maxItemCount);
}
JdbcCursorItemReader<Map<String, Object>> reader = builder.build();
ItemProcessor<Map<String, Object>, Map<String, Object>> processor = mapProcessor();
ItemWriter<Map<String, Object>> writer = mapWriter();
return jobBuilder().start(step(getName(), reader, writer).processor(processor).build()).build();
}

public String getSql() {
return sql;
}

public void setSql(String sql) {
this.sql = sql;
}

public DataSourceOptions getDataSourceOptions() {
return dataSourceOptions;
}

public void setDataSourceOptions(DataSourceOptions dataSourceOptions) {
this.dataSourceOptions = dataSourceOptions;
return builder;
}

public int getMaxItemCount() {
return maxItemCount;
}

public int getFetchSize() {
return fetchSize;
}

public int getMaxResultSetRows() {
return maxResultSetRows;
}

public int getQueryTimeout() {
return queryTimeout;
public void setMaxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
}

public boolean isUseSharedExtendedConnection() {
return useSharedExtendedConnection;
public int getFetchSize() {
return fetchSize;
}

public boolean isVerifyCursorPosition() {
return verifyCursorPosition;
public void setFetchSize(int fetchSize) {
this.fetchSize = fetchSize;
}

public void setMaxItemCount(int maxItemCount) {
this.maxItemCount = maxItemCount;
/**
* The max number of rows the {@link java.sql.ResultSet} can contain
*
* @return
*/
public int getMaxRows() {
return maxRows;
}

public void setFetchSize(int fetchSize) {
this.fetchSize = fetchSize;
public void setMaxRows(int maxResultSetRows) {
this.maxRows = maxResultSetRows;
}

public void setMaxResultSetRows(int rows) {
this.maxResultSetRows = rows;
public int getQueryTimeout() {
return queryTimeout;
}

public void setQueryTimeout(int queryTimeout) {
this.queryTimeout = queryTimeout;
}

public boolean isUseSharedExtendedConnection() {
return useSharedExtendedConnection;
}

public void setUseSharedExtendedConnection(boolean useSharedExtendedConnection) {
this.useSharedExtendedConnection = useSharedExtendedConnection;
}

public boolean isVerifyCursorPosition() {
return verifyCursorPosition;
}

public void setVerifyCursorPosition(boolean verifyCursorPosition) {
this.verifyCursorPosition = verifyCursorPosition;
}
Expand Down
Loading

0 comments on commit 870d10d

Please sign in to comment.