*/
public GenClassMapping createGenClassMapping(
GenClassRef gcr,
SpeedoField sf,
Mapping mapping) throws PException, SpeedoException {
RdbGenClassMapping rgcm = new RdbGenClassMapping("to-table", gcr,
mapping);
mapping.addGenClassMapping(gcr.getGenClassId(), rgcm);
RdbTable t = null;
if (gcr.isPrimitive()) {
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "The GCR field " + gcr.getName()
+ " is mappeded over a dedicated table: "
+ sf.join.extTable.name);
}
//Create the RdbTable for the Generic class
rgcm.createRdbTable(sf.join.extTable.name);
} else if (gcr.isClassRef()) {
SpeedoField reverseField = sf.getReverseField();
SpeedoClass tclass = sf.moClass.getSpeedoClassFromContext(
gcr.getClassRef().getMOClass().getFQName());
Class targetClassJMO = tclass.jormclass;
mapping.getClassMapping().addDependency(targetClassJMO.getFQName());
switch (sf.relationType) {
case SpeedoField.MANY_MANY_BI_RELATION:
//Create the join table for the Generic class
t = rgcm.createRdbTable(sf.join.extTable.name);
if (reverseField.mappedByReversefield
|| (reverseField.join != null
&& reverseField.join.extTable != null
&& t.getName().equalsIgnoreCase(reverseField.join.extTable.name))) {
//The MANY-MANY relation is mapped over the same join table
if (sf.name.compareToIgnoreCase(reverseField.name) < 0) {
// master side is not randomly choosen
t.setColocatedMaster(true);
} else {
//write are done only on master side. The slave side
// reads only the generic class
t.setReadOnly(true);
t.setColocated(true);
}
}
if (logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "Many-Many relation,"
+ " join table: " + t.getName()
+ (t.isColocated()?", colocated":"")
+ (t.isColocatedMaster()?", master":"")
+ (t.isReadOnly()?", readonly":"")
);
}
break;
case SpeedoField.ONE_MANY_BI_RELATION:
reverseField = sf.getReverseField();
RdbClassMultiMapping trcm = (RdbClassMultiMapping) getClassMapping(
mapping, targetClassJMO);
if (sf.mappedByReversefield) {
RdbTable tTable;
SpeedoTable table;
if (reverseField.join != null) {
table = reverseField.join.extTable;
tTable = trcm.getRdbExternalTable(table.name);
} else {
table = reverseField.moClass.mainTable;
tTable = trcm.getRdbTable();
}
t = rgcm.createRdbTable(table.name);
tTable.setColocated(true);
t.setColocated(true);
tTable.setColocatedMaster(true);
t.setColocatedMaster(false);
trcm.addDependency(sf.moClass.getFQName());
if (sf.isCoherentReverseField) {
//optimisation: the reverse field assumes the coherence.
// Then there is no need to write the generic class.
t.setReadOnly(true);
}
} else if (sf.join != null) {
t = rgcm.createRdbTable(sf.join.extTable.name);
}
if (t != null && logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "One-Many relation,"
+ " join table: " + t.getName()
+ (t.isColocated()?", colocated":"")
+ (t.isColocatedMaster()?", master":"")
+ (t.isReadOnly()?", readonly":"")
);
}
break;
default:
//Create the RdbTable for the Generic class
rgcm.createRdbTable(sf.join.extTable.name);
//add the dependency
trcm = (RdbClassMultiMapping) getClassMapping(mapping, targetClassJMO);
trcm.addDependency(sf.moClass.getFQName());
if (t != null && logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG, "GCR field,"