java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 15 Aug 2015 11:07:50 +0200
branchv_0
changeset 211 b5148f646278
parent 210 f8aa3686d512
child 212 d154d6012cbe
permissions -rw-r--r--
property annotations: dummy InfoLister table
     1 /**
     2  * SQL-DK
     3  * Copyright © 2013 František Kučera (frantovo.cz)
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, either version 3 of the License, or
     8  * (at your option) any later version.
     9  *
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  * GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 package info.globalcode.sql.dk;
    19 
    20 import info.globalcode.sql.dk.configuration.CommandArgument;
    21 import info.globalcode.sql.dk.configuration.Configuration;
    22 import info.globalcode.sql.dk.configuration.ConfigurationException;
    23 import info.globalcode.sql.dk.configuration.ConfigurationProvider;
    24 import info.globalcode.sql.dk.configuration.DatabaseDefinition;
    25 import info.globalcode.sql.dk.configuration.FormatterDefinition;
    26 import info.globalcode.sql.dk.configuration.Properties;
    27 import info.globalcode.sql.dk.configuration.Property;
    28 import info.globalcode.sql.dk.configuration.TunnelDefinition;
    29 import info.globalcode.sql.dk.formatting.ColumnsHeader;
    30 import info.globalcode.sql.dk.formatting.FakeSqlArray;
    31 import info.globalcode.sql.dk.formatting.Formatter;
    32 import info.globalcode.sql.dk.formatting.FormatterContext;
    33 import info.globalcode.sql.dk.formatting.FormatterException;
    34 import java.io.BufferedReader;
    35 import java.io.ByteArrayOutputStream;
    36 import java.io.InputStreamReader;
    37 import java.io.PrintStream;
    38 import java.sql.Array;
    39 import java.sql.Driver;
    40 import java.sql.DriverManager;
    41 import java.sql.DriverPropertyInfo;
    42 import java.sql.SQLException;
    43 import java.util.ArrayList;
    44 import java.util.Collections;
    45 import java.util.Comparator;
    46 import java.util.EnumSet;
    47 import java.util.HashSet;
    48 import java.util.List;
    49 import java.util.Map.Entry;
    50 import java.util.ServiceLoader;
    51 import java.util.Set;
    52 import java.util.concurrent.ExecutorService;
    53 import java.util.concurrent.Executors;
    54 import java.util.concurrent.TimeUnit;
    55 import java.util.logging.Level;
    56 import java.util.logging.LogRecord;
    57 import java.util.logging.Logger;
    58 import javax.sql.rowset.RowSetMetaDataImpl;
    59 
    60 /**
    61  * Displays info like help, version etc.
    62  *
    63  * @author Ing. František Kučera (frantovo.cz)
    64  */
    65 public class InfoLister {
    66 
    67 	private static final Logger log = Logger.getLogger(InfoLister.class.getName());
    68 	/**
    69 	 * Fake database name for output formatting
    70 	 */
    71 	public static final String CONFIG_DB_NAME = "sqldk_configuration";
    72 	private final PrintStream out;
    73 	private final ConfigurationProvider configurationProvider;
    74 	private final CLIOptions options;
    75 	private Formatter formatter;
    76 
    77 	public InfoLister(PrintStream out, ConfigurationProvider configurationProvider, CLIOptions options) {
    78 		this.out = out;
    79 		this.configurationProvider = configurationProvider;
    80 		this.options = options;
    81 	}
    82 
    83 	public void showInfo() throws ConfigurationException, FormatterException {
    84 		EnumSet<InfoType> commands = options.getShowInfo();
    85 
    86 		boolean formattinNeeded = false;
    87 
    88 		for (InfoType infoType : commands) {
    89 			switch (infoType) {
    90 				case CONNECTION:
    91 				case JDBC_DRIVERS:
    92 				case JDBC_PROPERTIES:
    93 				case DATABASES:
    94 				case FORMATTERS:
    95 				case FORMATTER_PROPERTIES:
    96 				case TYPES:
    97 				case JAVA_PROPERTIES:
    98 				case ENVIRONMENT_VARIABLES:
    99 					formattinNeeded = true;
   100 					break;
   101 			}
   102 		}
   103 
   104 		if (formattinNeeded) {
   105 			try (Formatter f = getFormatter()) {
   106 				formatter = f;
   107 				formatter.writeStartBatch();
   108 				DatabaseDefinition dd = new DatabaseDefinition();
   109 				dd.setName(CONFIG_DB_NAME);
   110 				formatter.writeStartDatabase(dd);
   111 				showInfos(commands);
   112 				formatter.writeEndDatabase();
   113 				formatter.writeEndBatch();
   114 				formatter.close();
   115 			}
   116 		} else {
   117 			showInfos(commands);
   118 		}
   119 	}
   120 
   121 	private void showInfos(EnumSet<InfoType> commands) throws ConfigurationException, FormatterException {
   122 		for (InfoType infoType : commands) {
   123 			infoType.showInfo(this);
   124 		}
   125 	}
   126 
   127 	private void listJavaProperties() throws FormatterException, ConfigurationException {
   128 		ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("value", SQLType.VARCHAR));
   129 		List<Object[]> data = new ArrayList<>();
   130 		for (Entry<Object, Object> e : System.getProperties().entrySet()) {
   131 			data.add(new Object[]{e.getKey(), e.getValue()});
   132 		}
   133 		printTable(formatter, header, "-- Java system properties", null, data, 0);
   134 	}
   135 
   136 	private void listEnvironmentVariables() throws FormatterException, ConfigurationException {
   137 		ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("value", SQLType.VARCHAR));
   138 		List<Object[]> data = new ArrayList<>();
   139 		for (Entry<String, String> e : System.getenv().entrySet()) {
   140 			data.add(new Object[]{e.getKey(), e.getValue()});
   141 		}
   142 		printTable(formatter, header, "-- environment variables", null, data, 0);
   143 	}
   144 
   145 	private void listFormatters() throws ConfigurationException, FormatterException {
   146 		ColumnsHeader header = constructHeader(
   147 				new HeaderField("name", SQLType.VARCHAR),
   148 				new HeaderField("built_in", SQLType.BOOLEAN),
   149 				new HeaderField("default", SQLType.BOOLEAN),
   150 				new HeaderField("class_name", SQLType.VARCHAR),
   151 				new HeaderField("valid", SQLType.BOOLEAN));
   152 		List<Object[]> data = new ArrayList<>();
   153 
   154 		String defaultFormatter = configurationProvider.getConfiguration().getDefaultFormatter();
   155 		defaultFormatter = defaultFormatter == null ? Configuration.DEFAULT_FORMATTER : defaultFormatter;
   156 
   157 		for (FormatterDefinition fd : configurationProvider.getConfiguration().getBuildInFormatters()) {
   158 			data.add(new Object[]{fd.getName(), true, defaultFormatter.equals(fd.getName()), fd.getClassName(), isInstantiable(fd)});
   159 		}
   160 
   161 		for (FormatterDefinition fd : configurationProvider.getConfiguration().getFormatters()) {
   162 			data.add(new Object[]{fd.getName(), false, defaultFormatter.equals(fd.getName()), fd.getClassName(), isInstantiable(fd)});
   163 		}
   164 
   165 		printTable(formatter, header, "-- configured and built-in output formatters", null, data);
   166 	}
   167 
   168 	private boolean isInstantiable(FormatterDefinition fd) {
   169 		try {
   170 			try (ByteArrayOutputStream testStream = new ByteArrayOutputStream()) {
   171 				fd.getInstance(new FormatterContext(testStream, new Properties(0)));
   172 				return true;
   173 			}
   174 		} catch (Exception e) {
   175 			log.log(Level.SEVERE, "Unable to create an instance of formatter: " + fd.getName(), e);
   176 			return false;
   177 		}
   178 	}
   179 
   180 	private void listFormatterProperties() throws FormatterException, ConfigurationException {
   181 		for (String formatterName : options.getFormatterNamesToListProperties()) {
   182 			listFormatterProperties(formatterName);
   183 		}
   184 	}
   185 
   186 	private void listFormatterProperties(String formatterName) throws FormatterException, ConfigurationException {
   187 		ColumnsHeader header = constructHeader(
   188 				new HeaderField("name", SQLType.VARCHAR),
   189 				new HeaderField("type", SQLType.VARCHAR),
   190 				new HeaderField("default", SQLType.VARCHAR),
   191 				new HeaderField("description", SQLType.VARCHAR)
   192 		);
   193 		List<Object[]> data = new ArrayList<>();
   194 
   195 		data.add(new Object[]{"TODO", "a", "b", "c"});
   196 		data.add(new Object[]{"TODO", "a", "b", "c"});
   197 		data.add(new Object[]{"TODO", "a", "b", "c"});
   198 		data.add(new Object[]{"TODO", "a", "b", "c"});
   199 
   200 		List<Parameter> parameters = new ArrayList<>();
   201 		parameters.add(new NamedParameter("formatter", formatterName, SQLType.VARCHAR));
   202 
   203 		printTable(formatter, header, "-- formatter properties", parameters, data);
   204 	}
   205 
   206 	private void listTypes() throws FormatterException, ConfigurationException {
   207 		ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER));
   208 		List<Object[]> data = new ArrayList<>();
   209 		for (SQLType sqlType : SQLType.values()) {
   210 			data.add(new Object[]{sqlType.name(), sqlType.getCode()});
   211 		}
   212 		printTable(formatter, header, "-- data types", null, data);
   213 		log.log(Level.INFO, "Type names in --types option are case insensitive");
   214 	}
   215 
   216 	private void listDatabases() throws ConfigurationException, FormatterException {
   217 		ColumnsHeader header = constructHeader(
   218 				new HeaderField("database_name", SQLType.VARCHAR),
   219 				new HeaderField("user_name", SQLType.VARCHAR),
   220 				new HeaderField("database_url", SQLType.VARCHAR));
   221 		List<Object[]> data = new ArrayList<>();
   222 
   223 		final List<DatabaseDefinition> configuredDatabases = configurationProvider.getConfiguration().getDatabases();
   224 		if (configuredDatabases.isEmpty()) {
   225 			log.log(Level.WARNING, "No databases are configured.");
   226 		} else {
   227 			for (DatabaseDefinition dd : configuredDatabases) {
   228 				data.add(new Object[]{dd.getName(), dd.getUserName(), dd.getUrl()});
   229 
   230 				final TunnelDefinition tunnel = dd.getTunnel();
   231 				if (tunnel != null) {
   232 					log.log(Level.INFO, "Tunnel command: {0}", tunnel.getCommand());
   233 					for (CommandArgument ca : Functions.notNull(tunnel.getArguments())) {
   234 						log.log(Level.INFO, "\targument: {0}/{1}", new Object[]{ca.getType(), ca.getValue()});
   235 					}
   236 				}
   237 
   238 			}
   239 		}
   240 
   241 		printTable(formatter, header, "-- configured databases", null, data);
   242 	}
   243 
   244 	private void listJdbcDrivers() throws FormatterException, ConfigurationException {
   245 		ColumnsHeader header = constructHeader(
   246 				new HeaderField("class", SQLType.VARCHAR),
   247 				new HeaderField("version", SQLType.VARCHAR),
   248 				new HeaderField("major", SQLType.INTEGER),
   249 				new HeaderField("minor", SQLType.INTEGER),
   250 				new HeaderField("jdbc_compliant", SQLType.BOOLEAN));
   251 		List<Object[]> data = new ArrayList<>();
   252 
   253 		final ServiceLoader<Driver> drivers = ServiceLoader.load(Driver.class);
   254 		for (Driver d : drivers) {
   255 			data.add(new Object[]{
   256 				d.getClass().getName(),
   257 				d.getMajorVersion() + "." + d.getMinorVersion(),
   258 				d.getMajorVersion(),
   259 				d.getMinorVersion(),
   260 				d.jdbcCompliant()
   261 			});
   262 		}
   263 
   264 		printTable(formatter, header, "-- discovered JDBC drivers (available on the CLASSPATH)", null, data);
   265 	}
   266 
   267 	private void listJdbcProperties() throws FormatterException, ConfigurationException {
   268 		for (String dbName : options.getDatabaseNamesToListProperties()) {
   269 			ColumnsHeader header = constructHeader(
   270 					new HeaderField("property_name", SQLType.VARCHAR),
   271 					new HeaderField("required", SQLType.BOOLEAN),
   272 					new HeaderField("choices", SQLType.ARRAY),
   273 					new HeaderField("configured_value", SQLType.VARCHAR),
   274 					new HeaderField("description", SQLType.VARCHAR));
   275 			List<Object[]> data = new ArrayList<>();
   276 
   277 			DatabaseDefinition dd = configurationProvider.getConfiguration().getDatabase(dbName);
   278 
   279 			Driver driver = findDriver(dd);
   280 
   281 			if (driver == null) {
   282 				log.log(Level.WARNING, "No JDBC driver was found for DB: {0} with URL: {1}", new Object[]{dd.getName(), dd.getUrl()});
   283 			} else {
   284 				log.log(Level.INFO, "For DB: {0} was found JDBC driver: {1}", new Object[]{dd.getName(), driver.getClass().getName()});
   285 
   286 				try {
   287 					DriverPropertyInfo[] propertyInfos = driver.getPropertyInfo(dd.getUrl(), dd.getProperties().getJavaProperties());
   288 
   289 					Set<String> standardProperties = new HashSet<>();
   290 
   291 					for (DriverPropertyInfo pi : propertyInfos) {
   292 						Array choices = new FakeSqlArray(pi.choices, SQLType.VARCHAR);
   293 						data.add(new Object[]{
   294 							pi.name,
   295 							pi.required,
   296 							choices.getArray() == null ? "" : choices,
   297 							pi.value == null ? "" : pi.value,
   298 							pi.description
   299 						});
   300 						standardProperties.add(pi.name);
   301 					}
   302 
   303 					for (Property p : dd.getProperties()) {
   304 						if (!standardProperties.contains(p.getName())) {
   305 							data.add(new Object[]{
   306 								p.getName(),
   307 								"",
   308 								"",
   309 								p.getValue(),
   310 								""
   311 							});
   312 							log.log(Level.WARNING, "Your configuration contains property „{0}“ not declared by the JDBC driver.", p.getName());
   313 						}
   314 					}
   315 
   316 				} catch (SQLException e) {
   317 					log.log(Level.WARNING, "Error during getting property infos.", e);
   318 				}
   319 
   320 				List<Parameter> parameters = new ArrayList<>();
   321 				parameters.add(new NamedParameter("database", dbName, SQLType.VARCHAR));
   322 				parameters.add(new NamedParameter("driver_class", driver.getClass().getName(), SQLType.VARCHAR));
   323 				parameters.add(new NamedParameter("driver_major_version", driver.getMajorVersion(), SQLType.INTEGER));
   324 				parameters.add(new NamedParameter("driver_minor_version", driver.getMinorVersion(), SQLType.INTEGER));
   325 
   326 				printTable(formatter, header, "-- configured and configurable JDBC driver properties", parameters, data);
   327 			}
   328 		}
   329 
   330 	}
   331 
   332 	private Driver findDriver(DatabaseDefinition dd) {
   333 		final ServiceLoader<Driver> drivers = ServiceLoader.load(Driver.class);
   334 		for (Driver d : drivers) {
   335 			try {
   336 				if (d.acceptsURL(dd.getUrl())) {
   337 					return d;
   338 				}
   339 			} catch (SQLException e) {
   340 				log.log(Level.WARNING, "Error during finding JDBC driver for: " + dd.getName(), e);
   341 			}
   342 		}
   343 		return null;
   344 	}
   345 
   346 	/**
   347 	 * Parallelism for connection testing – maximum concurrent database connections.
   348 	 */
   349 	private static final int TESTING_THREAD_COUNT = 64;
   350 	/**
   351 	 * Time limit for all connection testing threads – particular timeouts per connection will be
   352 	 * much smaller.
   353 	 */
   354 	private static final long TESTING_AWAIT_LIMIT = 1;
   355 	private static final TimeUnit TESTING_AWAIT_UNIT = TimeUnit.DAYS;
   356 
   357 	private void testConnections() throws FormatterException, ConfigurationException {
   358 		ColumnsHeader header = constructHeader(
   359 				new HeaderField("database_name", SQLType.VARCHAR),
   360 				new HeaderField("configured", SQLType.BOOLEAN),
   361 				new HeaderField("connected", SQLType.BOOLEAN));
   362 
   363 		log.log(Level.FINE, "Testing DB connections in {0} threads", TESTING_THREAD_COUNT);
   364 
   365 		ExecutorService es = Executors.newFixedThreadPool(TESTING_THREAD_COUNT);
   366 
   367 		final Formatter currentFormatter = formatter;
   368 
   369 		printHeader(currentFormatter, header, "-- database configuration and connectivity test", null);
   370 
   371 		for (final String dbName : options.getDatabaseNamesToTest()) {
   372 			preloadDriver(dbName);
   373 		}
   374 
   375 		for (final String dbName : options.getDatabaseNamesToTest()) {
   376 			es.submit(() -> {
   377 				final Object[] row = testConnection(dbName);
   378 				synchronized (currentFormatter) {
   379 					printRow(currentFormatter, row);
   380 				}
   381 			}
   382 			);
   383 		}
   384 
   385 		es.shutdown();
   386 
   387 		try {
   388 			log.log(Level.FINEST, "Waiting for test results: {0} {1}", new Object[]{TESTING_AWAIT_LIMIT, TESTING_AWAIT_UNIT.name()});
   389 			boolean finished = es.awaitTermination(TESTING_AWAIT_LIMIT, TESTING_AWAIT_UNIT);
   390 			if (finished) {
   391 				log.log(Level.FINEST, "All testing threads finished in time limit.");
   392 			} else {
   393 				throw new FormatterException("Exceeded total time limit for test threads – this should never happen");
   394 			}
   395 		} catch (InterruptedException e) {
   396 			throw new FormatterException("Interrupted while waiting for test results", e);
   397 		}
   398 
   399 		printFooter(currentFormatter);
   400 	}
   401 
   402 	/**
   403 	 * JDBC driver classes should be preloaded in single thread to avoid deadlocks while doing
   404 	 * {@linkplain DriverManager#registerDriver(java.sql.Driver)} during parallel connections.
   405 	 *
   406 	 * @param dbName
   407 	 */
   408 	private void preloadDriver(String dbName) {
   409 		try {
   410 			DatabaseDefinition dd = configurationProvider.getConfiguration().getDatabase(dbName);
   411 			Driver driver = findDriver(dd);
   412 			if (driver == null) {
   413 				log.log(Level.WARNING, "No Driver found for DB: {0}", dbName);
   414 			} else {
   415 				log.log(Level.FINEST, "Driver preloading for DB: {0} was successfull", dbName);
   416 			}
   417 		} catch (Exception e) {
   418 			LogRecord r = new LogRecord(Level.WARNING, "Failed to preload the Driver for DB: {0}");
   419 			r.setParameters(new Object[]{dbName});
   420 			r.setThrown(e);
   421 			log.log(r);
   422 		}
   423 	}
   424 
   425 	private Object[] testConnection(String dbName) {
   426 		log.log(Level.FINE, "Testing connection to database: {0}", dbName);
   427 
   428 		boolean succesfullyConnected = false;
   429 		boolean succesfullyConfigured = false;
   430 
   431 		try {
   432 			DatabaseDefinition dd = configurationProvider.getConfiguration().getDatabase(dbName);
   433 			log.log(Level.FINE, "Database definition was loaded from configuration");
   434 			succesfullyConfigured = true;
   435 			try (DatabaseConnection dc = dd.connect(options.getDatabaseProperties())) {
   436 				succesfullyConnected = dc.test();
   437 			}
   438 			log.log(Level.FINE, "Database connection test was successful");
   439 		} catch (ConfigurationException | SQLException | RuntimeException e) {
   440 			log.log(Level.SEVERE, "Error during testing connection " + dbName, e);
   441 		}
   442 
   443 		return new Object[]{dbName, succesfullyConfigured, succesfullyConnected};
   444 	}
   445 
   446 	private void printResource(String fileName) {
   447 		try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(fileName)))) {
   448 			while (true) {
   449 				String line = reader.readLine();
   450 				if (line == null) {
   451 					break;
   452 				} else {
   453 					println(line);
   454 				}
   455 			}
   456 		} catch (Exception e) {
   457 			log.log(Level.SEVERE, "Unable to print this info. Please see our website for it: " + Constants.WEBSITE, e);
   458 		}
   459 	}
   460 
   461 	private void println(String line) {
   462 		out.println(line);
   463 	}
   464 
   465 	private void printTable(Formatter formatter, ColumnsHeader header, String sql, List<Parameter> parameters, List<Object[]> data) throws ConfigurationException, FormatterException {
   466 		printTable(formatter, header, sql, parameters, data, null);
   467 	}
   468 
   469 	private void printTable(Formatter formatter, ColumnsHeader header, String sql, List<Parameter> parameters, List<Object[]> data, final Integer sortByColumn) throws ConfigurationException, FormatterException {
   470 		printHeader(formatter, header, sql, parameters);
   471 
   472 		if (sortByColumn != null) {
   473 			Collections.sort(data, new Comparator<Object[]>() {
   474 
   475 				@Override
   476 				public int compare(Object[] o1, Object[] o2) {
   477 					String s1 = String.valueOf(o1[sortByColumn]);
   478 					String s2 = String.valueOf(o2[sortByColumn]);
   479 					return s1.compareTo(s2);
   480 				}
   481 			});
   482 		}
   483 
   484 		for (Object[] row : data) {
   485 			printRow(formatter, row);
   486 		}
   487 
   488 		printFooter(formatter);
   489 	}
   490 
   491 	private void printHeader(Formatter formatter, ColumnsHeader header, String sql, List<Parameter> parameters) {
   492 		formatter.writeStartStatement();
   493 		if (sql != null) {
   494 			formatter.writeQuery(sql);
   495 			if (parameters != null) {
   496 				formatter.writeParameters(parameters);
   497 			}
   498 		}
   499 		formatter.writeStartResultSet(header);
   500 	}
   501 
   502 	private void printRow(Formatter formatter, Object[] row) {
   503 		formatter.writeStartRow();
   504 		for (Object cell : row) {
   505 			formatter.writeColumnValue(cell);
   506 		}
   507 		formatter.writeEndRow();
   508 	}
   509 
   510 	private void printFooter(Formatter formatter) {
   511 		formatter.writeEndResultSet();
   512 		formatter.writeEndStatement();
   513 	}
   514 
   515 	private Formatter getFormatter() throws ConfigurationException, FormatterException {
   516 		String formatterName = options.getFormatterName();
   517 		formatterName = formatterName == null ? Configuration.DEFAULT_FORMATTER_PREFETCHING : formatterName;
   518 		FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName);
   519 		FormatterContext context = new FormatterContext(out, options.getFormatterProperties());
   520 		return fd.getInstance(context);
   521 	}
   522 
   523 	private ColumnsHeader constructHeader(HeaderField... fields) throws FormatterException {
   524 		try {
   525 			RowSetMetaDataImpl metaData = new RowSetMetaDataImpl();
   526 			metaData.setColumnCount(fields.length);
   527 
   528 			for (int i = 0; i < fields.length; i++) {
   529 				HeaderField hf = fields[i];
   530 				int sqlIndex = i + 1;
   531 				metaData.setColumnName(sqlIndex, hf.name);
   532 				metaData.setColumnLabel(sqlIndex, hf.name);
   533 				metaData.setColumnType(sqlIndex, hf.type.getCode());
   534 				metaData.setColumnTypeName(sqlIndex, hf.type.name());
   535 			}
   536 
   537 			return new ColumnsHeader(metaData);
   538 		} catch (SQLException e) {
   539 			throw new FormatterException("Error while constructing table headers", e);
   540 		}
   541 	}
   542 
   543 	private static class HeaderField {
   544 
   545 		String name;
   546 		SQLType type;
   547 
   548 		public HeaderField(String name, SQLType type) {
   549 			this.name = name;
   550 			this.type = type;
   551 		}
   552 	}
   553 
   554 	public enum InfoType {
   555 
   556 		HELP {
   557 					@Override
   558 					public void showInfo(InfoLister infoLister) {
   559 						infoLister.printResource(Constants.HELP_FILE);
   560 					}
   561 				},
   562 		VERSION {
   563 					@Override
   564 					public void showInfo(InfoLister infoLister) {
   565 						infoLister.printResource(Constants.VERSION_FILE);
   566 					}
   567 				},
   568 		LICENSE {
   569 					@Override
   570 					public void showInfo(InfoLister infoLister) {
   571 						infoLister.printResource(Constants.LICENSE_FILE);
   572 					}
   573 				},
   574 		JAVA_PROPERTIES {
   575 					@Override
   576 					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   577 						infoLister.listJavaProperties();
   578 					}
   579 				},
   580 		ENVIRONMENT_VARIABLES {
   581 					@Override
   582 					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   583 						infoLister.listEnvironmentVariables();
   584 					}
   585 				},
   586 		FORMATTERS {
   587 					@Override
   588 					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   589 						infoLister.listFormatters();
   590 					}
   591 				},
   592 		FORMATTER_PROPERTIES {
   593 					@Override
   594 					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   595 						infoLister.listFormatterProperties();
   596 					}
   597 				},
   598 		TYPES {
   599 					@Override
   600 					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   601 						infoLister.listTypes();
   602 					}
   603 				},
   604 		JDBC_DRIVERS {
   605 					@Override
   606 					public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException {
   607 						infoLister.listJdbcDrivers();
   608 					}
   609 				},
   610 		JDBC_PROPERTIES {
   611 					@Override
   612 					public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException {
   613 						infoLister.listJdbcProperties();
   614 					}
   615 				},
   616 		DATABASES {
   617 					@Override
   618 					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   619 						infoLister.listDatabases();
   620 					}
   621 				},
   622 		CONNECTION {
   623 					@Override
   624 					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
   625 						infoLister.testConnections();
   626 					}
   627 				};
   628 
   629 		public abstract void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException;
   630 	}
   631 }