SpeedoCommonField sf,
NameDef nd,
RdbClassMultiMapping trcm,
NameDef tnd,
SpeedoClass tclass) throws PException, SpeedoException {
RdbExternalTable exttable = rcm.createRdbExternalTable(sf.join.extTable.name);
if (sf.join.extTable.name.equals(tclass.mainTable.name)) {
// The external table is the table of the targeted class
exttable.setColocated(true);
trcm.getRdbTable().setColocated(true);
trcm.getRdbTable().setColocatedMaster(true);
trcm.addDependency(sf.moClass.getFQName());
rcm.addDependency(tclass.getFQName());
//optimisation: if there is a reverse field then we suppose
// that the user will do the coherence.
if (sf instanceof SpeedoField) {
exttable.setReadOnly(((SpeedoField) sf).isCoherentReverseField);
} else if (sf instanceof SpeedoInheritedField) {
exttable.setReadOnly(((SpeedoInheritedField) sf).inheritedField.isCoherentReverseField);
}
exttable.setColocated(true);
exttable.setColocatedMaster(false);
}
//Define the join to the external table
RdbJoin j = exttable.createRdbJoin(sf.name);
for (Iterator fkColIt = sf.join.columns.iterator(); fkColIt
.hasNext();) {
SpeedoJoinColumn jc = (SpeedoJoinColumn) fkColIt.next();
j.addJoinColumnNames(jc.targetColumn, jc.column.name);
}
// map the name def over pk field of the referenced class
if (tnd.isFieldName()) {
RdbPrimitiveElementMapping pem = (RdbPrimitiveElementMapping) trcm
.getPrimitiveElementMapping(tnd.getFieldName(), true);
PrimitiveElement pe = (PrimitiveElement) jclass
.getTypedElement(nd.getFieldName());
exttable.createPrimitiveElementMapping(pe, pem.getName(),
null, false, j);
} else {
Map tclassndproj = tnd.getNameRef().getProjection();
Iterator it = nd.getNameRef().getProjection().entrySet()
.iterator();
while (it.hasNext()) {
Map.Entry me = (Map.Entry) it.next();
PrimitiveElement pe = (PrimitiveElement) jclass
.getTypedElement((String) me.getValue());
RdbPrimitiveElementMapping pem = (RdbPrimitiveElementMapping)
trcm.getPrimitiveElementMapping(
(String) tclassndproj.get(me.getKey()), true);
exttable.createPrimitiveElementMapping(pe, pem.getName(), null, false, j);
}
}
}