public ClassMapping createClassMapping(
Class clazz,
SpeedoClass sc,
Mapping mapping) throws PException, SpeedoException {
//build ClassMapping instance
RdbClassMultiMapping rcm =
new RdbClassMultiMapping("multi-table", clazz, mapping);
mapping.setClassMapping(rcm);
//Build JORM meta objects for the main table
if (sc.mainTable != null) {
if (debug) {
logger.log(BasicLevel.DEBUG, "define main table '"
+ sc.mainTable.name + "' of the class '"
+ sc.getFQName() + "'.");
}
rcm.createRdbTable(sc.mainTable.name);
}
//Build JORM meta objects for the secondary (external) tables
if (sc.joinToExtTables != null) {
for (int i = 0; i < sc.joinToExtTables.length; i++) {
RdbExternalTable extTable = rcm
.createRdbExternalTable(sc.joinToExtTables[i].extTable.name);
RdbJoin join = extTable.createRdbJoin("_" + i);
if (debug) {
logger.log(BasicLevel.DEBUG, "define external table '"
+ sc.joinToExtTables[i].extTable.name
+ "' for the class '" + sc.getFQName() + "'.");
}
for (Iterator it = sc.joinToExtTables[i].columns.iterator(); it
.hasNext();) {
SpeedoJoinColumn jc = (SpeedoJoinColumn) it.next();
join.addJoinColumnNames(jc.targetColumn,
jc.column.name);
if (debug) {
logger.log(BasicLevel.DEBUG,
"\tdefine join between columns '"
+ jc.column.name + "' and '"
+ jc.column.targetColumn + "'.");
}
}
}
}
//manage inheritance
if (sc.inheritance != null && sc.inheritance.superClassName != null) {
String ruleName = null;
if (sc.inheritance.isFilteredMapping()) {
ruleName = RdbClassMapping.MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES;
} else if (sc.inheritance.isHorizontalMapping()) {
ruleName = RdbClassMapping.REMAP_FIELDS_TO_NEW_STRUCTURES;
} else if (sc.inheritance.isVerticalMapping()) {
ruleName = RdbClassMapping.MAP_NEW_FIELDS_TO_ADDED_STRUCTURES;
//TODO: link the main table to the one of the parent
}
SpeedoClass parent = sc.getSpeedoClassFromContext(sc
.getSuperClassName());
rcm.createParentClassMapping(ruleName, sc.jormclass
.getSuperClass(parent.getFQName()));
//Add inter dependencies between the parent and its child
if (debug) {
logger.log(BasicLevel.DEBUG, "Add dependencies between "
+ parent.getFQName() + " and " + sc.getFQName());
}
rcm.addDependency(parent.getFQName());
getClassMapping(mapping, parent.jormclass).addDependency(
sc.getFQName());
}
return rcm;
}