20 import info.globalcode.sql.dk.configuration.Configuration; |
20 import info.globalcode.sql.dk.configuration.Configuration; |
21 import info.globalcode.sql.dk.configuration.ConfigurationException; |
21 import info.globalcode.sql.dk.configuration.ConfigurationException; |
22 import info.globalcode.sql.dk.configuration.ConfigurationProvider; |
22 import info.globalcode.sql.dk.configuration.ConfigurationProvider; |
23 import info.globalcode.sql.dk.configuration.DatabaseDefinition; |
23 import info.globalcode.sql.dk.configuration.DatabaseDefinition; |
24 import info.globalcode.sql.dk.configuration.FormatterDefinition; |
24 import info.globalcode.sql.dk.configuration.FormatterDefinition; |
25 import static info.globalcode.sql.dk.Functions.rpad; |
|
26 import info.globalcode.sql.dk.formatting.ColumnsHeader; |
25 import info.globalcode.sql.dk.formatting.ColumnsHeader; |
27 import info.globalcode.sql.dk.formatting.Formatter; |
26 import info.globalcode.sql.dk.formatting.Formatter; |
28 import info.globalcode.sql.dk.formatting.FormatterContext; |
27 import info.globalcode.sql.dk.formatting.FormatterContext; |
29 import info.globalcode.sql.dk.formatting.FormatterException; |
28 import info.globalcode.sql.dk.formatting.FormatterException; |
30 import java.io.BufferedReader; |
29 import java.io.BufferedReader; |
79 if (formatter != null) { |
78 if (formatter != null) { |
80 formatter.writeEndDatabase(); |
79 formatter.writeEndDatabase(); |
81 } |
80 } |
82 } |
81 } |
83 |
82 |
84 private void listFormatters() throws ConfigurationException { |
83 private void listFormatters() throws ConfigurationException, FormatterException { |
|
84 ColumnsHeader header = constructHeader( |
|
85 new HeaderField("name", SQLType.VARCHAR), |
|
86 new HeaderField("built_in", SQLType.BOOLEAN), |
|
87 new HeaderField("default", SQLType.BOOLEAN), |
|
88 new HeaderField("class_name", SQLType.VARCHAR)); |
|
89 List<Object[]> data = new ArrayList<>(); |
|
90 |
|
91 String defaultFormatter = configurationProvider.getConfiguration().getDefaultFormatter(); |
|
92 defaultFormatter = defaultFormatter == null ? Configuration.DEFAULT_FORMATTER : defaultFormatter; |
|
93 |
85 for (FormatterDefinition fd : configurationProvider.getConfiguration().getBuildInFormatters()) { |
94 for (FormatterDefinition fd : configurationProvider.getConfiguration().getBuildInFormatters()) { |
86 log.log(Level.INFO, "Built-in formatter: {0} implemented by class: {1}", new Object[]{rpad(fd.getName(), 16), fd.getClassName()}); |
95 data.add(new Object[]{fd.getName(), true, defaultFormatter.equals(fd.getName()), fd.getClassName()}); |
87 } |
96 } |
88 List<FormatterDefinition> configuredFormatters = configurationProvider.getConfiguration().getFormatters(); |
97 |
89 for (FormatterDefinition fd : configuredFormatters) { |
98 for (FormatterDefinition fd : configurationProvider.getConfiguration().getFormatters()) { |
90 log.log(Level.INFO, "Configured formatter: {0} implemented by class: {1}", new Object[]{rpad(fd.getName(), 16), fd.getClassName()}); |
99 data.add(new Object[]{fd.getName(), false, defaultFormatter.equals(fd.getName()), fd.getClassName()}); |
91 } |
100 } |
92 if (configuredFormatters.isEmpty()) { |
101 |
93 log.log(Level.INFO, "No other formatters are configured"); |
102 printTable(formatter, header, data); |
94 } |
103 |
95 String configuredDefaultFormatter = configurationProvider.getConfiguration().getDefaultFormatter(); |
104 |
96 if (configuredDefaultFormatter == null) { |
|
97 log.log(Level.INFO, "Built-in default formatter: {0}", Configuration.DEFAULT_FORMATTER); |
|
98 } else { |
|
99 log.log(Level.INFO, "Configured default formatter: {0}", configuredDefaultFormatter); |
|
100 } |
|
101 } |
105 } |
102 |
106 |
103 public void listTypes() throws FormatterException, ConfigurationException { |
107 public void listTypes() throws FormatterException, ConfigurationException { |
104 ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER)); |
108 ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER)); |
105 List<Object[]> data = new ArrayList<>(); |
109 List<Object[]> data = new ArrayList<>(); |
107 data.add(new Object[]{sqlType.name(), sqlType.getCode()}); |
111 data.add(new Object[]{sqlType.name(), sqlType.getCode()}); |
108 } |
112 } |
109 printTable(formatter, header, data); |
113 printTable(formatter, header, data); |
110 } |
114 } |
111 |
115 |
112 public void listDatabases() throws ConfigurationException { |
116 public void listDatabases() throws ConfigurationException, FormatterException { |
|
117 ColumnsHeader header = constructHeader( |
|
118 new HeaderField("database_name", SQLType.VARCHAR), |
|
119 new HeaderField("user_name", SQLType.VARCHAR), |
|
120 new HeaderField("database_url", SQLType.VARCHAR)); |
|
121 List<Object[]> data = new ArrayList<>(); |
|
122 |
113 final List<DatabaseDefinition> configuredDatabases = configurationProvider.getConfiguration().getDatabases(); |
123 final List<DatabaseDefinition> configuredDatabases = configurationProvider.getConfiguration().getDatabases(); |
114 if (configuredDatabases.isEmpty()) { |
124 if (configuredDatabases.isEmpty()) { |
115 log.log(Level.WARNING, "No databases are configured."); |
125 log.log(Level.WARNING, "No databases are configured."); |
116 } else { |
126 } else { |
117 for (DatabaseDefinition dd : configuredDatabases) { |
127 for (DatabaseDefinition dd : configuredDatabases) { |
118 log.log(Level.INFO, "Configured database: {0}", dd.getName()); |
128 data.add(new Object[]{dd.getName(), dd.getUserName(), dd.getUrl()}); |
119 } |
129 } |
120 } |
130 } |
|
131 |
|
132 printTable(formatter, header, data); |
121 } |
133 } |
122 |
134 |
123 public void testConnection() { |
135 public void testConnection() { |
124 boolean connectionTestResult = false; |
136 boolean connectionTestResult = false; |
125 String dbName = options.getDatabaseNameToTest(); |
137 String dbName = options.getDatabaseNameToTest(); |