Skip to content

Commit 4303da3

Browse files
committed
refactored import and export packages
1 parent bf92c51 commit 4303da3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+473
-522
lines changed

pom.xml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@
7777
<groupId>com.fasterxml.jackson.dataformat</groupId>
7878
<artifactId>jackson-dataformat-xml</artifactId>
7979
</dependency>
80-
<!-- Test -->
81-
<dependency>
82-
<groupId>junit</groupId>
83-
<artifactId>junit</artifactId>
84-
<scope>test</scope>
85-
</dependency>
8680
<dependency>
8781
<groupId>info.picocli</groupId>
8882
<artifactId>picocli</artifactId>
@@ -103,14 +97,37 @@
10397
<artifactId>javafaker</artifactId>
10498
<version>0.18</version>
10599
</dependency>
100+
<!-- Test -->
106101
<dependency>
107-
<groupId>mysql</groupId>
108-
<artifactId>mysql-connector-java</artifactId>
102+
<groupId>junit</groupId>
103+
<artifactId>junit</artifactId>
104+
<scope>test</scope>
109105
</dependency>
106+
<!-- <dependency> -->
107+
<!-- <groupId>mysql</groupId> -->
108+
<!-- <artifactId>mysql-connector-java</artifactId> -->
109+
<!-- </dependency> -->
110110
</dependencies>
111111

112112
<build>
113113
<plugins>
114+
<!-- <plugin> -->
115+
<!-- <groupId>org.asciidoctor</groupId> -->
116+
<!-- <artifactId>asciidoctor-maven-plugin</artifactId> -->
117+
<!-- <version>1.5.8</version> -->
118+
<!-- <executions> -->
119+
<!-- <execution> -->
120+
<!-- <id>output-html</id> -->
121+
<!-- <phase>generate-resources</phase> -->
122+
<!-- <goals> -->
123+
<!-- <goal>process-asciidoc</goal> -->
124+
<!-- </goals> -->
125+
<!-- </execution> -->
126+
<!-- </executions> -->
127+
<!-- <configuration> -->
128+
<!-- <sourceDirectory>${basedir}</sourceDirectory> -->
129+
<!-- </configuration> -->
130+
<!-- </plugin> -->
114131
<plugin>
115132
<artifactId>maven-assembly-plugin</artifactId>
116133
<configuration>

src/main/java/com/redislabs/riot/RiotApplication.java

Lines changed: 5 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,30 @@
11
package com.redislabs.riot;
22

3-
import java.net.InetAddress;
43
import java.util.List;
54
import java.util.Locale;
65

76
import org.springframework.boot.CommandLineRunner;
87
import org.springframework.boot.SpringApplication;
98
import org.springframework.boot.autoconfigure.SpringBootApplication;
109

11-
import com.redislabs.riot.cli.Export;
12-
import com.redislabs.riot.cli.Import;
13-
import com.redislabs.riot.redis.RedisConnectionBuilder;
10+
import com.redislabs.riot.cli.RootCommand;
1411

15-
import io.lettuce.core.RedisURI;
16-
import lombok.Getter;
1712
import picocli.CommandLine;
18-
import picocli.CommandLine.Command;
1913
import picocli.CommandLine.DefaultExceptionHandler;
20-
import picocli.CommandLine.Option;
2114
import picocli.CommandLine.RunLast;
22-
import redis.clients.jedis.Protocol;
2315

