Skip to content

Instantly share code, notes, and snippets.

@mingyang91
Last active August 2, 2022 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingyang91/578747e27d0d68553f66ff60405a8827 to your computer and use it in GitHub Desktop.
Save mingyang91/578747e27d0d68553f66ff60405a8827 to your computer and use it in GitHub Desktop.
class V2EX_stream {
public List<String> getForeignKeyTable(List<String> tableNames,
DataSourceEntity info,
List<ForeignKeyInfo> foreignKeyInfos) {
var childTables = tableNames.stream()
.map(tableName -> findAllTable(info.getDataBaseName(), tableName))
.filter(column -> !DB_KEYWORD_SET.contains(column.getColumnName().toUpperCase()))
.flatMap(columnInfo -> foreignKeyInfos.stream()
.filter(it -> it.getSourceTableName().equals(columnInfo.getTableName()) &&
it.getSourceColumnName().equals(columnInfo.getColumnName())
)
)
.map(ForeignKeyInfo::getTargetTableName)
.toList();
if (childTables.isEmpty()) {
return Collections.emptyList();
} else {
return getForeignKeyTable(childTables, info, foreignKeyInfos);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment