@Test public void testListTables() throws SQLException { ResultSet rs = mock(ResultSet.class); when(rs.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false); when(rs.getString("TABLE_NAME")).thenReturn("KYLIN_SALES").thenReturn("CAT_DT").thenReturn("KYLIN_CAT"); String schema = "testschema"; when(connection.getMetaData()).thenReturn(dbmd); when(dbmd.getTables(null, schema, null, null)).thenReturn(rs); List<String> tables = jdbcMetadata.listTables(schema); Assert.assertEquals(3, tables.size()); Assert.assertEquals("CAT_DT", tables.get(1)); }
@Override public List<String> listTables(String schema) throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getTables(null, schema, null, null)) { while (rs.next()) { String name = rs.getString("TABLE_NAME"); ret.add(name); } } return ret; }
DefaultJdbcMetadata implements IJdbcMetadata { @Override public List<String> listTables(String schema) throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getTables(null, schema, null, null)) { while (rs.next()) { String name = rs.getString("TABLE_NAME"); ret.add(name); } } return ret; } }
DefaultJdbcMetadata implements IJdbcMetadata { @Override public List<String> listTables(String schema) throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getTables(null, schema, null, null)) { while (rs.next()) { String name = rs.getString("TABLE_NAME"); ret.add(name); } } return ret; } DefaultJdbcMetadata(DBConnConf dbConnConf); }
DefaultJdbcMetadata implements IJdbcMetadata { @Override public List<String> listTables(String schema) throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getTables(null, schema, null, null)) { while (rs.next()) { String name = rs.getString("TABLE_NAME"); ret.add(name); } } 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> listTables(String schema) throws SQLException { List<String> ret = new ArrayList<>(); try (Connection con = SqlUtil.getConnection(dbconf); ResultSet rs = con.getMetaData().getTables(null, schema, null, null)) { while (rs.next()) { String name = rs.getString("TABLE_NAME"); ret.add(name); } } 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();  }