Search in sources :

Example 1 with Reference

use of org.apache.ddlutils.model.Reference in project tmdmaker by tmdmaker.

the class DdlUtilsConverter method convert.

/**
 * Re-Used 列を DdlUtils の Reference のリストに変換する
 */
private List<Reference> convert(ReusedIdentifier reused) {
    List<Reference> refences = new ArrayList<Reference>();
    if (reused.isSurrogateKeyEnabled()) {
        // 再帰表の場合を考慮して1つ目のみを取得
        SurrogateKeyRef sref = reused.getSurrogateKeys().get(0);
        Column localColumn = convert(sref);
        Column originalColumn = convert(sref.getOriginal());
        addReference(refences, localColumn, originalColumn);
        return refences;
    } else {
        List<IdentifierRef> list = reused.getUniqueIdentifiers();
        int reusedCount = list.size();
        // 再帰表は同一Reused×2となっているため1つ目のみを取得する
        if (isRecursive(reused)) {
            reusedCount = reusedCount / 2;
        }
        for (int i = 0; i < reusedCount; i++) {
            IdentifierRef iref = list.get(i);
            Column localColumn = convert(iref);
            Column originalColumn = convert(iref.getOriginal());
            addReference(refences, localColumn, originalColumn);
        }
        return refences;
    }
}
Also used : SurrogateKeyRef(org.tmdmaker.core.model.SurrogateKeyRef) IndexColumn(org.apache.ddlutils.model.IndexColumn) Column(org.apache.ddlutils.model.Column) Reference(org.apache.ddlutils.model.Reference) ArrayList(java.util.ArrayList) IdentifierRef(org.tmdmaker.core.model.IdentifierRef)

Example 2 with Reference

use of org.apache.ddlutils.model.Reference in project tmdmaker by tmdmaker.

the class DdlUtilsConverter method addReference.

private void addReference(List<Reference> refences, Column localColumn, Column originalColumn) {
    Reference reference = new Reference(localColumn, originalColumn);
    refences.add(reference);
    logger.debug("参照: {}->{}", localColumn.getName(), originalColumn.getName());
}
Also used : Reference(org.apache.ddlutils.model.Reference)

Example 3 with Reference

use of org.apache.ddlutils.model.Reference in project tmdmaker by tmdmaker.

the class ForeignConstraints method addForeignKey.

/**
 * 再帰表の外部キー設定
 *
 * @param foreignTable
 * @param references
 * @param no
 */
private void addForeignKey(Table foreignTable, List<Reference> references, Integer no) {
    String foreignKeyName;
    if (no != null) {
        foreignKeyName = "FK_" + no.toString() + foreignTable.getName();
    } else {
        foreignKeyName = "FK_" + foreignTable.getName();
    }
    ForeignKey foreignKey = new ForeignKey(foreignKeyName);
    for (Reference ref : references) {
        foreignKey.addReference(ref);
    }
    foreignKey.setForeignTable(foreignTable);
    table.addForeignKey(foreignKey);
}
Also used : Reference(org.apache.ddlutils.model.Reference) ForeignKey(org.apache.ddlutils.model.ForeignKey)

Aggregations

Reference (org.apache.ddlutils.model.Reference)3 ArrayList (java.util.ArrayList)1 Column (org.apache.ddlutils.model.Column)1 ForeignKey (org.apache.ddlutils.model.ForeignKey)1 IndexColumn (org.apache.ddlutils.model.IndexColumn)1 IdentifierRef (org.tmdmaker.core.model.IdentifierRef)1 SurrogateKeyRef (org.tmdmaker.core.model.SurrogateKeyRef)1