java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
author František Kučera <franta-hg@frantovo.cz>
Fri, 10 Jan 2014 23:21:28 +0100
branchv_0
changeset 155 eb3676c6929b
parent 142 da1e38386d84
child 158 770b5009ec42
permissions -rw-r--r--
more JavaDoc
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
67
10c9b9e54622 option --list-formatters – list configured and built-in formatters
František Kučera <franta-hg@frantovo.cz>
parents: 66
diff changeset
    20
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
    21
import info.globalcode.sql.dk.configuration.ConfigurationException;
26
4ec8e5534eb9 configuration basics
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    22
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
    23
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
    24
import info.globalcode.sql.dk.configuration.FormatterDefinition;
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
    25
import info.globalcode.sql.dk.formatting.ColumnsHeader;
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
    26
import info.globalcode.sql.dk.formatting.Formatter;
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
    27
import info.globalcode.sql.dk.formatting.FormatterContext;
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
    28
import info.globalcode.sql.dk.formatting.FormatterException;
17
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    29
import java.io.BufferedReader;
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    30
import java.io.InputStreamReader;
14
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
import java.io.PrintStream;
65
f05be87239ad option --test-connection – tests connection to given database
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
    32
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
    33
import java.util.ArrayList;
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    34
import java.util.EnumSet;
66
6e28893eaada option --list-databases list configured databases
František Kučera <franta-hg@frantovo.cz>
parents: 65
diff changeset
    35
import java.util.List;
17
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    36
import java.util.logging.Level;
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    37
import java.util.logging.Logger;
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
    38
import javax.sql.rowset.RowSetMetaDataImpl;
14
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
/**
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
 * Displays info like help, version etc.
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
 *
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
 * @author Ing. František Kučera (frantovo.cz)
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
 */
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
public class InfoLister {
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
17
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    47
	private static final Logger log = Logger.getLogger(InfoLister.class.getName());
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    48
	private PrintStream out;
20
e225bdcd260e refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    49
	private ConfigurationProvider configurationProvider;
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
    50
	private CLIOptions options;
70
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    51
	private Formatter formatter;
17
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    52
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
    53
	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
    54
		this.out = out;
20
e225bdcd260e refactor, configuration
František Kučera <franta-hg@frantovo.cz>
parents: 19
diff changeset
    55
		this.configurationProvider = configurationProvider;
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
    56
		this.options = options;
17
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    57
	}
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
    58
70
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    59
	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
    60
		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
    61
139
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    62
		boolean formattinNeeded = false;
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    63
70
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    64
		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
    65
			switch (infoType) {
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    66
				case CONNECTION:
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    67
				case DATABASES:
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    68
				case FORMATTERS:
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    69
				case TYPES:
139
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    70
					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
    71
					break;
70
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    72
			}
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    73
		}
139
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    74
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    75
		if (formattinNeeded) {
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    76
			try (Formatter f = getFormatter()) {
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    77
				formatter = f;
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    78
				formatter.writeStartBatch();
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    79
				formatter.writeStartDatabase(new DatabaseDefinition());
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
    80
				formatter.writeStartStatement();
139
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    81
				showInfos(commands);
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
    82
				formatter.writeEndStatement();
139
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    83
				formatter.writeEndDatabase();
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    84
				formatter.writeEndBatch();
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    85
				formatter.close();
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    86
			}
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    87
		} else {
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    88
			showInfos(commands);
5c0e344c3b60 fix InfoLister: squared infos
František Kučera <franta-hg@frantovo.cz>
parents: 106
diff changeset
    89
		}
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
    90
	}
70
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    91
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
    92
	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
    93
		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
    94
			infoType.showInfo(this);
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    95
		}
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    96
	}
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
    97
72
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
    98
	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
    99
		ColumnsHeader header = constructHeader(
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   100
				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
   101
				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
   102
				new HeaderField("default", SQLType.BOOLEAN),
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   103
				new HeaderField("class_name", SQLType.VARCHAR));
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   104
		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
   105
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   106
		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
   107
		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
   108
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   109
		for (FormatterDefinition fd : configurationProvider.getConfiguration().getBuildInFormatters()) {
72
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   110
			data.add(new Object[]{fd.getName(), true, defaultFormatter.equals(fd.getName()), fd.getClassName()});
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   111
		}
