}
SQLStatement sqlStmt = null;
RDBMSStoreManager storeMgr = (RDBMSStoreManager)this.storeMgr;
final ClassLoaderResolver clr = ownerSM.getExecutionContext().getClassLoaderResolver();
if (elementInfo.length == 1 &&
elementInfo[0].getDatastoreClass().getDiscriminatorMetaData() != null &&
elementInfo[0].getDatastoreClass().getDiscriminatorMetaData().getStrategy() != DiscriminatorStrategy.NONE)
{
String elementType = ownerMemberMetaData.getCollection().getElementType();
if (ClassUtils.isReferenceType(clr.classForName(elementType)))
{
String[] clsNames =
storeMgr.getNucleusContext().getMetaDataManager().getClassesImplementingInterface(elementType, clr);
Class[] cls = new Class[clsNames.length];
for (int i=0; i<clsNames.length; i++)
{
cls[i] = clr.classForName(clsNames[i]);
}
sqlStmt = new DiscriminatorStatementGenerator(storeMgr, clr, cls, true, null, null).getStatement();
}
else
{
sqlStmt = new DiscriminatorStatementGenerator(storeMgr, clr,
clr.classForName(elementInfo[0].getClassName()), true, null, null).getStatement();
}
iterateUsingDiscriminator = true;
// Select the required fields
SQLStatementHelper.selectFetchPlanOfSourceClassInStatement(sqlStmt, resultMapping,
ownerSM.getExecutionContext().getFetchPlan(), sqlStmt.getPrimaryTable(), emd, 0);
}
else
{
for (int i=0;i<elementInfo.length;i++)
{
final Class elementCls = clr.classForName(this.elementInfo[i].getClassName());
UnionStatementGenerator stmtGen = new UnionStatementGenerator(storeMgr, clr, elementCls, true, null, null);
stmtGen.setOption(StatementGenerator.OPTION_SELECT_NUCLEUS_TYPE);
resultMapping.setNucleusTypeColumnName(UnionStatementGenerator.NUC_TYPE_COLUMN);
SQLStatement subStmt = stmtGen.getStatement();