* @param compositeKeyColumns
* @param processed
* @return
*/
private SimpleValue handleCompositeKey(RootClass rc, Set processedColumns, List keyColumns, Mapping mapping) {
Component pkc = new Component(rc);
pkc.setMetaAttributes(Collections.EMPTY_MAP);
pkc.setEmbedded(false);
String compositeIdName = revengStrategy.tableToCompositeIdName(TableIdentifier.create(rc.getTable()));
if(compositeIdName==null) {
compositeIdName = revengStrategy.classNameToCompositeIdName(rc.getClassName());
}
pkc.setComponentClassName(compositeIdName);
Table table = rc.getTable();
List list = null;
if (cfg.preferBasicCompositeIds() ) {
list = new ArrayList(keyColumns);
}
else {
list = findForeignKeys(table.getForeignKeyIterator(), keyColumns);
}
for (Iterator iter = list.iterator(); iter.hasNext();) {
Object element = iter.next();
Property property;
if (element instanceof Column) {
Column column = (Column) element;
if ( processedColumns.contains(column) ) {
throw new JDBCBinderException("Binding column twice for primary key should not happen: " + column);
}
else {
checkColumn(column);
String propertyName = revengStrategy.columnToPropertyName( TableIdentifier.create(table), column.getName() );
property = bindBasicProperty( makeUnique(pkc, propertyName), table, column, processedColumns, mapping);
processedColumns.add(column);
}
}
else if (element instanceof ForeignKeyForColumns) {
ForeignKeyForColumns fkfc = (ForeignKeyForColumns) element;
ForeignKey foreignKey = fkfc.key;
String propertyName = revengStrategy.foreignKeyToEntityName(
foreignKey.getName(),
TableIdentifier.create(foreignKey.getTable() ),
foreignKey.getColumns(), TableIdentifier.create(foreignKey.getReferencedTable() ), foreignKey.getReferencedColumns(), true
);
property = bindManyToOne( makeUnique(pkc, propertyName), true, table, foreignKey, processedColumns);
processedColumns.addAll(fkfc.columns);
}
else {
throw new JDBCBinderException("unknown thing");
}
markAsUseInEquals(property);
pkc.addProperty(property);
}
return pkc;
}