@Service
public class DataSourcesCommand extends JdbcCommandSupport {
@Override
public Object execute() throws Exception {
ShellTable table = new ShellTable();
table.column("Name");
table.column("Product");
table.column("Version");
table.column("URL");
table.column("Status");
Map<String, Set<String>> datasources = this.getJdbcService().aliases();
for (Map.Entry<String, Set<String>> entry : datasources.entrySet()) {
StringBuilder ids = new StringBuilder();
for (String id : entry.getValue()) {
if (ids.length() > 0) {
ids.append(", ");
}
ids.append(id);
}
String id = ids.toString();
try {
Map<String, String> info = this.getJdbcService().info(entry.getKey());
table.addRow().addContent(id, info.get("db.product"), info.get("db.version"), info.get("url"), "OK");
} catch (Exception e) {
table.addRow().addContent(id, "", "", "", "Error");
}
}
table.print(System.out);
return null;
}