java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
author František Kučera <franta-hg@frantovo.cz>
Wed, 15 Jan 2014 21:26:15 +0100
branchv_0
changeset 160 84ea4a819fb2
parent 159 9632b23df30c
child 161 385929a50dd9
permissions -rw-r--r--
InfoLister: option --list-formatters also tests, if formatter class can be instantiated (thus is valid)
franta-hg@16
     1
/**
franta-hg@16
     2
 * SQL-DK
franta-hg@16
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@16
     4
 *
franta-hg@16
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@16
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@16
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@16
     8
 * (at your option) any later version.
franta-hg@16
     9
 *
franta-hg@16
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@16
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@16
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@16
    13
 * GNU General Public License for more details.
franta-hg@16
    14
 *
franta-hg@16
    15
 * You should have received a copy of the GNU General Public License
franta-hg@16
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@16
    17
 */
franta-hg@14
    18
package info.globalcode.sql.dk;
franta-hg@14
    19
franta-hg@67
    20
import info.globalcode.sql.dk.configuration.Configuration;
franta-hg@65
    21
import info.globalcode.sql.dk.configuration.ConfigurationException;
franta-hg@26
    22
import info.globalcode.sql.dk.configuration.ConfigurationProvider;
franta-hg@65
    23
import info.globalcode.sql.dk.configuration.DatabaseDefinition;
franta-hg@67
    24
import info.globalcode.sql.dk.configuration.FormatterDefinition;
franta-hg@160
    25
import info.globalcode.sql.dk.configuration.Properties;
franta-hg@159
    26
import info.globalcode.sql.dk.configuration.Property;
franta-hg@69
    27
import info.globalcode.sql.dk.formatting.ColumnsHeader;
franta-hg@159
    28
import info.globalcode.sql.dk.formatting.FakeSqlArray;
franta-hg@69
    29
import info.globalcode.sql.dk.formatting.Formatter;
franta-hg@69
    30
import info.globalcode.sql.dk.formatting.FormatterContext;
franta-hg@69
    31
import info.globalcode.sql.dk.formatting.FormatterException;
franta-hg@17
    32
import java.io.BufferedReader;
franta-hg@160
    33
import java.io.ByteArrayInputStream;
franta-hg@160
    34
import java.io.ByteArrayOutputStream;
franta-hg@17
    35
import java.io.InputStreamReader;
franta-hg@14
    36
import java.io.PrintStream;
franta-hg@159
    37
import java.sql.Array;
franta-hg@158
    38
import java.sql.Driver;
franta-hg@159
    39
import java.sql.DriverPropertyInfo;
franta-hg@65
    40
import java.sql.SQLException;
franta-hg@70
    41
import java.util.ArrayList;
franta-hg@70
    42
import java.util.EnumSet;
franta-hg@159
    43
import java.util.HashSet;
franta-hg@66
    44
import java.util.List;
franta-hg@158
    45
import java.util.ServiceLoader;
franta-hg@159
    46
import java.util.Set;
franta-hg@17
    47
import java.util.logging.Level;
franta-hg@17
    48
import java.util.logging.Logger;
franta-hg@69
    49
import javax.sql.rowset.RowSetMetaDataImpl;
franta-hg@14
    50
franta-hg@14
    51
/**
franta-hg@14
    52
 * Displays info like help, version etc.
franta-hg@14
    53
 *
franta-hg@14
    54
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@14
    55
 */
franta-hg@14
    56
