InfoLister/test: show also database server name and version v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 09 Nov 2016 00:18:01 +0100
branchv_0
changeset 2297699133f5a01
parent 228 3787c999d12c
child 230 8bae71482622
InfoLister/test: show also database server name and version
java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java
java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Sun Sep 13 20:10:13 2015 +0200
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Wed Nov 09 00:18:01 2016 +0100
     1.3 @@ -177,6 +177,14 @@
     1.4  		return true;
     1.5  	}
     1.6  
     1.7 +	public String getProductName() throws SQLException {
     1.8 +		return connection.getMetaData().getDatabaseProductName();
     1.9 +	}
    1.10 +
    1.11 +	public String getProductVersion() throws SQLException {
    1.12 +		return connection.getMetaData().getDatabaseProductVersion();
    1.13 +	}
    1.14 +
    1.15  	@Override
    1.16  	public void close() throws SQLException {
    1.17  		connection.close();
     2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sun Sep 13 20:10:13 2015 +0200
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Wed Nov 09 00:18:01 2016 +0100
     2.3 @@ -26,7 +26,6 @@
     2.4  import info.globalcode.sql.dk.configuration.Properties;
     2.5  import info.globalcode.sql.dk.configuration.Property;
     2.6  import info.globalcode.sql.dk.configuration.PropertyDeclaration;
     2.7 -import info.globalcode.sql.dk.configuration.PropertyDeclarations;
     2.8  import info.globalcode.sql.dk.configuration.TunnelDefinition;
     2.9  import info.globalcode.sql.dk.formatting.ColumnsHeader;
    2.10  import info.globalcode.sql.dk.formatting.CommonProperties;
    2.11 @@ -395,7 +394,9 @@
    2.12  		ColumnsHeader header = constructHeader(
    2.13  				new HeaderField("database_name", SQLType.VARCHAR),
    2.14  				new HeaderField("configured", SQLType.BOOLEAN),
    2.15 -				new HeaderField("connected", SQLType.BOOLEAN));
    2.16 +				new HeaderField("connected", SQLType.BOOLEAN),
    2.17 +				new HeaderField("product_name", SQLType.VARCHAR),
    2.18 +				new HeaderField("product_version", SQLType.VARCHAR));
    2.19  
    2.20  		log.log(Level.FINE, "Testing DB connections in {0} threads", TESTING_THREAD_COUNT);
    2.21  
    2.22 @@ -464,6 +465,8 @@
    2.23  
    2.24  		boolean succesfullyConnected = false;
    2.25  		boolean succesfullyConfigured = false;
    2.26 +		String productName = null;
    2.27 +		String productVersion = null;
    2.28  
    2.29  		try {
    2.30  			DatabaseDefinition dd = configurationProvider.getConfiguration().getDatabase(dbName);
    2.31 @@ -471,13 +474,15 @@
    2.32  			succesfullyConfigured = true;
    2.33  			try (DatabaseConnection dc = dd.connect(options.getDatabaseProperties())) {
    2.34  				succesfullyConnected = dc.test();
    2.35 +				productName = dc.getProductName();
    2.36 +				productVersion = dc.getProductVersion();
    2.37  			}
    2.38  			log.log(Level.FINE, "Database connection test was successful");
    2.39  		} catch (ConfigurationException | SQLException | RuntimeException e) {
    2.40  			log.log(Level.SEVERE, "Error during testing connection " + dbName, e);
    2.41  		}
    2.42  
    2.43 -		return new Object[]{dbName, succesfullyConfigured, succesfullyConnected};
    2.44 +		return new Object[]{dbName, succesfullyConfigured, succesfullyConnected, productName, productVersion};
    2.45  	}
    2.46  
    2.47  	private void printResource(String fileName) {
    2.48 @@ -591,77 +596,77 @@
    2.49  	public enum InfoType {
    2.50  
    2.51  		HELP {
    2.52 -					@Override
    2.53 -					public void showInfo(InfoLister infoLister) {
    2.54 -						infoLister.printResource(Constants.HELP_FILE);
    2.55 -					}
    2.56 -				},
    2.57 +			@Override
    2.58 +			public void showInfo(InfoLister infoLister) {
    2.59 +				infoLister.printResource(Constants.HELP_FILE);
    2.60 +			}
    2.61 +		},
    2.62  		VERSION {
    2.63 -					@Override
    2.64 -					public void showInfo(InfoLister infoLister) {
    2.65 -						infoLister.printResource(Constants.VERSION_FILE);
    2.66 -					}
    2.67 -				},
    2.68 +			@Override
    2.69 +			public void showInfo(InfoLister infoLister) {
    2.70 +				infoLister.printResource(Constants.VERSION_FILE);
    2.71 +			}
    2.72 +		},
    2.73  		LICENSE {
    2.74 -					@Override
    2.75 -					public void showInfo(InfoLister infoLister) {
    2.76 -						infoLister.printResource(Constants.LICENSE_FILE);
    2.77 -					}
    2.78 -				},
    2.79 +			@Override
    2.80 +			public void showInfo(InfoLister infoLister) {
    2.81 +				infoLister.printResource(Constants.LICENSE_FILE);
    2.82 +			}
    2.83 +		},
    2.84  		JAVA_PROPERTIES {
    2.85 -					@Override
    2.86 -					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
    2.87 -						infoLister.listJavaProperties();
    2.88 -					}
    2.89 -				},
    2.90 +			@Override
    2.91 +			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
    2.92 +				infoLister.listJavaProperties();
    2.93 +			}
    2.94 +		},
    2.95  		ENVIRONMENT_VARIABLES {
    2.96 -					@Override
    2.97 -					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
    2.98 -						infoLister.listEnvironmentVariables();
    2.99 -					}
   2.100 -				},
   2.101 +			@Override
   2.102 +			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.103 +				infoLister.listEnvironmentVariables();
   2.104 +			}
   2.105 +		},
   2.106  		FORMATTERS {
   2.107 -					@Override
   2.108 -					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.109 -						infoLister.listFormatters();
   2.110 -					}
   2.111 -				},
   2.112 +			@Override
   2.113 +			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.114 +				infoLister.listFormatters();
   2.115 +			}
   2.116 +		},
   2.117  		FORMATTER_PROPERTIES {
   2.118 -					@Override
   2.119 -					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.120 -						infoLister.listFormatterProperties();
   2.121 -					}
   2.122 -				},
   2.123 +			@Override
   2.124 +			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.125 +				infoLister.listFormatterProperties();
   2.126 +			}
   2.127 +		},
   2.128  		TYPES {
   2.129 -					@Override
   2.130 -					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.131 -						infoLister.listTypes();
   2.132 -					}
   2.133 -				},
   2.134 +			@Override
   2.135 +			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.136 +				infoLister.listTypes();
   2.137 +			}
   2.138 +		},
   2.139  		JDBC_DRIVERS {
   2.140 -					@Override
   2.141 -					public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException {
   2.142 -						infoLister.listJdbcDrivers();
   2.143 -					}
   2.144 -				},
   2.145 +			@Override
   2.146 +			public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException {
   2.147 +				infoLister.listJdbcDrivers();
   2.148 +			}
   2.149 +		},
   2.150  		JDBC_PROPERTIES {
   2.151 -					@Override
   2.152 -					public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException {
   2.153 -						infoLister.listJdbcProperties();
   2.154 -					}
   2.155 -				},
   2.156 +			@Override
   2.157 +			public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException {
   2.158 +				infoLister.listJdbcProperties();
   2.159 +			}
   2.160 +		},
   2.161  		DATABASES {
   2.162 -					@Override
   2.163 -					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.164 -						infoLister.listDatabases();
   2.165 -					}
   2.166 -				},
   2.167 +			@Override
   2.168 +			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.169 +				infoLister.listDatabases();
   2.170 +			}
   2.171 +		},
   2.172  		CONNECTION {
   2.173 -					@Override
   2.174 -					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.175 -						infoLister.testConnections();
   2.176 -					}
   2.177 -				};
   2.178 +			@Override
   2.179 +			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   2.180 +				infoLister.testConnections();
   2.181 +			}
   2.182 +		};
   2.183  
   2.184  		public abstract void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException;
   2.185  	}