24 import info.globalcode.sql.dk.configuration.DatabaseDefinition; |
24 import info.globalcode.sql.dk.configuration.DatabaseDefinition; |
25 import info.globalcode.sql.dk.configuration.FormatterDefinition; |
25 import info.globalcode.sql.dk.configuration.FormatterDefinition; |
26 import info.globalcode.sql.dk.configuration.Properties; |
26 import info.globalcode.sql.dk.configuration.Properties; |
27 import info.globalcode.sql.dk.configuration.Property; |
27 import info.globalcode.sql.dk.configuration.Property; |
28 import info.globalcode.sql.dk.configuration.PropertyDeclaration; |
28 import info.globalcode.sql.dk.configuration.PropertyDeclaration; |
29 import info.globalcode.sql.dk.configuration.PropertyDeclarations; |
|
30 import info.globalcode.sql.dk.configuration.TunnelDefinition; |
29 import info.globalcode.sql.dk.configuration.TunnelDefinition; |
31 import info.globalcode.sql.dk.formatting.ColumnsHeader; |
30 import info.globalcode.sql.dk.formatting.ColumnsHeader; |
32 import info.globalcode.sql.dk.formatting.CommonProperties; |
31 import info.globalcode.sql.dk.formatting.CommonProperties; |
33 import info.globalcode.sql.dk.formatting.FakeSqlArray; |
32 import info.globalcode.sql.dk.formatting.FakeSqlArray; |
34 import info.globalcode.sql.dk.formatting.Formatter; |
33 import info.globalcode.sql.dk.formatting.Formatter; |
393 |
392 |
394 private void testConnections() throws FormatterException, ConfigurationException { |
393 private void testConnections() throws FormatterException, ConfigurationException { |
395 ColumnsHeader header = constructHeader( |
394 ColumnsHeader header = constructHeader( |
396 new HeaderField("database_name", SQLType.VARCHAR), |
395 new HeaderField("database_name", SQLType.VARCHAR), |
397 new HeaderField("configured", SQLType.BOOLEAN), |
396 new HeaderField("configured", SQLType.BOOLEAN), |
398 new HeaderField("connected", SQLType.BOOLEAN)); |
397 new HeaderField("connected", SQLType.BOOLEAN), |
|
398 new HeaderField("product_name", SQLType.VARCHAR), |
|
399 new HeaderField("product_version", SQLType.VARCHAR)); |
399 |
400 |
400 log.log(Level.FINE, "Testing DB connections in {0} threads", TESTING_THREAD_COUNT); |
401 log.log(Level.FINE, "Testing DB connections in {0} threads", TESTING_THREAD_COUNT); |
401 |
402 |
402 ExecutorService es = Executors.newFixedThreadPool(TESTING_THREAD_COUNT); |
403 ExecutorService es = Executors.newFixedThreadPool(TESTING_THREAD_COUNT); |
403 |
404 |
462 private Object[] testConnection(String dbName) { |
463 private Object[] testConnection(String dbName) { |
463 log.log(Level.FINE, "Testing connection to database: {0}", dbName); |
464 log.log(Level.FINE, "Testing connection to database: {0}", dbName); |
464 |
465 |
465 boolean succesfullyConnected = false; |
466 boolean succesfullyConnected = false; |
466 boolean succesfullyConfigured = false; |
467 boolean succesfullyConfigured = false; |
|
468 String productName = null; |
|
469 String productVersion = null; |
467 |
470 |
468 try { |
471 try { |
469 DatabaseDefinition dd = configurationProvider.getConfiguration().getDatabase(dbName); |
472 DatabaseDefinition dd = configurationProvider.getConfiguration().getDatabase(dbName); |
470 log.log(Level.FINE, "Database definition was loaded from configuration"); |
473 log.log(Level.FINE, "Database definition was loaded from configuration"); |
471 succesfullyConfigured = true; |
474 succesfullyConfigured = true; |
472 try (DatabaseConnection dc = dd.connect(options.getDatabaseProperties())) { |
475 try (DatabaseConnection dc = dd.connect(options.getDatabaseProperties())) { |
473 succesfullyConnected = dc.test(); |
476 succesfullyConnected = dc.test(); |
|
477 productName = dc.getProductName(); |
|
478 productVersion = dc.getProductVersion(); |
474 } |
479 } |
475 log.log(Level.FINE, "Database connection test was successful"); |
480 log.log(Level.FINE, "Database connection test was successful"); |
476 } catch (ConfigurationException | SQLException | RuntimeException e) { |
481 } catch (ConfigurationException | SQLException | RuntimeException e) { |
477 log.log(Level.SEVERE, "Error during testing connection " + dbName, e); |
482 log.log(Level.SEVERE, "Error during testing connection " + dbName, e); |
478 } |
483 } |
479 |
484 |
480 return new Object[]{dbName, succesfullyConfigured, succesfullyConnected}; |
485 return new Object[]{dbName, succesfullyConfigured, succesfullyConnected, productName, productVersion}; |
481 } |
486 } |
482 |
487 |
483 private void printResource(String fileName) { |
488 private void printResource(String fileName) { |
484 try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(fileName)))) { |
489 try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(fileName)))) { |
485 while (true) { |
490 while (true) { |
589 } |
594 } |
590 |
595 |
591 public enum InfoType { |
596 public enum InfoType { |
592 |
597 |
593 HELP { |
598 HELP { |
594 @Override |
599 @Override |
595 public void showInfo(InfoLister infoLister) { |
600 public void showInfo(InfoLister infoLister) { |
596 infoLister.printResource(Constants.HELP_FILE); |
601 infoLister.printResource(Constants.HELP_FILE); |
597 } |
602 } |
598 }, |
603 }, |
599 VERSION { |
604 VERSION { |
600 @Override |
605 @Override |
601 public void showInfo(InfoLister infoLister) { |
606 public void showInfo(InfoLister infoLister) { |
602 infoLister.printResource(Constants.VERSION_FILE); |
607 infoLister.printResource(Constants.VERSION_FILE); |
603 } |
608 } |
604 }, |
609 }, |
605 LICENSE { |
610 LICENSE { |
606 @Override |
611 @Override |
607 public void showInfo(InfoLister infoLister) { |
612 public void showInfo(InfoLister infoLister) { |
608 infoLister.printResource(Constants.LICENSE_FILE); |
613 infoLister.printResource(Constants.LICENSE_FILE); |
609 } |
614 } |
610 }, |
615 }, |
611 JAVA_PROPERTIES { |
616 JAVA_PROPERTIES { |
612 @Override |
617 @Override |
613 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
618 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
614 infoLister.listJavaProperties(); |
619 infoLister.listJavaProperties(); |
615 } |
620 } |
616 }, |
621 }, |
617 ENVIRONMENT_VARIABLES { |
622 ENVIRONMENT_VARIABLES { |
618 @Override |
623 @Override |
619 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
624 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
620 infoLister.listEnvironmentVariables(); |
625 infoLister.listEnvironmentVariables(); |
621 } |
626 } |
622 }, |
627 }, |
623 FORMATTERS { |
628 FORMATTERS { |
624 @Override |
629 @Override |
625 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
630 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
626 infoLister.listFormatters(); |
631 infoLister.listFormatters(); |
627 } |
632 } |
628 }, |
633 }, |
629 FORMATTER_PROPERTIES { |
634 FORMATTER_PROPERTIES { |
630 @Override |
635 @Override |
631 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
636 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
632 infoLister.listFormatterProperties(); |
637 infoLister.listFormatterProperties(); |
633 } |
638 } |
634 }, |
639 }, |
635 TYPES { |
640 TYPES { |
636 @Override |
641 @Override |
637 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
642 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
638 infoLister.listTypes(); |
643 infoLister.listTypes(); |
639 } |
644 } |
640 }, |
645 }, |
641 JDBC_DRIVERS { |
646 JDBC_DRIVERS { |
642 @Override |
647 @Override |
643 public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException { |
648 public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException { |
644 infoLister.listJdbcDrivers(); |
649 infoLister.listJdbcDrivers(); |
645 } |
650 } |
646 }, |
651 }, |
647 JDBC_PROPERTIES { |
652 JDBC_PROPERTIES { |
648 @Override |
653 @Override |
649 public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException { |
654 public void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException { |
650 infoLister.listJdbcProperties(); |
655 infoLister.listJdbcProperties(); |
651 } |
656 } |
652 }, |
657 }, |
653 DATABASES { |
658 DATABASES { |
654 @Override |
659 @Override |
655 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
660 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
656 infoLister.listDatabases(); |
661 infoLister.listDatabases(); |
657 } |
662 } |
658 }, |
663 }, |
659 CONNECTION { |
664 CONNECTION { |
660 @Override |
665 @Override |
661 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
666 public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { |
662 infoLister.testConnections(); |
667 infoLister.testConnections(); |
663 } |
668 } |
664 }; |
669 }; |
665 |
670 |
666 public abstract void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException; |
671 public abstract void showInfo(InfoLister infoLister) throws ConfigurationException, FormatterException; |
667 } |
672 } |
668 } |
673 } |