public class InfoLister {
franta-hg@14
    57
franta-hg@17
    58
	private static final Logger log = Logger.getLogger(InfoLister.class.getName());
franta-hg@159
    59
	/**
franta-hg@159
    60
	 * Fake database name for output formatting
franta-hg@159
    61
	 */
franta-hg@159
    62
	public static final String CONFIG_DB_NAME = "sqldk_configuration";
franta-hg@17
    63
	private PrintStream out;
franta-hg@20
    64
	private ConfigurationProvider configurationProvider;
franta-hg@69
    65
	private CLIOptions options;
franta-hg@70
    66
	private Formatter formatter;
franta-hg@17
    67
franta-hg@69
    68
	public InfoLister(PrintStream out, ConfigurationProvider configurationProvider, CLIOptions options) {
franta-hg@17
    69
		this.out = out;
franta-hg@20
    70
		this.configurationProvider = configurationProvider;
franta-hg@69
    71
		this.options = options;
franta-hg@17
    72
	}
franta-hg@17
    73
franta-hg@70
    74
	public void showInfo() throws ConfigurationException, FormatterException {
franta-hg@70
    75
		EnumSet<InfoType> commands = options.getShowInfo();
franta-hg@70
    76
franta-hg@139
    77
		boolean formattinNeeded = false;
franta-hg@139
    78
franta-hg@70
    79
		for (InfoType infoType : commands) {
franta-hg@70
    80
			switch (infoType) {
franta-hg@70
    81
				case CONNECTION:
franta-hg@158
    82
				case JDBC_DRIVERS:
franta-hg@159
    83
				case JDBC_PROPERTIES:
franta-hg@70
    84
				case DATABASES:
franta-hg@70
    85
				case FORMATTERS:
franta-hg@70
    86
				case TYPES:
franta-hg@139
    87
					formattinNeeded = true;
franta-hg@101
    88
					break;
franta-hg@70
    89
			}
franta-hg@70
    90
		}
franta-hg@139
    91
franta-hg@139
    92
		if (formattinNeeded) {
franta-hg@139
    93
			try (Formatter f = getFormatter()) {
franta-hg@139
    94
				formatter = f;
franta-hg@139
    95
				formatter.writeStartBatch();
franta-hg@159
    96
				DatabaseDefinition dd = new DatabaseDefinition();
franta-hg@159
    97
				dd.setName(CONFIG_DB_NAME);
franta-hg@159
    98
				formatter.writeStartDatabase(dd);
franta-hg@139
    99
				showInfos(commands);
franta-hg@139
   100
				formatter.writeEndDatabase();
franta-hg@139
   101
				formatter.writeEndBatch();
franta-hg@139
   102
				formatter.close();
franta-hg@139
   103
			}
franta-hg@139
   104
		} else {
franta-hg@139
   105
			showInfos(commands);
franta-hg@139
   106
		}
franta-hg@101
   107
	}
franta-hg@70
   108
franta-hg@101
   109
	private void showInfos(EnumSet<InfoType> commands) throws ConfigurationException, FormatterException {
franta-hg@70
   110
		for (InfoType infoType : commands) {
franta-hg@70
   111
			infoType.showInfo(this);
franta-hg@70
   112
		}
franta-hg@70
   113
	}
franta-hg@70
   114
franta-hg@72
   115
	private void listFormatters() throws ConfigurationException, FormatterException {
franta-hg@72
   116
		ColumnsHeader header = constructHeader(
franta-hg@72
   117
				new HeaderField("name", SQLType.VARCHAR),
franta-hg@72
   118
				new HeaderField("built_in", SQLType.BOOLEAN),
franta-hg@72
   119
				new HeaderField("default", SQLType.BOOLEAN),
franta-hg@160
   120
				new HeaderField("class_name", SQLType.VARCHAR),
franta-hg@160
   121
				new HeaderField("valid", SQLType.BOOLEAN));
franta-hg@72
   122
		List<Object[]> data = new ArrayList<>();
franta-hg@72
   123
franta-hg@72
   124
		String defaultFormatter = configurationProvider.getConfiguration().getDefaultFormatter();
franta-hg@72
   125
		defaultFormatter = defaultFormatter == null ? Configuration.DEFAULT_FORMATTER : defaultFormatter;
franta-hg@72
   126
franta-hg@69
   127
		for (FormatterDefinition fd : configurationProvider.getConfiguration().getBuildInFormatters()) {
franta-hg@160
   128
			data.add(new Object[]{fd.getName(), true, defaultFormatter.equals(fd.getName()), fd.getClassName(), isInstantiable(fd)});
franta-hg@69
   129
		}
franta-hg@72
   130
franta-hg@72
   131
		for (FormatterDefinition fd : configurationProvider.getConfiguration().getFormatters()) {
franta-hg@160
   132
			data.add(new Object[]{fd.getName(), false, defaultFormatter.equals(fd.getName()), fd.getClassName(), isInstantiable(fd)});
franta-hg@69
   133
		}
franta-hg@72
   134
franta-hg@159
   135
		printTable(formatter, header, data, "-- configured and built-in output formatters", null);
franta-hg@160
   136
	}
franta-hg@72
   137
franta-hg@160
   138
	private boolean isInstantiable(FormatterDefinition fd) {
franta-hg@160
   139
		try {
franta-hg@160
   140
			try (ByteArrayOutputStream testStream = new ByteArrayOutputStream()) {
franta-hg@160
   141
				fd.getInstance(new FormatterContext(testStream, new Properties(0)));
franta-hg@160
   142
				return true;
franta-hg@160
   143
			}
franta-hg@160
   144
		} catch (Exception e) {
franta-hg@160
   145
			log.log(Level.SEVERE, "Unable to create an instance of formatter: " + fd.getName(), e);
franta-hg@160
   146
			return false;
franta-hg@160
   147
		}
franta-hg@69
   148
	}
franta-hg@67
   149
franta-hg@70
   150
	public void listTypes() throws FormatterException, ConfigurationException {
franta-hg@70
   151
		ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER));