72
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   112
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   113
		for (FormatterDefinition fd : configurationProvider.getConfiguration().getFormatters()) {
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   114
			data.add(new Object[]{fd.getName(), false, defaultFormatter.equals(fd.getName()), fd.getClassName()});
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   115
		}
72
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   116
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   117
		printTable(formatter, header, data);
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   118
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   119
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   120
	}
67
10c9b9e54622 option --list-formatters – list configured and built-in formatters
František Kučera <franta-hg@frantovo.cz>
parents: 66
diff changeset
   121
70
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
   122
	public void listTypes() throws FormatterException, ConfigurationException {
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
   123
		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
   124
		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
   125
		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
   126
			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
   127
		}
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
   128
		printTable(formatter, header, data);
93
5a4dbe6f962c Type names in --types option are case insensitive
František Kučera <franta-hg@frantovo.cz>
parents: 91
diff changeset
   129
		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
   130
	}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   131
72
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   132
	public void listDatabases() throws ConfigurationException, FormatterException {
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   133
		ColumnsHeader header = constructHeader(
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   134
				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
   135
				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
   136
				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
   137
		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
   138
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   139
		final List<DatabaseDefinition> configuredDatabases = configurationProvider.getConfiguration().getDatabases();
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   140
		if (configuredDatabases.isEmpty()) {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   141
			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
   142
		} else {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   143
			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
   144
				data.add(new Object[]{dd.getName(), dd.getUserName(), dd.getUrl()});
14
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   145
			}
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   146
		}
72
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   147
fc9fc1f26b88 formatted output for: --list-formatters --list-databases
František Kučera <franta-hg@frantovo.cz>
parents: 70
diff changeset
   148
		printTable(formatter, header, data);
14
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   149
	}
17
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   150
73
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   151
	public void testConnection() throws FormatterException, ConfigurationException {
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   152
		ColumnsHeader header = constructHeader(
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   153
				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
   154
				new HeaderField("configured", SQLType.BOOLEAN),
a8444f6a54f3 allow multiple databases connection test in --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 73
diff changeset
   155
				new HeaderField("connected", SQLType.BOOLEAN));
73
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   156
		List<Object[]> data = new ArrayList<>();
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   157
155
eb3676c6929b more JavaDoc
František Kučera <franta-hg@frantovo.cz>
parents: 142
diff changeset
   158
		for (String dbName : options.getDatabaseNamesToTest()) {
74
a8444f6a54f3 allow multiple databases connection test in --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 73
diff changeset
   159
			data.add(testConnection(dbName));
a8444f6a54f3 allow multiple databases connection test in --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 73
diff changeset
   160
		}
73
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   161
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   162
		printTable(formatter, header, data);
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   163
	}
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   164
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   165
	public Object[] testConnection(String dbName) {
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   166
		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
   167
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   168
		boolean succesfullyConnected = false;
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   169
		boolean succesfullyConfigured = false;
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   170
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   171
		try {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   172
			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
   173
			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
   174
			succesfullyConfigured = true;
106
e9c3583580c8 use database properties
František Kučera <franta-hg@frantovo.cz>
parents: 104
diff changeset
   175
			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
   176
				succesfullyConnected = dc.test();
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   177
			}
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
   178
			log.log(Level.FINE, "Database connection test was successful");
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   179
		} catch (ConfigurationException | SQLException e) {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   180
			log.log(Level.SEVERE, "Error during testing connection", e);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   181
		}
