From 2b39e14fbd7194cbae1cd2dae62eb4880abfa6b5 Mon Sep 17 00:00:00 2001 From: Julien Ruaux Date: Thu, 22 Sep 2022 20:56:37 -0700 Subject: [PATCH] feat: Added setters for command options --- VERSION | 2 +- .../redis/riot/db/DatabaseExportCommand.java | 28 +++++++++++++++---- .../redis/riot/db/DatabaseImportCommand.java | 12 ++++++++ .../riot/file/DumpFileImportCommand.java | 10 +++++++ .../redis/riot/file/FileExportCommand.java | 4 +++ .../redis/riot/file/FileImportCommand.java | 4 +++ .../gen/DataStructureGeneratorCommand.java | 16 +++++++++++ .../redis/riot/gen/FakerGeneratorCommand.java | 8 ++++++ .../riot/redis/AbstractReplicateCommand.java | 12 ++++++++ .../riot/redis/AbstractTargetCommand.java | 8 ++++++ .../com/redis/riot/AbstractExportCommand.java | 14 ++++++---- .../com/redis/riot/AbstractImportCommand.java | 20 +++++++++++-- .../redis/riot/AbstractTransferCommand.java | 8 ++++++ 13 files changed, 132 insertions(+), 14 deletions(-) diff --git a/VERSION b/VERSION index 26452813e..4fc7e37c6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.18.3 +2.18.4-SNAPSHOT diff --git a/connectors/riot-db/src/main/java/com/redis/riot/db/DatabaseExportCommand.java b/connectors/riot-db/src/main/java/com/redis/riot/db/DatabaseExportCommand.java index 9e4e5ae20..df04fd85c 100644 --- a/connectors/riot-db/src/main/java/com/redis/riot/db/DatabaseExportCommand.java +++ b/connectors/riot-db/src/main/java/com/redis/riot/db/DatabaseExportCommand.java @@ -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> builder = new JdbcBatchItemWriterBuilder<>(); builder.itemSqlParameterSourceProvider(NullableMapSqlParameterSource::new); builder.dataSource(dataSource); builder.sql(sql); - builder.assertUpdates(exportOptions.isAssertUpdates()); + builder.assertUpdates(options.isAssertUpdates()); JdbcBatchItemWriter> writer = builder.build(); writer.afterPropertiesSet(); ItemProcessor, Map> 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); } diff --git a/connectors/riot-db/src/main/java/com/redis/riot/db/DatabaseImportCommand.java b/connectors/riot-db/src/main/java/com/redis/riot/db/DatabaseImportCommand.java index 0d09940df..2296eedec 100644 --- a/connectors/riot-db/src/main/java/com/redis/riot/db/DatabaseImportCommand.java +++ b/connectors/riot-db/src/main/java/com/redis/riot/db/DatabaseImportCommand.java @@ -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); diff --git a/connectors/riot-file/src/main/java/com/redis/riot/file/DumpFileImportCommand.java b/connectors/riot-file/src/main/java/com/redis/riot/file/DumpFileImportCommand.java index 6a41c2d1e..ee875670c 100644 --- a/connectors/riot-file/src/main/java/com/redis/riot/file/DumpFileImportCommand.java +++ b/connectors/riot-file/src/main/java/com/redis/riot/file/DumpFileImportCommand.java @@ -39,8 +39,10 @@ public class DumpFileImportCommand extends AbstractTransferCommand { @Parameters(arity = "0..*", description = "One ore more files or URLs", paramLabel = "FILE") private List files; + @Mixin private DumpFileOptions options = new DumpFileOptions(); + @ArgGroup(exclusive = false, heading = "Writer options%n") private RedisWriterOptions writerOptions = new RedisWriterOptions(); @@ -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"); diff --git a/connectors/riot-file/src/main/java/com/redis/riot/file/FileExportCommand.java b/connectors/riot-file/src/main/java/com/redis/riot/file/FileExportCommand.java index 9fe1bd134..c2386b1ef 100644 --- a/connectors/riot-file/src/main/java/com/redis/riot/file/FileExportCommand.java +++ b/connectors/riot-file/src/main/java/com/redis/riot/file/FileExportCommand.java @@ -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); diff --git a/connectors/riot-file/src/main/java/com/redis/riot/file/FileImportCommand.java b/connectors/riot-file/src/main/java/com/redis/riot/file/FileImportCommand.java index 75956c684..39d3395c2 100644 --- a/connectors/riot-file/src/main/java/com/redis/riot/file/FileImportCommand.java +++ b/connectors/riot-file/src/main/java/com/redis/riot/file/FileImportCommand.java @@ -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"); diff --git a/connectors/riot-gen/src/main/java/com/redis/riot/gen/DataStructureGeneratorCommand.java b/connectors/riot-gen/src/main/java/com/redis/riot/gen/DataStructureGeneratorCommand.java index e444e5e0f..2d2da6c02 100644 --- a/connectors/riot-gen/src/main/java/com/redis/riot/gen/DataStructureGeneratorCommand.java +++ b/connectors/riot-gen/src/main/java/com/redis/riot/gen/DataStructureGeneratorCommand.java @@ -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> writer = RedisItemWriter.dataStructure(context.pool()) diff --git a/connectors/riot-gen/src/main/java/com/redis/riot/gen/FakerGeneratorCommand.java b/connectors/riot-gen/src/main/java/com/redis/riot/gen/FakerGeneratorCommand.java index dbc48137d..cabb4f837 100644 --- a/connectors/riot-gen/src/main/java/com/redis/riot/gen/FakerGeneratorCommand.java +++ b/connectors/riot-gen/src/main/java/com/redis/riot/gen/FakerGeneratorCommand.java @@ -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> step = step(context, NAME, reader(context)); diff --git a/connectors/riot-redis/src/main/java/com/redis/riot/redis/AbstractReplicateCommand.java b/connectors/riot-redis/src/main/java/com/redis/riot/redis/AbstractReplicateCommand.java index 9ea91687b..f4f069b63 100644 --- a/connectors/riot-redis/src/main/java/com/redis/riot/redis/AbstractReplicateCommand.java +++ b/connectors/riot-redis/src/main/java/com/redis/riot/redis/AbstractReplicateCommand.java @@ -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; diff --git a/connectors/riot-redis/src/main/java/com/redis/riot/redis/AbstractTargetCommand.java b/connectors/riot-redis/src/main/java/com/redis/riot/redis/AbstractTargetCommand.java index aeb84e0b0..f6e25ad89 100644 --- a/connectors/riot-redis/src/main/java/com/redis/riot/redis/AbstractTargetCommand.java +++ b/connectors/riot-redis/src/main/java/com/redis/riot/redis/AbstractTargetCommand.java @@ -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; } diff --git a/core/riot-core/src/main/java/com/redis/riot/AbstractExportCommand.java b/core/riot-core/src/main/java/com/redis/riot/AbstractExportCommand.java index 32bba1419..6c8029cec 100644 --- a/core/riot-core/src/main/java/com/redis/riot/AbstractExportCommand.java +++ b/core/riot-core/src/main/java/com/redis/riot/AbstractExportCommand.java @@ -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> 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 Job job(JobCommandContext context, String name, SimpleStepBuilder 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()); } diff --git a/core/riot-core/src/main/java/com/redis/riot/AbstractImportCommand.java b/core/riot-core/src/main/java/com/redis/riot/AbstractImportCommand.java index 22b4d9c59..c32bf31ff 100644 --- a/core/riot-core/src/main/java/com/redis/riot/AbstractImportCommand.java +++ b/core/riot-core/src/main/java/com/redis/riot/AbstractImportCommand.java @@ -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 @@ -67,6 +67,22 @@ public List>> 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>> redisCommands) { this.redisCommands = redisCommands; } @@ -117,7 +133,7 @@ protected ItemWriter> writer(JobCommandContext context) { private ItemWriter> writer(JobCommandContext context, Operation> 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> reader, diff --git a/core/riot-core/src/main/java/com/redis/riot/AbstractTransferCommand.java b/core/riot-core/src/main/java/com/redis/riot/AbstractTransferCommand.java index a70435cfa..fd9a408fb 100644 --- a/core/riot-core/src/main/java/com/redis/riot/AbstractTransferCommand.java +++ b/core/riot-core/src/main/java/com/redis/riot/AbstractTransferCommand.java @@ -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 SimpleStepBuilder step(JobCommandContext context, String name, ItemReader reader, ItemProcessor processor, ItemWriter writer) { return context.step(name).chunk(transferOptions.getChunkSize()).reader(synchronize(reader))