franta-hg@70
   152
		List<Object[]> data = new ArrayList<>();
franta-hg@70
   153
		for (SQLType sqlType : SQLType.values()) {
franta-hg@70
   154
			data.add(new Object[]{sqlType.name(), sqlType.getCode()});
franta-hg@70
   155
		}
franta-hg@159
   156
		printTable(formatter, header, data, "-- data types", null);
franta-hg@93
   157
		log.log(Level.INFO, "Type names in --types option are case insensitive");
franta-hg@69
   158
	}
franta-hg@67
   159
franta-hg@72
   160
	public void listDatabases() throws ConfigurationException, FormatterException {
franta-hg@72
   161
		ColumnsHeader header = constructHeader(
franta-hg@72
   162
				new HeaderField("database_name", SQLType.VARCHAR),
franta-hg@72
   163
				new HeaderField("user_name", SQLType.VARCHAR),
franta-hg@72
   164
				new HeaderField("database_url", SQLType.VARCHAR));
franta-hg@72
   165
		List<Object[]> data = new ArrayList<>();
franta-hg@72
   166
franta-hg@69
   167
		final List<DatabaseDefinition> configuredDatabases = configurationProvider.getConfiguration().getDatabases();
franta-hg@69
   168
		if (configuredDatabases.isEmpty()) {
franta-hg@69
   169
			log.log(Level.WARNING, "No databases are configured.");
franta-hg@69
   170
		} else {
franta-hg@69
   171
			for (DatabaseDefinition dd : configuredDatabases) {
franta-hg@72
   172
				data.add(new Object[]{dd.getName(), dd.getUserName(), dd.getUrl()});
franta-hg@14
   173
			}
franta-hg@14
   174
		}
franta-hg@72
   175
franta-hg@159
   176
		printTable(formatter, header, data, "-- configured databases", null);
franta-hg@14
   177
	}
franta-hg@17
   178
