private static final Collection.Key TYPE = CommonUtil.createKey("type");
public static void createXMLMapping(PageContext pc,DatasourceConnection dc, Component cfc,Element hibernateMapping,SessionFactoryData data) throws PageException {
// MUST Support for embeded objects
Struct meta = cfc.getMetaData(pc);
String extend = cfc.getExtends();
boolean isClass=Util.isEmpty(extend);
// MZ: Fetches all inherited persistent properties
//Property[] _props=getAllPersistentProperties(pc,cfc,dc,meta,isClass);
Property[] _props=getProperties(pc,cfc,dc,meta,isClass, true,data);
Map<String, PropertyCollection> joins=new HashMap<String, PropertyCollection>();
PropertyCollection propColl = splitJoins(cfc,joins, _props,data);
// create class element and attach
Document doc = CommonUtil.getDocument(hibernateMapping);
StringBuilder comment=new StringBuilder();
comment.append("\nsource:").append(cfc.getPageSource().getDisplayPath());
comment.append("\ncompilation-time:").append(CommonUtil.createDateTime(HibernateUtil.getCompileTime(pc,cfc.getPageSource()))).append("\n");
hibernateMapping.appendChild(doc.createComment(comment.toString()));
//print.e(cfc.getAbsName()+";"+isClass+" -> "+cfci.getBaseAbsName()+":"+cfci.isBasePeristent());
if(!isClass && !cfc.isBasePeristent()) {
isClass=true;
}
Element join=null;
boolean doTable=true;
Element clazz;
if(isClass) {
clazz = doc.createElement("class");
hibernateMapping.appendChild(clazz);
}
// extended CFC
else{
// MZ: Fetches one level deep
_props=getProperties(pc,cfc,dc,meta,isClass, false,data);
// MZ: Reinitiate the property collection
propColl = splitJoins(cfc,joins, _props,data);
String ext = CommonUtil.last(extend,'.').trim();
try {
Component base = data.getEntityByCFCName(ext, false);
ext = HibernateCaster.getEntityName(base);
}
catch(Throwable t){}
String discriminatorValue = toString(cfc,null,meta,"discriminatorValue",data);
if(!Util.isEmpty(discriminatorValue,true)) {
doTable=false;
clazz = doc.createElement("subclass");
hibernateMapping.appendChild(clazz);
//addClassAttributes(classNode);
clazz.setAttribute("extends", ext);
clazz.setAttribute("discriminator-value", discriminatorValue);
String joincolumn = toString(cfc,null,meta,"joincolumn",false,data);
if(!Util.isEmpty(joincolumn)){
join = doc.createElement("join");
clazz.appendChild(join);
doTable=true;
Element key = doc.createElement("key");
join.appendChild(key);
key.setAttribute("column", formatColumn(joincolumn,data));
}
}
else {
// MZ: Match on joinColumn for a joined subclass, otherwise use a union subclass
String joinColumn = toString(cfc,null,meta,"joincolumn",false,data);
if (!Util.isEmpty(joinColumn,true)) {
clazz = doc.createElement("joined-subclass");
hibernateMapping.appendChild( clazz);
clazz.setAttribute("extends",ext);
Element key = doc.createElement("key");
clazz.appendChild(key);
key.setAttribute("column", formatColumn(joinColumn,data));
}
else {
// MZ: When no joinColumn exists, default to an explicit table per class
clazz = doc.createElement("union-subclass");
clazz.setAttribute("extends",ext);
doTable = true;
hibernateMapping.appendChild( clazz);
}
}
}
//createXMLMappingTuplizer(clazz,pc);
addGeneralClassAttributes(pc,cfc,meta,clazz,data);
String tableName=getTableName(pc,meta,cfc,data);
if(join!=null) clazz=join;
if(doTable)addGeneralTableAttributes(pc,cfc,meta,clazz,data);
Struct columnsInfo=null;
if(data.getORMConfiguration().useDBForMapping()){
columnsInfo = data.getTableInfo(dc,getTableName(pc, meta, cfc,data));
}
if(isClass)setCacheStrategy(cfc,null,doc, meta, clazz,data);