public void map(boolean adapt) {
field.getValueInfo().assertNoSchemaComponents(field, !adapt);
field.getKeyMapping().getValueInfo().assertNoSchemaComponents
(field.getKey(), !adapt);
ValueMapping elem = field.getElementMapping();
if (elem.getTypeCode() != JavaTypes.PC || elem.isEmbeddedPC()
|| !elem.getTypeMapping().isMapped())
throw new MetaDataException(_loc.get("not-elem-relation", field));
// check for named inverse
FieldMapping mapped = field.getMappedByMapping();
FieldMappingInfo finfo = field.getMappingInfo();
ValueMappingInfo vinfo = elem.getValueInfo();
boolean criteria = vinfo.getUseClassCriteria();
if (mapped != null) {
mapped.resolve(mapped.MODE_META | mapped.MODE_MAPPING);
if (!(mapped.getStrategy() instanceof RelationFieldStrategy))
throw new MetaDataException(_loc.get("not-inv-relation",
field, mapped));
vinfo.assertNoSchemaComponents(elem, !adapt);
elem.setForeignKey(mapped.getForeignKey
(field.getDefiningMapping()));
elem.setColumns(mapped.getDefiningMapping().
getPrimaryKeyColumns());
elem.setJoinDirection(ValueMapping.JOIN_EXPECTED_INVERSE);
elem.setUseClassCriteria(criteria);
field.setOrderColumn(finfo.getOrderColumn(field,
mapped.getForeignKey().getTable(), adapt));
field.setOrderColumnIO(finfo.getColumnIO());
return;
}
// map inverse foreign key in related table
ForeignKey fk = vinfo.getInverseTypeJoin(elem, field.getName(), adapt);
elem.setForeignKey(fk);
elem.setColumnIO(vinfo.getColumnIO());
elem.setColumns(elem.getTypeMapping().getPrimaryKeyColumns());
elem.setJoinDirection(ValueMapping.JOIN_EXPECTED_INVERSE);
elem.setUseClassCriteria(criteria);
elem.mapConstraints(field.getName(), adapt);
field.setOrderColumn(finfo.getOrderColumn(field, fk.getTable(),
adapt));
field.setOrderColumnIO(finfo.getColumnIO());
}