use of orgomg.cwm.objectmodel.core.StructuralFeature in project tdq-studio-se by Talend.
the class UpdateRelationalSwitch method caseForeignKey.
@Override
public Boolean caseForeignKey(ForeignKey object) {
ColumnSet columnSet = (ColumnSet) object.eContainer();
if (columnSet == null) {
return Boolean.FALSE;
}
ForeignKey rightColumn = null;
if (rightElement instanceof ForeignKey) {
rightColumn = (ForeignKey) rightElement;
} else {
return Boolean.FALSE;
}
object.setName(rightColumn.getName());
object.getFeature().clear();
List<StructuralFeature> refColumns = new ArrayList<StructuralFeature>();
for (StructuralFeature newColumn : rightColumn.getFeature()) {
for (Feature column : columnSet.getFeature()) {
if (column.getName().equalsIgnoreCase(newColumn.getName())) {
refColumns.add((StructuralFeature) column);
break;
}
}
}
object.getFeature().addAll(refColumns);
return Boolean.TRUE;
}
use of orgomg.cwm.objectmodel.core.StructuralFeature in project tdq-studio-se by Talend.
the class UniquePkAndFkTask method checkPkAndFk.
/**
* DOC zshen Comment method "checkPkAndFk".
*
* @param element
* @return merge pks or fks if their name is same each other
*/
private Boolean checkPkAndFk(TdTable element) {
boolean needToSave = false;
// case pk
if (TableHelper.getPrimaryKeys(element).size() > 1) {
List<PrimaryKey> primaryKeyList = TableHelper.getPrimaryKeys(element);
for (int i = 1; i < primaryKeyList.size(); i++) {
PrimaryKey pk = primaryKeyList.get(i);
TdColumn column = (TdColumn) pk.getFeature().get(pk.getFeature().size() - 1);
// remove old pk from column
ColumnHelper.removePrimaryKey(column);
// add new pk to column
column.getUniqueKey().add(primaryKeyList.get(0));
// add column to new pk
primaryKeyList.get(0).getFeature().add(column);
// remove old pk from table
TableHelper.removeTableKey(element, pk);
}
needToSave = true;
}
// case fk
if (TableHelper.getForeignKeys(element).size() > 1) {
Map<String, ForeignKey> foreignKeySet = new HashMap<String, ForeignKey>();
List<ForeignKey> foreignKeyList = TableHelper.getForeignKeys(element);
for (int i = 0; i < foreignKeyList.size(); i++) {
ForeignKey fk = foreignKeyList.get(i);
if (foreignKeySet.get(fk.getName()) != null) {
foreignKeySet.get(fk.getName()).getFeature().addAll(fk.getFeature());
StructuralFeature[] structFeatureArray = fk.getFeature().toArray(new StructuralFeature[fk.getFeature().size()]);
for (StructuralFeature fkFeature : structFeatureArray) {
TdColumn fkColumn = (TdColumn) fkFeature;
fkColumn.getKeyRelationship().remove(fk);
fkColumn.getKeyRelationship().add(foreignKeySet.get(fk.getName()));
}
// remove old fk from table
TableHelper.removeForeignKey(element, fk);
needToSave = true;
} else {
foreignKeySet.put(fk.getName(), fk);
}
}
}
return Boolean.valueOf(needToSave);
}
Aggregations