73
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   182
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   183
		return new Object[]{dbName, succesfullyConfigured, succesfullyConnected};
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   184
	}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   185
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   186
	public void printResource(String fileName) {
18
7900bb1666f6 version info: option --version
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   187
		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
   188
			while (true) {
18
7900bb1666f6 version info: option --version
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   189
				String line = reader.readLine();
17
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   190
				if (line == null) {
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   191
					break;
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   192
				} else {
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   193
					println(line);
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   194
				}
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   195
			}
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   196
		} catch (Exception e) {
18
7900bb1666f6 version info: option --version
František Kučera <franta-hg@frantovo.cz>
parents: 17
diff changeset
   197
			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
   198
		}
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   199
	}
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   200
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   201
	private void println(String line) {
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   202
		out.println(line);
d8ab8aece6f2 license option: --license
František Kučera <franta-hg@frantovo.cz>
parents: 16
diff changeset
   203
	}
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   204
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   205
	private void printTable(Formatter formatter, ColumnsHeader header, List<Object[]> data) throws ConfigurationException, FormatterException {
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
   206
		formatter.writeStartResultSet(header);
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   207
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   208
		for (Object[] row : data) {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   209
			formatter.writeStartRow();
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   210
			for (Object cell : row) {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   211
				formatter.writeColumnValue(cell);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   212
			}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   213
			formatter.writeEndRow();
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   214
		}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   215
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   216
		formatter.writeEndResultSet();
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   217
	}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   218
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   219
	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
   220
		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
   221
		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
   222
		FormatterDefinition fd = configurationProvider.getConfiguration().getFormatter(formatterName);
104
245f1b88a3e6 formatter/database properties
František Kučera <franta-hg@frantovo.cz>
parents: 101
diff changeset
   223
		FormatterContext context = new FormatterContext(out, options.getFormatterProperties());
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   224
		return fd.getInstance(context);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   225
	}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   226
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   227
	private ColumnsHeader constructHeader(HeaderField... fields) throws FormatterException {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   228
		try {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   229
			RowSetMetaDataImpl metaData = new RowSetMetaDataImpl();
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   230
			metaData.setColumnCount(fields.length);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   231
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   232
			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
   233
				HeaderField hf = fields[i];
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   234
				int sqlIndex = i + 1;
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   235
				metaData.setColumnName(sqlIndex, hf.name);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   236
				metaData.setColumnLabel(sqlIndex, hf.name);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   237
				metaData.setColumnType(sqlIndex, hf.type.getCode());
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   238
				metaData.setColumnTypeName(sqlIndex, hf.type.name());
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   239
			}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   240
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   241
			return new ColumnsHeader(metaData);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   242
		} catch (SQLException e) {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   243
			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
   244
		}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   245
	}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   246
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   247
	private static class HeaderField {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   248
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   249
		String name;
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   250
		SQLType type;
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   251
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   252
		public HeaderField(String name, SQLType type) {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   253
			this.name = name;
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   254
			this.type = type;
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   255
		}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   256
	}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   257
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   258
	public enum InfoType {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   259
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   260
		HELP {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   261
			@Override
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   262
			public void showInfo(InfoLister infoLister) {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   263
				infoLister.printResource(Constants.HELP_FILE);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   264
			}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   265
		},
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   266
		VERSION {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   267
			@Override
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   268
			public void showInfo(InfoLister infoLister) {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   269
				infoLister.printResource(Constants.VERSION_FILE);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   270
			}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   271
		},
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   272
		LICENSE {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   273
			@Override
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   274
			public void showInfo(InfoLister infoLister) {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   275
				infoLister.printResource(Constants.LICENSE_FILE);
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   276
			}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   277
		},
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   278
		FORMATTERS {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   279
			@Override
70
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
   280
			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   281
				infoLister.listFormatters();
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   282
			}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   283
		},
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   284
		TYPES {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   285
			@Override
70
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
   286
			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   287
				infoLister.listTypes();
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   288
			}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   289
		},
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   290
		DATABASES {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   291
			@Override
70
02c8eaa425e8 use formatter also for printing info! --list-types
František Kučera <franta-hg@frantovo.cz>
parents: 69
diff changeset
   292
			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   293
				infoLister.listDatabases();
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   294
			}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   295
		},
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   296
		CONNECTION {
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   297
			@Override
73
d32fd50d3c2c formatted output for: --test-connection
František Kučera <franta-hg@frantovo.cz>
parents: 72
diff changeset
   298
			public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
69
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   299
				infoLister.testConnection();
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   300
			}
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   301
		};
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   302
0befec5034c2 InfoLister, InfoType: switch → enum
František Kučera <franta-hg@frantovo.cz>
parents: 67
diff changeset
   303
		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
   304
	}
14
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   305
}