@Test public void testListDatabases() throws SQLException { ResultSet rs = mock(ResultSet.class); when(rs.next()).thenReturn(true).thenReturn(true).thenReturn(false); when(rs.getString("TABLE_SCHEM")).thenReturn("schema1").thenReturn("schema2"); when(rs.getString("TABLE_CATALOG")).thenReturn("catalog1").thenReturn("catalog2"); when(connection.getMetaData()).thenReturn(dbmd); when(dbmd.getSchemas()).thenReturn(rs); List<String> dbs = jdbcMetadata.listDatabases(); Assert.assertEquals(2, dbs.size()); Assert.assertEquals("schema1", dbs.get(0)); }
@Override public List<String> listDatabases() throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getSchemas()) { while (rs.next()) { String schema = rs.getString("TABLE_SCHEM"); String catalog = rs.getString("TABLE_CATALOG"); logger.info(String.format(Locale.ROOT, "%s,%s", schema, catalog)); ret.add(schema); } } return ret; }
DefaultJdbcMetadata implements IJdbcMetadata { @Override public List<String> listDatabases() throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getSchemas()) { while (rs.next()) { String schema = rs.getString("TABLE_SCHEM"); String catalog = rs.getString("TABLE_CATALOG"); logger.info(String.format(Locale.ROOT, "%s,%s", schema, catalog)); ret.add(schema); } } return ret; } }
DefaultJdbcMetadata implements IJdbcMetadata { @Override public List<String> listDatabases() throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getSchemas()) { while (rs.next()) { String schema = rs.getString("TABLE_SCHEM"); String catalog = rs.getString("TABLE_CATALOG"); logger.info(String.format(Locale.ROOT, "%s,%s", schema, catalog)); ret.add(schema); } } return ret; } DefaultJdbcMetadata(DBConnConf dbConnConf); }
DefaultJdbcMetadata implements IJdbcMetadata { @Override public List<String> listDatabases() throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getSchemas()) { while (rs.next()) { String schema = rs.getString("TABLE_SCHEM"); String catalog = rs.getString("TABLE_CATALOG"); logger.info(String.format(Locale.ROOT, "%s,%s", schema, catalog)); ret.add(schema); } } return ret; } DefaultJdbcMetadata(DBConnConf dbConnConf); @Override List<String> listDatabases(); @Override List<String> listTables(String schema); @Override ResultSet getTable(final DatabaseMetaData dbmd, String schema, String table); @Override ResultSet listColumns(final DatabaseMetaData dbmd, String schema, String table); SourceDialect getDialect(); }
DefaultJdbcMetadata implements IJdbcMetadata { @Override public List<String> listDatabases() throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getSchemas()) { while (rs.next()) { String schema = rs.getString("TABLE_SCHEM"); String catalog = rs.getString("TABLE_CATALOG"); logger.info(String.format(Locale.ROOT, "%s,%s", schema, catalog)); ret.add(schema); } } return ret; } DefaultJdbcMetadata(DBConnConf dbConnConf); @Override List<String> listDatabases(); @Override List<String> listTables(String schema); @Override ResultSet getTable(final DatabaseMetaData dbmd, String schema, String table); @Override ResultSet listColumns(final DatabaseMetaData dbmd, String schema, String table); SourceDialect getDialect();  }