1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Thu Dec 26 21:18:54 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Thu Dec 26 21:47:33 2013 +0100
1.3 @@ -31,6 +31,8 @@
1.4 import java.io.InputStreamReader;
1.5 import java.io.PrintStream;
1.6 import java.sql.SQLException;
1.7 +import java.util.ArrayList;
1.8 +import java.util.EnumSet;
1.9 import java.util.List;
1.10 import java.util.logging.Level;
1.11 import java.util.logging.Logger;
1.12 @@ -47,6 +49,7 @@
1.13 private PrintStream out;
1.14 private ConfigurationProvider configurationProvider;
1.15 private CLIOptions options;
1.16 + private Formatter formatter;
1.17
1.18 public InfoLister(PrintStream out, ConfigurationProvider configurationProvider, CLIOptions options) {
1.19 this.out = out;
1.20 @@ -54,7 +57,31 @@
1.21 this.options = options;
1.22 }
1.23
1.24 - public void listFormatters() throws ConfigurationException {
1.25 + public void showInfo() throws ConfigurationException, FormatterException {
1.26 + EnumSet<InfoType> commands = options.getShowInfo();
1.27 +
1.28 + for (InfoType infoType : commands) {
1.29 + switch (infoType) {
1.30 + // only these needs formatted output
1.31 + case CONNECTION:
1.32 + case DATABASES:
1.33 + case FORMATTERS:
1.34 + case TYPES:
1.35 + formatter = getFormatter();
1.36 + formatter.writeStartDatabase(new DatabaseDefinition());
1.37 + }
1.38 + }
1.39 +
1.40 + for (InfoType infoType : commands) {
1.41 + infoType.showInfo(this);
1.42 + }
1.43 +
1.44 + if (formatter != null) {
1.45 + formatter.writeEndDatabase();
1.46 + }
1.47 + }
1.48 +
1.49 + private void listFormatters() throws ConfigurationException {
1.50 for (FormatterDefinition fd : configurationProvider.getConfiguration().getBuildInFormatters()) {
1.51 log.log(Level.INFO, "Built-in formatter: {0} implemented by class: {1}", new Object[]{rpad(fd.getName(), 16), fd.getClassName()});
1.52 }
1.53 @@ -73,7 +100,13 @@
1.54 }
1.55 }
1.56
1.57 - public void listTypes() throws FormatterException {
1.58 + public void listTypes() throws FormatterException, ConfigurationException {
1.59 + ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER));
1.60 + List<Object[]> data = new ArrayList<>();
1.61 + for (SQLType sqlType : SQLType.values()) {
1.62 + data.add(new Object[]{sqlType.name(), sqlType.getCode()});
1.63 + }
1.64 + printTable(formatter, header, data);
1.65 }
1.66
1.67 public void listDatabases() throws ConfigurationException {
1.68 @@ -199,19 +232,19 @@
1.69 },
1.70 FORMATTERS {
1.71 @Override
1.72 - public void showInfo(InfoLister infoLister) throws ConfigurationException {
1.73 + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
1.74 infoLister.listFormatters();
1.75 }
1.76 },
1.77 TYPES {
1.78 @Override
1.79 - public void showInfo(InfoLister infoLister) throws FormatterException {
1.80 + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
1.81 infoLister.listTypes();
1.82 }
1.83 },
1.84 DATABASES {
1.85 @Override
1.86 - public void showInfo(InfoLister infoLister) throws ConfigurationException {
1.87 + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
1.88 infoLister.listDatabases();
1.89 }
1.90 },