}
if (!existsQuery)
{
// Not part of an EXISTS subquery
LogicSetExpression ownTblExpr = stmt.newTableExpression(containerTable, setTableAlias);
if (!parentStmt.hasCrossJoin(ownTblExpr) &&
!stmt.getMainTableExpression().equals(ownTblExpr))
{
// Parent doesnt have the collection table, and not the candidate here so cross join to it
stmt.crossJoin(ownTblExpr, true);
}
// Reverse collection contains query so join back to the owner
ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, ownerTblExpr);
ScalarExpression ownerSetExpr = this.ownerMapping.newScalarExpression(stmt,
stmt.getTableExpression(setTableAlias));
stmt.andCondition(ownerExpr.eq(ownerSetExpr), true);
}
if (storeMgr.getOMFContext().getTypeManager().isSupportedType(filteredElementType.getName()))
{
// Element = Non-PC(embedded)
return elementMapping.newScalarExpression(stmt, stmt.getTableExpression(setTableAlias));
}
else if (elementsAreEmbedded || elementsAreSerialised)
{
// Element = PC(embedded), PC(serialised)
return elementMapping.newScalarExpression(stmt, stmt.getTableExpression(setTableAlias));
}
else
{
// Element = PC
// Join to element table on id column(s) of element
DatastoreClass elementTable = storeMgr.getDatastoreClass(filteredElementType.getName(), clr);
DatastoreClass joiningClass = (elementExpr.getLogicSetExpression() == null ?
elementTable : (DatastoreClass)elementExpr.getLogicSetExpression().getMainTable());
JavaTypeMapping elementTableID = joiningClass.getIDMapping();
// Get expression for the element table, allowing for it existing in this query or the parent query
LogicSetExpression elmTblExpr = stmt.getTableExpression(elementTableAlias);
if (elmTblExpr == null)
{
// Note : we only use the parentStmt if not an unbound variable. Unbound variables may be registered
// with the parent but not yet bound so ignore the parent for those
if (!(elementExpr instanceof UnboundVariable) && parentStmt != stmt)