-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathVersionInfoCommand.java
More file actions
68 lines (54 loc) · 2.06 KB
/
VersionInfoCommand.java
File metadata and controls
68 lines (54 loc) · 2.06 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.utplsql.cli;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import org.utplsql.api.DBHelper;
import org.utplsql.api.JavaApiVersionInfo;
import org.utplsql.api.Version;
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Parameters(separators = "=", commandDescription = "prints version information of cli, java-api and - if connection is given - database utPLSQL framework")
public class VersionInfoCommand implements ICommand {
@Parameter(
converter = ConnectionInfo.ConnectionStringConverter.class,
variableArity = true,
description = ConnectionInfo.COMMANDLINE_PARAM_DESCRIPTION)
private List<ConnectionInfo> connectionInfoList = new ArrayList<>();
public ConnectionInfo getConnectionInfo() {
if ( connectionInfoList != null && connectionInfoList.size() > 0 )
return connectionInfoList.get(0);
else
return null;
}
public int run() {
System.out.println(CliVersionInfo.getInfo());
System.out.println(JavaApiVersionInfo.getInfo());
try {
writeUtPlsqlVersion(getConnectionInfo());
}
catch (SQLException e) {
e.printStackTrace();
return 1;
}
return 0;
}
private void writeUtPlsqlVersion( ConnectionInfo ci ) throws SQLException {
if ( ci != null ) {
DataSource dataSource = DataSourceProvider.getDataSource(ci, 1);
try (Connection con = dataSource.getConnection()) {
Version v = DBHelper.getDatabaseFrameworkVersion( con );
System.out.println("utPLSQL " + v.getNormalizedString());
}
catch ( UtPLSQLNotInstalledException e ) {
System.out.println("utPLSQL framework is not installed in database.");
}
}
}
@Override
public String getCommand() {
return "info";
}
}