franta-hg@158
   179
	public void listJdbcDrivers() throws FormatterException, ConfigurationException {
franta-hg@158
   180
		ColumnsHeader header = constructHeader(
franta-hg@158
   181
				new HeaderField("class", SQLType.VARCHAR),
franta-hg@158
   182
				new HeaderField("version", SQLType.VARCHAR),
franta-hg@158
   183
				new HeaderField("major", SQLType.INTEGER),
franta-hg@158
   184
				new HeaderField("minor", SQLType.INTEGER),
franta-hg@158
   185
				new HeaderField("jdbc_compliant", SQLType.BOOLEAN));
franta-hg@158
   186
		List<Object[]> data = new ArrayList<>();
franta-hg@158
   187
franta-hg@158
   188
		final ServiceLoader<Driver> drivers = ServiceLoader.load(Driver.class);
franta-hg@158
   189
		for (Driver d : drivers) {
franta-hg@158
   190
			data.add(new Object[]{
franta-hg@158
   191
				d.getClass().getName(),
franta-hg@158
   192
				d.getMajorVersion() + "." + d.getMinorVersion(),
franta-hg@158
   193
				d.getMajorVersion(),
franta-hg@158
   194
				d.getMinorVersion(),
franta-hg@159
   195
				d.jdbcCompliant()
franta-hg@159
   196
			});
franta-hg@158
   197
		}
franta-hg@158
   198
franta-hg@159
   199
		printTable(formatter, header, data, "-- discovered JDBC drivers (available on the CLASSPATH)", null);
franta-hg@159
   200
	}
franta-hg@158
   201
franta-hg@159
   202
	public void listJdbcProperties() throws FormatterException, ConfigurationException {
franta-hg@159
   203
		for (String dbName : options.getDatabaseNamesToListProperties()) {
franta-hg@159
   204
			ColumnsHeader header = constructHeader(
franta-hg@159
   205
					new HeaderField("property_name", SQLType.VARCHAR),
franta-hg@159
   206
					new HeaderField("required", SQLType.BOOLEAN),
franta-hg@159
   207
					new HeaderField("choices", SQLType.ARRAY),
franta-hg@159
   208
					new HeaderField("configured_value", SQLType.VARCHAR),
franta-hg@159
   209
					new HeaderField("description", SQLType.VARCHAR));
franta-hg@159
   210
			List<Object[]> data = new ArrayList<>();
franta-hg@159
   211
franta-hg@159
   212
			DatabaseDefinition dd = configurationProvider.getConfiguration().getDatabase(dbName);
franta-hg@159
   213
franta-hg@159
   214
			Driver driver = findDriver(dd);
franta-hg@159
   215
franta-hg@159
   216
			if (driver == null) {
franta-hg@159
   217
				log.log(Level.WARNING, "No JDBC driver was found for DB: {0} with URL: {1}", new Object[]{dd.getName(), dd.getUrl()});
franta-hg@159
   218
			} else {
franta-hg@159
   219
				log.log(Level.INFO, "For DB: {0} was found JDBC driver: {1}", new Object[]{dd.getName(), driver.getClass().getName()});
franta-hg@159
   220
franta-hg@159
   221
				try {
franta-hg@159
   222
					DriverPropertyInfo[] propertyInfos = driver.getPropertyInfo(dd.getUrl(), dd.getProperties().getJavaProperties());
franta-hg@159
   223
franta-hg@159
   224
					Set<String> standardProperties = new HashSet<>();
franta-hg@159
   225
franta-hg@159
   226
					for (DriverPropertyInfo pi : propertyInfos) {
franta-hg@159
   227
						Array choices = new FakeSqlArray(pi.choices, SQLType.VARCHAR);
franta-hg@159
   228
						data.add(new Object[]{
franta-hg@159
   229
							pi.name,
franta-hg@159
   230
							pi.required,
franta-hg@159
   231
							choices.getArray() == null ? "" : choices,
franta-hg@159
   232
							pi.value == null ? "" : pi.value,
franta-hg@159
   233
							pi.description
franta-hg@159
   234
						});
franta-hg@159
   235
						standardProperties.add(pi.name);
franta-hg@159
   236
					}
franta-hg@159
   237
franta-hg@159
   238
					for (Property p : dd.getProperties()) {
franta-hg@159
   239
						if (!standardProperties.contains(p.getName())) {
franta-hg@159
   240
							data.add(new Object[]{
franta-hg@159
   241
								p.getName(),
franta-hg@159
   242
								"",
franta-hg@159
   243
								"",
franta-hg@159
   244
								p.getValue(),
franta-hg@159
   245
								""
franta-hg@159
   246
							});
franta-hg@159
   247
							log.log(Level.WARNING, "Your configuration contains property „{0}“ not declared by the JDBC driver.", p.getName());
franta-hg@159
   248
						}
franta-hg@159
   249
					}
franta-hg@159
   250
franta-hg@159
   251
				} catch (SQLException e) {
franta-hg@159
   252
					log.log(Level.WARNING, "Error during getting property infos.", e);
franta-hg@159
   253
				}
franta-hg@159
   254
franta-hg@159
   255
				List<Parameter> parameters = new ArrayList<>();
franta-hg@159
   256
				parameters.add(new NamedParameter("databgase", dbName, SQLType.VARCHAR));
franta-hg@159
   257
				parameters.add(new NamedParameter("driver_class", driver.getClass().getName(), SQLType.VARCHAR));
franta-hg@159
   258
				parameters.add(new NamedParameter("driver_major_version", driver.getMajorVersion(), SQLType.INTEGER));
franta-hg@159
   259
				parameters.add(new NamedParameter("driver_minor_version", driver.getMinorVersion(), SQLType.INTEGER));
franta-hg@159
   260
franta-hg@159
   261
				printTable(formatter, header, data, "-- configured and configurable JDBC driver properties", parameters);
franta-hg@159
   262
			}
franta-hg@159
   263
		}
franta-hg@159
   264
franta-hg@159
   265
	}
