@ParameterizedTest @ArgumentsSource(TestCaseArgumentsProvider.class) @NullValue("NULL") @TestCase({"NULL", "NULL", ",,", ",,", "FRED,BOB,JOE", "FRED,BOB,JOE"}) @TestCase({"NULL", "NULL", "A,B,C", ",,", "FRED,BOB,JOE", "A..FRED,B..BOB,C..JOE"}) @TestCase({"NULL", "NULL", ",,", "D,E,F", "FRED,BOB,JOE", "D.FRED,E.BOB,F.JOE"}) @TestCase({"NULL", "NULL", "A,B,C", "D,E,F", "FRED,BOB,JOE", "A.D.FRED,B.E.BOB,C.F.JOE"}) @TestCase({"A", "NULL", ",,", ",,", "FRED,BOB,JOE", "FRED,BOB,JOE"}) @TestCase({"A", "NULL", "A,B,C", ",,", "FRED,BOB,JOE", "A..FRED"}) @TestCase({"A", "NULL", "A,B,C", "D,E,F", "FRED,BOB,JOE", "A.D.FRED"}) @TestCase({"X", "NULL", "A,B,C", "D,E,F", "FRED,BOB,JOE", ""}) @TestCase({"A", "", ",,", ",,", "FRED,BOB,JOE", "FRED,BOB,JOE"}) @TestCase({"A", "", "A,B,C", ",,", "FRED,BOB,JOE", "A..FRED"}) @TestCase({"A", "", "A,B,C", "D,E,F", "FRED,BOB,JOE", "A.D.FRED"}) @TestCase({"NULL", "E", ",,", ",,", "FRED,BOB,JOE", "FRED,BOB,JOE"}) @TestCase({"NULL", "E", ",,", "D,E,F", "FRED,BOB,JOE", "E.BOB"}) @TestCase({"NULL", "E", "A,B,C", "D,E,F", "FRED,BOB,JOE", "B.E.BOB"}) @TestCase({"", "E", ",,", ",,", "FRED,BOB,JOE", "FRED,BOB,JOE"}) @TestCase({"", "E", ",,", "D,E,F", "FRED,BOB,JOE", "E.BOB"}) @TestCase({"", "E", "NULL,NULL,NULL", "NULL,NULL,NULL", "FRED,BOB,JOE", "FRED,BOB,JOE"}) @TestCase({"", "E", "NULL,NULL,NULL", "D,E,F", "FRED,BOB,JOE", "E.BOB"}) @TestCase({"", "E", "A,B,C", "D,E,F", "FRED,BOB,JOE", "B.E.BOB"}) @TestCase({"C", "F", ",,", ",,", "FRED,BOB,JOE", "FRED,BOB,JOE"}) @TestCase({"C", "F", ",,", "D,E,F", "FRED,BOB,JOE", "F.JOE"}) @TestCase({"C", "F", "NULL,NULL,NULL", "NULL,NULL,NULL", "FRED,BOB,JOE", "FRED,BOB,JOE"}) @TestCase({"C", "F", "NULL,NULL,NULL", "D,E,F", "FRED,BOB,JOE", "F.JOE"}) @TestCase({"C", "F", "A,B,C", "D,E,F", "FRED,BOB,JOE", "C.F.JOE"}) void tableNames(String catalog, String schema, String[] actualCatalog, String[] actualSchema, String[] actualTable, String[] expectedTableNames) throws SQLException { QualifiedName[] expectedTables = parseQualifiedNames(expectedTableNames); when(metaData.getTables(isNull(), isNull(), isNull(), eq(new String[] {"TABLE"}))) .thenReturn(resultSet); when(resultSet.getString("TABLE_CAT")) .thenReturn(actualCatalog); when(resultSet.getString("TABLE_SCHEM")) .thenReturn(actualSchema); when(resultSet.getString("TABLE_NAME")) .thenReturn(actualTable); when(resultSet.next()) .thenReturn(actualTable.length, TRUE) .thenReturn(FALSE); Stream<QualifiedName> result = DatabaseMetaDataUtil.tableNames(metaData, catalog, schema); assertThat(result, contains(expectedTables)); }
public static Stream<QualifiedName> tableNames(DatabaseMetaData metaData, String catalog, String schema) { return ResultSetUtil.stream( () -> metaData.getTables(null, null, null, new String[] {"TABLE"}), rs -> new QualifiedName(getString(rs, "TABLE_CAT"), getString(rs, "TABLE_SCHEM"), getString(rs, "TABLE_NAME"))) .filter(matchesCatalogAndSchema(catalog, schema)); }
DatabaseMetaDataUtil extends UtilityClass { public static Stream<QualifiedName> tableNames(DatabaseMetaData metaData, String catalog, String schema) { return ResultSetUtil.stream( () -> metaData.getTables(null, null, null, new String[] {"TABLE"}), rs -> new QualifiedName(getString(rs, "TABLE_CAT"), getString(rs, "TABLE_SCHEM"), getString(rs, "TABLE_NAME"))) .filter(matchesCatalogAndSchema(catalog, schema)); } }
DatabaseMetaDataUtil extends UtilityClass { public static Stream<QualifiedName> tableNames(DatabaseMetaData metaData, String catalog, String schema) { return ResultSetUtil.stream( () -> metaData.getTables(null, null, null, new String[] {"TABLE"}), rs -> new QualifiedName(getString(rs, "TABLE_CAT"), getString(rs, "TABLE_SCHEM"), getString(rs, "TABLE_NAME"))) .filter(matchesCatalogAndSchema(catalog, schema)); }  }
DatabaseMetaDataUtil extends UtilityClass { public static Stream<QualifiedName> tableNames(DatabaseMetaData metaData, String catalog, String schema) { return ResultSetUtil.stream( () -> metaData.getTables(null, null, null, new String[] {"TABLE"}), rs -> new QualifiedName(getString(rs, "TABLE_CAT"), getString(rs, "TABLE_SCHEM"), getString(rs, "TABLE_NAME"))) .filter(matchesCatalogAndSchema(catalog, schema)); }  static boolean tableExists(DatabaseMetaData metaData, String catalog, String schema, String tableName); static Stream<QualifiedName> tableNames(DatabaseMetaData metaData, String catalog, String schema); static Stream<ForeignKeyName> foreignKeyNames(DatabaseMetaData metaData, String catalog, String schema); }
DatabaseMetaDataUtil extends UtilityClass { public static Stream<QualifiedName> tableNames(DatabaseMetaData metaData, String catalog, String schema) { return ResultSetUtil.stream( () -> metaData.getTables(null, null, null, new String[] {"TABLE"}), rs -> new QualifiedName(getString(rs, "TABLE_CAT"), getString(rs, "TABLE_SCHEM"), getString(rs, "TABLE_NAME"))) .filter(matchesCatalogAndSchema(catalog, schema)); }  static boolean tableExists(DatabaseMetaData metaData, String catalog, String schema, String tableName); static Stream<QualifiedName> tableNames(DatabaseMetaData metaData, String catalog, String schema); static Stream<ForeignKeyName> foreignKeyNames(DatabaseMetaData metaData, String catalog, String schema);  }