use of org.dbflute.logic.jdbc.metadata.info.DfForeignKeyMeta in project dbflute-core by dbflute.
the class DfSchemaXmlSerializer method processForeignKey.
// -----------------------------------------------------
// ForeignKey
// ----------
protected void processForeignKey(Connection conn, DatabaseMetaData metaData, DfTableMeta tableMeta, Element tableElement) throws SQLException {
final Map<String, DfForeignKeyMeta> foreignKeyMap = getForeignKeys(conn, metaData, tableMeta);
if (foreignKeyMap.isEmpty()) {
return;
}
final Set<String> foreignKeyNameSet = deriveForeignKeyLoopSet(foreignKeyMap, tableMeta);
for (String foreignKeyName : foreignKeyNameSet) {
final DfForeignKeyMeta fkMetaInfo = foreignKeyMap.get(foreignKeyName);
final Element fkElement = _doc.createElement("foreign-key");
fkElement.setAttribute("foreignTable", fkMetaInfo.getForeignTablePureName());
fkElement.setAttribute("foreignSchema", fkMetaInfo.getForeignSchema().getIdentifiedSchema());
fkElement.setAttribute("name", fkMetaInfo.getForeignKeyName());
final Map<String, String> columnNameMap = fkMetaInfo.getColumnNameMap();
final Set<String> columnNameKeySet = columnNameMap.keySet();
for (String localColumnName : columnNameKeySet) {
final String foreignColumnName = columnNameMap.get(localColumnName);
final Element referenceElement = _doc.createElement("reference");
referenceElement.setAttribute("local", localColumnName);
referenceElement.setAttribute("foreign", foreignColumnName);
fkElement.appendChild(referenceElement);
}
tableElement.appendChild(fkElement);
}
}
Aggregations