franta-hg@159
   266
franta-hg@159
   267
	private Driver findDriver(DatabaseDefinition dd) {
franta-hg@159
   268
		final ServiceLoader<Driver> drivers = ServiceLoader.load(Driver.class);
franta-hg@159
   269
		for (Driver d : drivers) {
franta-hg@159
   270
			try {
franta-hg@159
   271
				if (d.acceptsURL(dd.getUrl())) {
franta-hg@159
   272
					return d;
franta-hg@159
   273
				}
franta-hg@159
   274
			} catch (SQLException e) {
franta-hg@159
   275
				log.log(Level.WARNING, "Error during finding JDBC driver for: " + dd.getName(), e);
franta-hg@159
   276
			}
franta-hg@159
   277
		}
franta-hg@159
   278
		return null;
franta-hg@158
   279
	}
franta-hg@158
   280
franta-hg@73
   281
	public void testConnection() throws FormatterException, ConfigurationException {
franta-hg@73
   282
		ColumnsHeader header = constructHeader(
franta-hg@73
   283
				new HeaderField("database_name", SQLType.VARCHAR),
franta-hg@74
   284
				new HeaderField("configured", SQLType.BOOLEAN),
franta-hg@74
   285
				new HeaderField("connected", SQLType.BOOLEAN));
franta-hg@73
   286
		List<Object[]> data = new ArrayList<>();
franta-hg@73
   287
franta-hg@155
   288
		for (String dbName : options.getDatabaseNamesToTest()) {
franta-hg@74
   289
			data.add(testConnection(dbName));
franta-hg@74
   290
		}
franta-hg@73
   291
franta-hg@159
   292
		printTable(formatter, header, data, "-- database configuration and connectivity test", null);
franta-hg@73
   293
	}
franta-hg@73
   294
franta-hg@73
   295
	public Object[] testConnection(String dbName) {
franta-hg@69
   296
		log.log(Level.FINE, "Testing connection to database: {0}", dbName);
franta-hg@73
   297
franta-hg@73
   298
		boolean succesfullyConnected = false;
franta-hg@73
   299
		boolean succesfullyConfigured = false;
franta-hg@73
   300
franta-hg@69
   301
		try {
franta-hg@69
   302
			DatabaseDefinition dd = configurationProvider.getConfiguration().getDatabase(dbName);
franta-hg@75
   303
			log.log(Level.FINE, "Database definition was loaded from configuration");
franta-hg@75
   304
			succesfullyConfigured = true;
franta-hg@106
   305
			try (DatabaseConnection dc = dd.connect(options.getDatabaseProperties())) {
franta-hg@75
   306
				succesfullyConnected = dc.test();
franta-hg@69
   307
			}
franta-hg@75
   308
			log.log(Level.FINE, "Database connection test was successful");
franta-hg@69
   309
		} catch (ConfigurationException | SQLException e) {
franta-hg@69
   310
			log.log(Level.SEVERE, "Error during testing connection", e);
franta-hg@69
   311
		}
franta-hg@73
   312
franta-hg@73
   313
		return new Object[]{dbName, succesfullyConfigured, succesfullyConnected};
franta-hg@69
   314
	}