2416
@SpringBootApplication
25-
@Command(name = "riot", subcommands = { Export.class, Import.class })
26-
public class RiotApplication extends BaseCommand implements CommandLineRunner {
17+
public class RiotApplication implements CommandLineRunner {
18+
19+
private RootCommand riot = new RootCommand();
2720

2821
public static void main(String[] args) {
2922
SpringApplication.run(RiotApplication.class, args);
3023
}
3124

32-
public static final String DEFAULT_HOST = "localhost";
33-
34-
public enum RedisDriver {
35-
Jedis, Lettuce
36-
}
37-
38-
/**
39-
* Just to avoid picocli complain in Eclipse console
40-
*/
41-
@Option(names = "--spring.output.ansi.enabled", hidden = true)
42-
private String ansiEnabled;
43-
44-
@Option(names = "--driver", description = "Redis driver: ${COMPLETION-CANDIDATES}. (default: ${DEFAULT-VALUE})")
45-
@Getter
46-
private RedisDriver driver = RedisDriver.Jedis;
47-
@Option(names = "--host", description = "Redis server host. (default: localhost).")
48-
private InetAddress host;
49-
@Option(names = "--port", description = "Redis server port. (default: ${DEFAULT-VALUE}).")
50-
private int port = RedisURI.DEFAULT_REDIS_PORT;
51-
@Option(names = "--command-timeout", description = "Redis command timeout in seconds for synchronous command execution (default: ${DEFAULT-VALUE}).")
52-
private long commandTimeout = RedisURI.DEFAULT_TIMEOUT;
53-
@Option(names = "--connection-timeout", description = "Redis connect timeout in milliseconds. (default: ${DEFAULT-VALUE}).")
54-
private int connectionTimeout = Protocol.DEFAULT_TIMEOUT;
55-
@Option(names = "--socket-timeout", description = "Redis socket timeout in milliseconds. (default: ${DEFAULT-VALUE}).")
56-
private int socketTimeout = Protocol.DEFAULT_TIMEOUT;
57-
@Option(names = "--password", description = "Redis database password.", interactive = true)
58-
private String password;
59-
@Option(names = "--max-idle", description = "Maximum number of idle connections in the pool. Use a negative value to indicate an unlimited number of idle connections. (default: ${DEFAULT-VALUE}).")
60-
private int maxIdle = 8;
61-
@Option(names = "--min-idle", description = "Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive. (default: ${DEFAULT-VALUE}).")
62-
private int minIdle = 0;
63-
@Option(names = "--max-total", description = "Maximum number of connections that can be allocated by the pool at a given time. Use a negative value for no limit. (default: ${DEFAULT-VALUE})")
64-
private int maxTotal = 8;
65-
@Option(names = "--max-wait", description = "Maximum amount of time in milliseconds a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely (default).")
66-
private long maxWait = -1L;
67-
@Option(names = "--database", description = "Redis database number. Databases are only available for Redis Standalone and Redis Master/Slave. (default: ${DEFAULT-VALUE}).")
68-
private int database = 0;
69-
@Option(names = "--client-name", description = "Redis client name.")
70-
private String clientName;
71-
72-
public RedisConnectionBuilder redisConnectionBuilder() {
73-
RedisConnectionBuilder builder = new RedisConnectionBuilder();
74-
builder.setClientName(clientName);
75-
builder.setCommandTimeout(commandTimeout);
76-
builder.setConnectionTimeout(connectionTimeout);
77-
builder.setDatabase(database);
78-
builder.setHost(getHostname());
79-
builder.setMaxTotal(maxTotal);
80-
builder.setMaxIdle(maxIdle);
81-
builder.setMaxWait(maxWait);
82-
builder.setMinIdle(minIdle);
83-
builder.setPassword(password);
84-
builder.setPort(port);
85-
builder.setSocketTimeout(socketTimeout);
86-
return builder;
87-
}
88-
89-
private String getHostname() {
90-
if (host != null) {
91-
return host.getHostName();
92-
}
93-
return DEFAULT_HOST;
94-
}
95-
9625
@Override
9726
public void run(String... args) {
98-
CommandLine commandLine = new CommandLine(this);
27+
CommandLine commandLine = new CommandLine(riot);
9928
commandLine.registerConverter(Locale.class, s -> new Locale.Builder().setLanguageTag(s).build());
10029
commandLine.setCaseInsensitiveEnumValuesAllowed(true);
10130
RunLast handler = new RunLast();
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package com.redislabs.riot;
1+
package com.redislabs.riot.cli;
22

33
import picocli.CommandLine;
44
import picocli.CommandLine.Command;
55

66
@Command(mixinStandardHelpOptions = true)
7-
public class BaseCommand implements Runnable {
7+
public abstract class AbstractCommand implements Runnable {
88

99
@Override
10-
public void run() {
10+
public void run() {
1111
new CommandLine(this).usage(System.out);
1212
}
1313
}

src/main/java/com/redislabs/riot/cli/CommandsBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
package com.redislabs.riot.cli;
33

4-
import com.redislabs.riot.RiotApplication.RedisDriver;
54
import com.redislabs.riot.redis.writer.JedisCommands;
65
import com.redislabs.riot.redis.writer.LettuceCommands;
76
import com.redislabs.riot.redis.writer.RedisCommands;
@@ -13,7 +12,7 @@ public class CommandsBuilder {
1312
@Setter
1413
private RedisDriver driver;
1514

16-
protected RedisCommands build() {
15+
public RedisCommands build() {
1716
switch (driver) {
1817
case Lettuce:
1918
return lettuceCommands();

src/main/java/com/redislabs/riot/cli/DelimitedFileImport.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/com/redislabs/riot/cli/FileImport.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/main/java/com/redislabs/riot/cli/FixedLengthFileImport.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/java/com/redislabs/riot/cli/FlatFileImport.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/main/java/com/redislabs/riot/cli/Import.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/java/com/redislabs/riot/cli/JobCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import org.springframework.core.task.SyncTaskExecutor;
2121
import org.springframework.transaction.PlatformTransactionManager;
2222

23-
import com.redislabs.riot.BaseCommand;
24-
import com.redislabs.riot.RiotApplication;
2523
import com.redislabs.riot.batch.JobBuilder;
2624

2725
import lombok.Getter;
@@ -30,11 +28,11 @@
3028
import picocli.CommandLine.ParentCommand;
3129

3230
@Command
33-
public class JobCommand<I, O> extends BaseCommand {
31+
public class JobCommand<I, O> extends AbstractCommand {
3432

3533
@ParentCommand
3634
@Getter
37-
private RiotApplication parent;
35+
private RootCommand parent;
3836

3937
private NumberFormat numberFormat = NumberFormat.getIntegerInstance();
4038

src/main/java/com/redislabs/riot/cli/JsonImport.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)