@Test(expected = IllegalArgumentException.class) public void testListDatabasesWithoutSpecificDB() throws SQLException { when(connection.getCatalog()).thenReturn(""); jdbcMetadata.listDatabases(); }
@Override public List<String> listDatabases() throws SQLException { Set<String> ret = new HashSet<>(); try (Connection con = SqlUtil.getConnection(dbconf)) { String database = con.getCatalog(); Preconditions.checkArgument(StringUtils.isNotEmpty(database), "SQL Server needs a specific database in " + "connection string."); try (ResultSet rs = con.getMetaData().getTables(database, null, null, null)) { String schema; String catalog; while (rs.next()) { schema = rs.getString("TABLE_SCHEM"); catalog = rs.getString("TABLE_CAT"); if (database.equals(catalog) || schema.equals("dbo")) { ret.add(schema); } } } } return new ArrayList<>(ret); }
SQLServerJdbcMetadata extends DefaultJdbcMetadata { @Override public List<String> listDatabases() throws SQLException { Set<String> ret = new HashSet<>(); try (Connection con = SqlUtil.getConnection(dbconf)) { String database = con.getCatalog(); Preconditions.checkArgument(StringUtils.isNotEmpty(database), "SQL Server needs a specific database in " + "connection string."); try (ResultSet rs = con.getMetaData().getTables(database, null, null, null)) { String schema; String catalog; while (rs.next()) { schema = rs.getString("TABLE_SCHEM"); catalog = rs.getString("TABLE_CAT"); if (database.equals(catalog) || schema.equals("dbo")) { ret.add(schema); } } } } return new ArrayList<>(ret); } }
SQLServerJdbcMetadata extends DefaultJdbcMetadata { @Override public List<String> listDatabases() throws SQLException { Set<String> ret = new HashSet<>(); try (Connection con = SqlUtil.getConnection(dbconf)) { String database = con.getCatalog(); Preconditions.checkArgument(StringUtils.isNotEmpty(database), "SQL Server needs a specific database in " + "connection string."); try (ResultSet rs = con.getMetaData().getTables(database, null, null, null)) { String schema; String catalog; while (rs.next()) { schema = rs.getString("TABLE_SCHEM"); catalog = rs.getString("TABLE_CAT"); if (database.equals(catalog) || schema.equals("dbo")) { ret.add(schema); } } } } return new ArrayList<>(ret); } SQLServerJdbcMetadata(DBConnConf dbConnConf); }
SQLServerJdbcMetadata extends DefaultJdbcMetadata { @Override public List<String> listDatabases() throws SQLException { Set<String> ret = new HashSet<>(); try (Connection con = SqlUtil.getConnection(dbconf)) { String database = con.getCatalog(); Preconditions.checkArgument(StringUtils.isNotEmpty(database), "SQL Server needs a specific database in " + "connection string."); try (ResultSet rs = con.getMetaData().getTables(database, null, null, null)) { String schema; String catalog; while (rs.next()) { schema = rs.getString("TABLE_SCHEM"); catalog = rs.getString("TABLE_CAT"); if (database.equals(catalog) || schema.equals("dbo")) { ret.add(schema); } } } } return new ArrayList<>(ret); } SQLServerJdbcMetadata(DBConnConf dbConnConf); @Override List<String> listDatabases(); @Override SourceDialect getDialect(); }
SQLServerJdbcMetadata extends DefaultJdbcMetadata { @Override public List<String> listDatabases() throws SQLException { Set<String> ret = new HashSet<>(); try (Connection con = SqlUtil.getConnection(dbconf)) { String database = con.getCatalog(); Preconditions.checkArgument(StringUtils.isNotEmpty(database), "SQL Server needs a specific database in " + "connection string."); try (ResultSet rs = con.getMetaData().getTables(database, null, null, null)) { String schema; String catalog; while (rs.next()) { schema = rs.getString("TABLE_SCHEM"); catalog = rs.getString("TABLE_CAT"); if (database.equals(catalog) || schema.equals("dbo")) { ret.add(schema); } } } } return new ArrayList<>(ret); } SQLServerJdbcMetadata(DBConnConf dbConnConf); @Override List<String> listDatabases(); @Override SourceDialect getDialect();  }