27 import info.globalcode.sql.dk.formatting.FormatterContext; |
27 import info.globalcode.sql.dk.formatting.FormatterContext; |
28 import info.globalcode.sql.dk.formatting.FormatterException; |
28 import info.globalcode.sql.dk.formatting.FormatterException; |
29 import java.io.BufferedReader; |
29 import java.io.BufferedReader; |
30 import java.io.InputStreamReader; |
30 import java.io.InputStreamReader; |
31 import java.io.PrintStream; |
31 import java.io.PrintStream; |
|
32 import java.sql.Driver; |
32 import java.sql.SQLException; |
33 import java.sql.SQLException; |
33 import java.util.ArrayList; |
34 import java.util.ArrayList; |
34 import java.util.EnumSet; |
35 import java.util.EnumSet; |
35 import java.util.List; |
36 import java.util.List; |
|
37 import java.util.ServiceLoader; |
36 import java.util.logging.Level; |
38 import java.util.logging.Level; |
37 import java.util.logging.Logger; |
39 import java.util.logging.Logger; |
38 import javax.sql.rowset.RowSetMetaDataImpl; |
40 import javax.sql.rowset.RowSetMetaDataImpl; |
39 |
41 |
40 /** |
42 /** |
146 } |
149 } |
147 |
150 |
148 printTable(formatter, header, data); |
151 printTable(formatter, header, data); |
149 } |
152 } |
150 |
153 |
|
154 public void listJdbcDrivers() throws FormatterException, ConfigurationException { |
|
155 ColumnsHeader header = constructHeader( |
|
156 new HeaderField("class", SQLType.VARCHAR), |
|
157 new HeaderField("version", SQLType.VARCHAR), |
|
158 new HeaderField("major", SQLType.INTEGER), |
|
159 new HeaderField("minor", SQLType.INTEGER), |
|
160 new HeaderField("jdbc_compliant", SQLType.BOOLEAN)); |
|
161 List<Object[]> data = new ArrayList<>(); |
|
162 |
|
163 final ServiceLoader<Driver> drivers = ServiceLoader.load(Driver.class); |
|
164 for (Driver d : drivers) { |
|
165 data.add(new Object[]{ |
|
166 d.getClass().getName(), |
|
167 d.getMajorVersion() + "." + d.getMinorVersion(), |
|
168 d.getMajorVersion(), |
|
169 d.getMinorVersion(), |
|
170 d.jdbcCompliant()}); |
|
171 } |
|
172 |
|
173 printTable(formatter, header, data); |
|
174 |
|
175 } |
|
176 |
151 public void testConnection() throws FormatterException, ConfigurationException { |
177 public void testConnection() throws FormatterException, ConfigurationException { |
152 ColumnsHeader header = constructHeader( |
178 ColumnsHeader header = constructHeader( |
153 new HeaderField("database_name", SQLType.VARCHAR), |
179 new HeaderField("database_name", SQLType.VARCHAR), |
154 new HeaderField("configured", SQLType.BOOLEAN), |
180 new HeaderField("configured", SQLType.BOOLEAN), |
155 new HeaderField("connected", SQLType.BOOLEAN)); |
181 new HeaderField("connected", SQLType.BOOLEAN)); |
285 @Override |
311 @Override |
286 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
312 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
287 infoLister.listTypes(); |
313 infoLister.listTypes(); |
288 } |
314 } |
289 }, |
315 }, |
|
316 JDBC_DRIVERS { |
|
317 @Override |
|
318 public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException { |
|
319 infoLister.listJdbcDrivers(); |
|
320 } |
|
321 }, |
290 DATABASES { |
322 DATABASES { |
291 @Override |
323 @Override |
292 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
324 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
293 infoLister.listDatabases(); |
325 infoLister.listDatabases(); |
294 } |
326 } |