Skip to content

Commit

Permalink
feat: Added setters for command options
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Sep 23, 2022
1 parent e8c67dc commit 2b39e14
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.18.3
2.18.4-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,48 @@ public class DatabaseExportCommand extends AbstractExportCommand {
@Mixin
private DataSourceOptions dataSourceOptions = new DataSourceOptions();
@Mixin
private DatabaseExportOptions exportOptions = new DatabaseExportOptions();
private DatabaseExportOptions options = new DatabaseExportOptions();

public DatabaseExportOptions getExportOptions() {
return exportOptions;
public DatabaseExportOptions getOptions() {
return options;
}

public void setOptions(DatabaseExportOptions exportOptions) {
this.options = exportOptions;
}

public DataSourceOptions getDataSourceOptions() {
return dataSourceOptions;
}

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

public String getSql() {
return sql;
}

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

@Override
protected Job job(JobCommandContext context) throws SQLException {
log.log(Level.FINE, "Creating data source with {0}", dataSourceOptions);
DataSource dataSource = dataSourceOptions.dataSource();
try (Connection connection = dataSource.getConnection()) {
String dbName = connection.getMetaData().getDatabaseProductName();
log.log(Level.FINE, "Creating writer for database {0} with {1}", new Object[] { dbName, exportOptions });
log.log(Level.FINE, "Creating writer for database {0} with {1}", new Object[] { dbName, options });
JdbcBatchItemWriterBuilder<Map<String, Object>> builder = new JdbcBatchItemWriterBuilder<>();
builder.itemSqlParameterSourceProvider(NullableMapSqlParameterSource::new);
builder.dataSource(dataSource);
builder.sql(sql);
builder.assertUpdates(exportOptions.isAssertUpdates());
builder.assertUpdates(options.isAssertUpdates());
JdbcBatchItemWriter<Map<String, Object>> writer = builder.build();
writer.afterPropertiesSet();
ItemProcessor<DataStructure<String>, Map<String, Object>> processor = DataStructureToMapProcessor
.of(exportOptions.getKeyRegex());
.of(options.getKeyRegex());
String task = String.format("Exporting to %s", dbName);
return job(context, NAME, step(context, NAME, reader(context), processor, writer), task);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ public DataSourceOptions getDataSourceOptions() {
return dataSourceOptions;
}

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

public DatabaseImportOptions getImportOptions() {
return importOptions;
}

public void setImportOptions(DatabaseImportOptions importOptions) {
this.importOptions = importOptions;
}

@Override
protected Job job(JobCommandContext context) throws Exception {
log.log(Level.FINE, "Creating data source: {0}", dataSourceOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public class DumpFileImportCommand extends AbstractTransferCommand {

@Parameters(arity = "0..*", description = "One ore more files or URLs", paramLabel = "FILE")
private List<String> files;

@Mixin
private DumpFileOptions options = new DumpFileOptions();

@ArgGroup(exclusive = false, heading = "Writer options%n")
private RedisWriterOptions writerOptions = new RedisWriterOptions();

Expand All @@ -56,10 +58,18 @@ public DumpFileOptions getOptions() {
return options;
}

public void setOptions(DumpFileOptions options) {
this.options = options;
}

public RedisWriterOptions getWriterOptions() {
return writerOptions;
}

public void setWriterOptions(RedisWriterOptions writerOptions) {
this.writerOptions = writerOptions;
}

@Override
protected Job job(JobCommandContext context) throws Exception {
Assert.isTrue(!ObjectUtils.isEmpty(files), "No file specified");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public FileExportOptions getOptions() {
return options;
}

public void setOptions(FileExportOptions options) {
this.options = options;
}

@Override
protected Job job(JobCommandContext context) throws Exception {
WritableResource resource = options.outputResource(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public FileImportOptions getOptions() {
return options;
}

public void setOptions(FileImportOptions options) {
this.options = options;
}

@Override
protected Job job(JobCommandContext context) throws Exception {
Assert.isTrue(!ObjectUtils.isEmpty(files), "No file specified");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ public class DataStructureGeneratorCommand extends AbstractTransferCommand {
@ArgGroup(exclusive = false, heading = "Writer options%n")
private RedisWriterOptions writerOptions = new RedisWriterOptions();

public DataStructureGeneratorOptions getOptions() {
return options;
}

public void setOptions(DataStructureGeneratorOptions options) {
this.options = options;
}

public RedisWriterOptions getWriterOptions() {
return writerOptions;
}

public void setWriterOptions(RedisWriterOptions writerOptions) {
this.writerOptions = writerOptions;
}

@Override
protected Job job(JobCommandContext context) throws Exception {
RedisItemWriter<String, String, DataStructure<String>> writer = RedisItemWriter.dataStructure(context.pool())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public class FakerGeneratorCommand extends AbstractImportCommand {
@Mixin
private FakerGeneratorOptions options = new FakerGeneratorOptions();

public FakerGeneratorOptions getOptions() {
return options;
}

public void setOptions(FakerGeneratorOptions options) {
this.options = options;
}

@Override
protected Job job(JobCommandContext context) throws Exception {
SimpleStepBuilder<Map<String, Object>, Map<String, Object>> step = step(context, NAME, reader(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,26 @@ public FlushingTransferOptions getFlushingTransferOptions() {
return flushingTransferOptions;
}

public void setFlushingTransferOptions(FlushingTransferOptions flushingTransferOptions) {
this.flushingTransferOptions = flushingTransferOptions;
}

public ReplicationOptions getReplicationOptions() {
return replicationOptions;
}

public void setReplicationOptions(ReplicationOptions replicationOptions) {
this.replicationOptions = replicationOptions;
}

public RedisWriterOptions getWriterOptions() {
return writerOptions;
}

public void setWriterOptions(RedisWriterOptions writerOptions) {
this.writerOptions = writerOptions;
}

@Override
protected Job job(JobCommandContext jobCommandContext) {
TargetCommandContext context = (TargetCommandContext) jobCommandContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ public RedisOptions getTargetRedisOptions() {
return targetRedisOptions;
}

public void setTargetRedisOptions(RedisOptions targetRedisOptions) {
this.targetRedisOptions = targetRedisOptions;
}

public RedisReaderOptions getReaderOptions() {
return readerOptions;
}

public void setReaderOptions(RedisReaderOptions readerOptions) {
this.readerOptions = readerOptions;
}

public CompareOptions getCompareOptions() {
return compareOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
public abstract class AbstractExportCommand extends AbstractTransferCommand {

@ArgGroup(exclusive = false, heading = "Reader options%n")
private RedisReaderOptions readerArgs = new RedisReaderOptions();
private RedisReaderOptions readerOptions = new RedisReaderOptions();

public void setReaderOptions(RedisReaderOptions readerOptions) {
this.readerOptions = readerOptions;
}

protected RedisItemReader<String, DataStructure<String>> reader(JobCommandContext context) {
return RedisItemReader.dataStructure(context.pool(), context.getJobRunner()).options(readerArgs.readerOptions())
.build();
return RedisItemReader.dataStructure(context.pool(), context.getJobRunner())
.options(readerOptions.readerOptions()).build();
}

protected <I, O> Job job(JobCommandContext context, String name, SimpleStepBuilder<I, O> step, String task) {
ScanSizeEstimator estimator = ScanSizeEstimator.builder(context.pool()).options(readerArgs.estimatorOptions())
.build();
ScanSizeEstimator estimator = ScanSizeEstimator.builder(context.pool())
.options(readerOptions.estimatorOptions()).build();
return super.job(context, name, step, progressMonitor().task(task).initialMax(estimator::execute).build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public abstract class AbstractImportCommand extends AbstractTransferCommand {
private MapProcessorOptions processorOptions = new MapProcessorOptions();

@ArgGroup(exclusive = false, heading = "Writer options%n")
private RedisWriterOptions writerArgs = new RedisWriterOptions();
private RedisWriterOptions writerOptions = new RedisWriterOptions();

/**
* Initialized manually during command parsing
Expand All @@ -67,6 +67,22 @@ public List<OperationCommand<Map<String, Object>>> getRedisCommands() {
return redisCommands;
}

public MapProcessorOptions getProcessorOptions() {
return processorOptions;
}

public void setProcessorOptions(MapProcessorOptions processorOptions) {
this.processorOptions = processorOptions;
}

public RedisWriterOptions getWriterOptions() {
return writerOptions;
}

public void setWriterOptions(RedisWriterOptions writerOptions) {
this.writerOptions = writerOptions;
}

public void setRedisCommands(List<OperationCommand<Map<String, Object>>> redisCommands) {
this.redisCommands = redisCommands;
}
Expand Down Expand Up @@ -117,7 +133,7 @@ protected ItemWriter<Map<String, Object>> writer(JobCommandContext context) {

private ItemWriter<Map<String, Object>> writer(JobCommandContext context,
Operation<String, String, Map<String, Object>> operation) {
return RedisItemWriter.operation(context.pool(), operation).options(writerArgs.writerOptions()).build();
return RedisItemWriter.operation(context.pool(), operation).options(writerOptions.writerOptions()).build();
}

protected Job job(JobCommandContext context, String name, ItemReader<Map<String, Object>> reader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public abstract class AbstractTransferCommand extends AbstractJobCommand {
@Mixin
protected ProgressMonitorOptions progressOptions = new ProgressMonitorOptions();

public void setTransferOptions(TransferOptions transferOptions) {
this.transferOptions = transferOptions;
}

public void setProgressOptions(ProgressMonitorOptions progressOptions) {
this.progressOptions = progressOptions;
}

protected <I, O> SimpleStepBuilder<I, O> step(JobCommandContext context, String name, ItemReader<I> reader,
ItemProcessor<I, O> processor, ItemWriter<O> writer) {
return context.step(name).<I, O>chunk(transferOptions.getChunkSize()).reader(synchronize(reader))
Expand Down

0 comments on commit 2b39e14

Please sign in to comment.