franta-hg@69
   315
franta-hg@69
   316
	public void printResource(String fileName) {
franta-hg@18
   317
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(fileName)))) {
franta-hg@17
   318
			while (true) {
franta-hg@18
   319
				String line = reader.readLine();
franta-hg@17
   320
				if (line == null) {
franta-hg@17
   321
					break;
franta-hg@17
   322
				} else {
franta-hg@17
   323
					println(line);
franta-hg@17
   324
				}
franta-hg@17
   325
			}
franta-hg@17
   326
		} catch (Exception e) {
franta-hg@18
   327
			log.log(Level.SEVERE, "Unable to print this info. Please see our website for it: " + Constants.WEBSITE, e);
franta-hg@17
   328
		}
franta-hg@17
   329
	}
franta-hg@17
   330
franta-hg@17
   331
	private void println(String line) {
franta-hg@17
   332
		out.println(line);
franta-hg@17
   333
	}
franta-hg@69
   334
franta-hg@159
   335
	private void printTable(Formatter formatter, ColumnsHeader header, List<Object[]> data, String sql, List<Parameter> parameters) throws ConfigurationException, FormatterException {
franta-hg@159
   336
		formatter.writeStartStatement();
franta-hg@159
   337
franta-hg@159
   338
		if (sql != null) {
franta-hg@159
   339
			formatter.writeQuery(sql);
franta-hg@159
   340
			if (parameters != null) {
franta-hg@159
   341
				formatter.writeParameters(parameters);
franta-hg@159
   342
			}
franta-hg@159
   343
		}
franta-hg@159
   344
franta-hg@142
   345
		formatter.writeStartResultSet(header);
franta-hg@69
   346
franta-hg@69
   347
		for (Object[] row : data) {
franta-hg@69
   348
			formatter.writeStartRow();
franta-hg@69
   349
			for (Object cell : row) {
franta-hg@69
   350
				formatter.writeColumnValue(cell);
franta-hg@69
   351
			}
franta-hg@69
   352
			formatter.writeEndRow();
franta-hg@69
   353
		}
franta-hg@69
   354
franta-hg@69
   355
		formatter.writeEndResultSet();
franta-hg@159
   356
		formatter.writeEndStatement();
franta-hg@69
   357
	}
franta-hg@69
   358
franta-hg@69
   359
	private Formatter getFormatter() throws ConfigurationException, FormatterException {
franta-hg@89
   360
		String formatterName = options.getFormatterName();
franta-hg@89
   361
		formatterName = formatterName == null ? Configuration.DEFAULT_FORMATTER_PREFETCHING : formatterName;
franta-hg@89
   362
		FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName);
franta-hg@104
   363
		FormatterContext context = new FormatterContext(out, options.getFormatterProperties());
franta-hg@69
   364
		return fd.getInstance(context);
franta-hg@69
   365
	}
franta-hg@69
   366
