use of org.dbflute.logic.jdbc.metadata.supplement.DfUniqueKeyFkExtractor.UserUniqueFkColumn in project dbflute-core by dbflute.
the class DfForeignKeyExtractor method prepareUniqueKeyFkCache.
protected void prepareUniqueKeyFkCache(Connection conn, UnifiedSchema unifiedSchema) {
// preparing unique-key FK info of the schema
final Map<String, List<DfForeignKeyMeta>> tableMap = StringKeyMap.createAsFlexibleConcurrent();
final DfUniqueKeyFkExtractor extractor = createUniqueKeyFkExtractor(conn, unifiedSchema);
if (extractor == null) {
// no need to extract in this DBMS
_uniqueKeyFkMap.put(unifiedSchema, new ConcurrentHashMap<String, List<DfForeignKeyMeta>>());
return;
}
_log.info("...Extracting unique-key FK: " + unifiedSchema);
final Map<String, Map<String, List<UserUniqueFkColumn>>> uniqueKeyFkMap = extractor.extractUniqueKeyFkMap();
for (Entry<String, Map<String, List<UserUniqueFkColumn>>> tableEntry : uniqueKeyFkMap.entrySet()) {
final String tableKey = tableEntry.getKey();
final List<DfForeignKeyMeta> metaList = new ArrayList<DfForeignKeyMeta>();
final Map<String, List<UserUniqueFkColumn>> fkColumnListMap = tableEntry.getValue();
for (Entry<String, List<UserUniqueFkColumn>> fkEntry : fkColumnListMap.entrySet()) {
final List<UserUniqueFkColumn> columnList = fkEntry.getValue();
DfForeignKeyMeta meta = null;
for (UserUniqueFkColumn uniqueFkColumn : columnList) {
if (meta == null) {
meta = new DfForeignKeyMeta();
meta.setForeignKeyName(uniqueFkColumn.getForeignKeyName());
meta.setLocalSchema(unifiedSchema);
meta.setLocalTablePureName(uniqueFkColumn.getLocalTableName());
// same schema only supported
meta.setForeignSchema(unifiedSchema);
final String foreignTableName = uniqueFkColumn.getForeignTableName();
meta.setForeignTablePureName(foreignTableName);
if (!isForeignTableGenerated(foreignTableName)) {
break;
}
}
meta.putColumnName(uniqueFkColumn.getLocalColumnName(), uniqueFkColumn.getForeignColumnName());
}
if (meta == null) {
// basically no way
throw new IllegalStateException("The key should have any elements: " + tableKey);
}
metaList.add(meta);
}
tableMap.put(tableKey, metaList);
}
_uniqueKeyFkMap.put(unifiedSchema, tableMap);
if (!tableMap.isEmpty()) {
_log.info(" -> Unique-key FK: " + tableMap.keySet());
} else {
_log.info(" -> Not found unique-key FK");
}
}
Aggregations