Search in sources :

Example 11 with DfForeignKeyMeta

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);
    }
}
Also used : Element(org.w3c.dom.Element) DfForeignKeyMeta(org.dbflute.logic.jdbc.metadata.info.DfForeignKeyMeta)

Aggregations

DfForeignKeyMeta (org.dbflute.logic.jdbc.metadata.info.DfForeignKeyMeta)11 Map (java.util.Map)3 StringKeyMap (org.dbflute.helper.StringKeyMap)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 UnifiedSchema (org.apache.torque.engine.database.model.UnifiedSchema)2 DfForeignKeyExtractor (org.dbflute.logic.jdbc.metadata.basic.DfForeignKeyExtractor)2 DfSynonymMeta (org.dbflute.logic.jdbc.metadata.info.DfSynonymMeta)2 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Comparator (java.util.Comparator)1 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 SQLFailureException (org.dbflute.exception.SQLFailureException)1 DfPrimaryKeyMeta (org.dbflute.logic.jdbc.metadata.info.DfPrimaryKeyMeta)1 DfTableMeta (org.dbflute.logic.jdbc.metadata.info.DfTableMeta)1