franta-hg@69
   367
	private ColumnsHeader constructHeader(HeaderField... fields) throws FormatterException {
franta-hg@69
   368
		try {
franta-hg@69
   369
			RowSetMetaDataImpl metaData = new RowSetMetaDataImpl();
franta-hg@69
   370
			metaData.setColumnCount(fields.length);
franta-hg@69
   371
franta-hg@69
   372
			for (int i = 0; i < fields.length; i++) {
franta-hg@69
   373
				HeaderField hf = fields[i];
franta-hg@69
   374
				int sqlIndex = i + 1;
franta-hg@69
   375
				metaData.setColumnName(sqlIndex, hf.name);
franta-hg@69
   376
				metaData.setColumnLabel(sqlIndex, hf.name);
franta-hg@69
   377
				metaData.setColumnType(sqlIndex, hf.type.getCode());
franta-hg@69
   378
				metaData.setColumnTypeName(sqlIndex, hf.type.name());
franta-hg@69
   379
			}
franta-hg@69
   380
franta-hg@69
   381
			return new ColumnsHeader(metaData);
franta-hg@69
   382
		} catch (SQLException e) {
franta-hg@69
   383
			throw new FormatterException("Error while constructing table headers", e);
franta-hg@69
   384
		}
franta-hg@69
   385
	}
franta-hg@69
   386
franta-hg@69
   387
	private static class HeaderField {
franta-hg@69
   388
franta-hg@69
   389
		String name;
franta-hg@69
   390
		SQLType type;
franta-hg@69
   391
franta-hg@69
   392
		public HeaderField(String name, SQLType type) {
franta-hg@69
   393
			this.name = name;
franta-hg@69
   394
			this.type = type;
franta-hg@69
   395
		}
franta-hg@69
   396
	}
franta-hg@69
   397
franta-hg@69
   398
	public enum InfoType {
franta-hg@69
   399
franta-hg@69
   400
		HELP {
franta-hg@69
   401
			@Override
franta-hg@69
   402
			public void showInfo(InfoLister infoLister) {
franta-hg@69
   403
				infoLister.printResource(Constants.HELP_FILE);
franta-hg@69
   404
			}
franta-hg@69
   405
		},
franta-hg@69
   406
		VERSION {
franta-hg@69
   407
			@Override
franta-hg@69
   408
			public void showInfo(InfoLister infoLister) {
franta-hg@69
   409
				infoLister.printResource(Constants.VERSION_FILE);
franta-hg@69
   410
			}
franta-hg@69
   411
		},
franta-hg@69
   412
		LICENSE {
franta-hg@69
   413
			@Override
franta-hg@69
   414
			public void showInfo(InfoLister infoLister) {
franta-hg@69
   415
				infoLister.printResource(Constants.LICENSE_FILE);
franta-hg@69
   416
			}
franta-hg@69
   417
		},
franta-hg@69
   418
		FORMATTERS {
franta-hg@69
   419
			@Override
franta-hg@70
   420
			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
franta-hg@69
   421
				infoLister.listFormatters();
franta-hg@69
   422
			}
franta-hg@69
   423
		},
franta-hg@69
   424
		TYPES {
franta-hg@69
   425
			@Override
franta-hg@70
   426
			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
franta-hg@69
   427
				infoLister.listTypes();
franta-hg@69
   428
			}
franta-hg@69
   429
		},
franta-hg@158
   430
		JDBC_DRIVERS {
franta-hg@158
   431
			@Override
franta-hg@158
   432
			public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException {
franta-hg@158
   433
				infoLister.listJdbcDrivers();
franta-hg@158
   434
			}
franta-hg@158
   435
		},
franta-hg@159
   436
		JDBC_PROPERTIES {
franta-hg@159
   437
			@Override
franta-hg@159
   438
			public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException {
franta-hg@159
   439
				infoLister.listJdbcProperties();
franta-hg@159
   440
			}
franta-hg@159
   441
		},
franta-hg@69
   442
		DATABASES {
franta-hg@69
   443
			@Override
franta-hg@70
   444
			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
franta-hg@69
   445
				infoLister.listDatabases();
franta-hg@69
   446
			}
franta-hg@69
   447
		},
franta-hg@69
   448
		CONNECTION {
franta-hg@69
   449
			@Override
franta-hg@73
   450
			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
franta-hg@69
   451
				infoLister.testConnection();
franta-hg@69
   452
			}
franta-hg@69
   453
		};
franta-hg@69
   454
franta-hg@69
   455
		public abstract void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException;
franta-hg@69
   456
	}
franta-hg@14
   457
}