forked from utPLSQL/utPLSQL-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersionInfoCommand.java
More file actions
54 lines (41 loc) · 1.8 KB
/
VersionInfoCommand.java
File metadata and controls
54 lines (41 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.utplsql.cli;
import org.utplsql.api.JavaApiVersionInfo;
import org.utplsql.api.Version;
import org.utplsql.api.db.DefaultDatabaseInformation;
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
@Command(name = "info", description = "prints version information of cli, java-api and - if connection is given - database utPLSQL framework")
public class VersionInfoCommand implements ICommand {
@Parameters(description = UtplsqlPicocliCommand.COMMANDLINE_PARAM_DESCRIPTION, arity = "0..1")
private String connectionString;
@Option(names = "-h", usageHelp = true, description = "display this help and exit")
boolean help;
public int run() {
LoggerConfiguration.configure(LoggerConfiguration.ConfigLevel.NONE);
System.out.println(CliVersionInfo.getInfo());
System.out.println(JavaApiVersionInfo.getInfo());
try {
writeUtPlsqlVersion(connectionString);
} catch (SQLException e) {
e.printStackTrace();
return 1;
}
return 0;
}
private void writeUtPlsqlVersion(String connectString) throws SQLException {
if (connectString != null) {
DataSource dataSource = DataSourceProvider.getDataSource(connectString, 1);
try (Connection con = dataSource.getConnection()) {
Version v = new DefaultDatabaseInformation().getUtPlsqlFrameworkVersion(con);
System.out.println("utPLSQL " + v.getNormalizedString());
} catch (UtPLSQLNotInstalledException e) {
System.out.println(e.getMessage());
}
}
}
}