AbstractClassMetaData targetCmd =
storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(className, clr);
discriminatorValue = targetCmd.getInheritanceMetaData().getDiscriminatorMetaData().getValue();
}
SQLExpression discExpr = factory.newExpression(stmt, stmt.getPrimaryTable(), discriminatorMapping);
SQLExpression discVal = factory.newLiteral(stmt, discriminatorMapping, discriminatorValue);
stmt.whereAnd(discExpr.eq(discVal), false);
}
// Eliminate any subclasses (catered for in separate UNION statement)
Iterator<String> subIter = storeMgr.getSubClassesForClass(className, false, clr).iterator();
while (subIter.hasNext())
{
String subclassName = subIter.next();
DatastoreClass[] subclassTables = null;
DatastoreClass subclassTable = storeMgr.getDatastoreClass(subclassName, clr);
if (subclassTable == null)
{
AbstractClassMetaData targetSubCmd =
storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(subclassName, clr);
AbstractClassMetaData[] targetSubCmds = storeMgr.getClassesManagingTableForClass(targetSubCmd, clr);
subclassTables = new DatastoreClass[targetSubCmds.length];
for (int i=0;i<targetSubCmds.length;i++)
{
subclassTables[i] = storeMgr.getDatastoreClass(targetSubCmds[i].getFullClassName(), clr);
}
}
else
{
subclassTables = new DatastoreClass[1];
subclassTables[0] = subclassTable;
}
for (int i=0;i<subclassTables.length;i++)
{
if (subclassTables[i] != table)
{
// Subclass of our class is stored in different table to the candidate so exclude it
// Adds FROM clause of "LEFT OUTER JOIN {subTable} ON ..."
// and WHERE clause of "{subTable}.ID = NULL"
JavaTypeMapping tableIdMapping = table.getIdMapping();
JavaTypeMapping subclassIdMapping = subclassTables[i].getIdMapping();
SQLTable sqlTableSubclass =
stmt.leftOuterJoin(null, tableIdMapping, subclassTables[i], null, subclassIdMapping,
null, stmt.getPrimaryTable().getGroupName());
SQLExpression subclassIdExpr = factory.newExpression(stmt, sqlTableSubclass, subclassIdMapping);
SQLExpression nullExpr = new NullLiteral(stmt, null, null, null);
stmt.whereAnd(subclassIdExpr.eq(nullExpr), false);
}
}
}