|
| 1 | +package org.utplsql.cli; |
| 2 | + |
| 3 | + |
| 4 | +import com.beust.jcommander.Parameter; |
| 5 | +import com.beust.jcommander.Parameters; |
| 6 | +import org.utplsql.api.DBHelper; |
| 7 | +import org.utplsql.api.JavaApiVersionInfo; |
| 8 | +import org.utplsql.api.Version; |
| 9 | +import org.utplsql.api.exception.UtPLSQLNotInstalledException; |
| 10 | + |
| 11 | +import java.sql.Connection; |
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +@Parameters(separators = "=", commandDescription = "prints version information of cli, java-api and - if connection is given - database utPLSQL framework") |
| 16 | +public class VersionInfoCommand { |
| 17 | + |
| 18 | + @Parameter( |
| 19 | + converter = ConnectionInfo.ConnectionStringConverter.class, |
| 20 | + variableArity = true, |
| 21 | + description = "<user>/<password>@//<host>[:<port>]/<service> OR <user>/<password>@<TNSName> OR <user>/<password>@<host>:<port>:<SID>") |
| 22 | + private List<ConnectionInfo> connectionInfoList = new ArrayList<>(); |
| 23 | + |
| 24 | + public ConnectionInfo getConnectionInfo() { |
| 25 | + if ( connectionInfoList != null && connectionInfoList.size() > 0 ) |
| 26 | + return connectionInfoList.get(0); |
| 27 | + else |
| 28 | + return null; |
| 29 | + } |
| 30 | + |
| 31 | + public int run() throws Exception { |
| 32 | + |
| 33 | + System.out.println(CliVersionInfo.getInfo()); |
| 34 | + System.out.println("Java-API " + JavaApiVersionInfo.getVersion()); |
| 35 | + |
| 36 | + ConnectionInfo ci = getConnectionInfo(); |
| 37 | + if ( ci != null ) { |
| 38 | + // TODO: Ora-check |
| 39 | + ci.setMaxConnections(1); |
| 40 | + try (Connection con = ci.getConnection()) { |
| 41 | + Version v = DBHelper.getDatabaseFrameworkVersion( con ); |
| 42 | + System.out.println("utPLSQL " + v.getNormalizedString()); |
| 43 | + } |
| 44 | + catch ( UtPLSQLNotInstalledException e ) { |
| 45 | + System.out.println("utPLSQL framework is not installed in database."); |
| 46 | + } |
| 47 | + catch ( Exception e ) { |
| 48 | + e.printStackTrace(); |
| 49 | + return 1; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + return 0; |
| 54 | + } |
| 55 | +} |
0 commit comments