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