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;
}
}
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());
}
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);
}
Aggregations