protected SQLStatement getSQLStatementForIterator(ObjectProvider ownerSM)
{
SQLStatement sqlStmt = null;
// TODO This is the same as RDBMSJoinSetStore
final ClassLoaderResolver clr = ownerSM.getExecutionContext().getClassLoaderResolver();
RDBMSStoreManager storeMgr = (RDBMSStoreManager)this.storeMgr;
SQLExpressionFactory exprFactory = storeMgr.getSQLExpressionFactory();
if (elementsAreEmbedded || elementsAreSerialised)
{
// Element = embedded, serialised (maybe Non-PC)
// Just select the join table since we're going to return the embedded/serialised columns from it
sqlStmt = new SQLStatement(storeMgr, containerTable, null, null);
sqlStmt.setClassLoaderResolver(clr);
// Select the element column - first select is assumed by SetStoreIterator
sqlStmt.select(sqlStmt.getPrimaryTable(), elementMapping, null);
}
else if (elementMapping instanceof ReferenceMapping)
{
// Element = Reference type (interface/Object)
// Just select the join table since we're going to return the implementation id columns only
sqlStmt = new SQLStatement(storeMgr, containerTable, null, null);
sqlStmt.setClassLoaderResolver(clr);
// Select the reference column(s) - first select is assumed by SetStoreIterator
sqlStmt.select(sqlStmt.getPrimaryTable(), elementMapping, null);
}
else
{
// Element = PC
// Join to the element table(s)
iteratorMappingClass = new StatementClassMapping();
for (int i = 0; i < elementInfo.length; i++)
{
// TODO This will only work if all element types have a discriminator
final int elementNo = i;
final Class elementCls = clr.classForName(elementInfo[elementNo].getClassName());
SQLStatement elementStmt = null;
if (elementInfo[elementNo].getDiscriminatorStrategy() != null &&
elementInfo[elementNo].getDiscriminatorStrategy() != DiscriminatorStrategy.NONE)
{
// The element uses a discriminator so just use that in the SELECT
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 j = 0; j < clsNames.length; j++)
{
cls[j] = clr.classForName(clsNames[j]);
}
StatementGenerator stmtGen = new DiscriminatorStatementGenerator(storeMgr, clr, cls,
true, null, null, containerTable, null, elementMapping);
if (allowNulls)