(primitiveType !=null && clr.isAssignableFrom(elementType,primitiveType.getName())))
{
throw new IncompatibleQueryElementTypeException(elementType, filteredElementType.getName());
}
LogicSetExpression ownTblExpr = stmt.newTableExpression(containerTable, listTableAlias);
ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt, ownerTe);
ScalarExpression ownerSetExpr = this.ownerMapping.newScalarExpression(stmt, stmt.getTableExpression(listTableAlias));
if (!parentStmt.hasCrossJoin(ownTblExpr))
{
stmt.crossJoin(ownTblExpr, true);
}
stmt.andCondition(ownerExpr.eq(ownerSetExpr),true);
if (storeMgr.getMappedTypeManager().isSupportedMappedType(filteredElementType.getName()))
{
// Element = Non-PC(embedded)
return elementMapping.newScalarExpression(stmt, stmt.getTableExpression(listTableAlias));
}
else if (elementsAreEmbedded || elementsAreSerialised)
{
// Element = PC(embedded), PC(serialised)
return elementMapping.newScalarExpression(stmt, stmt.getTableExpression(listTableAlias));
}
else
{
// Element = PC
// Join to element table on id column(s) of element
DatastoreClass elementTable = storeMgr.getDatastoreClass(filteredElementType.getName(), stmt.getClassLoaderResolver());
DatastoreClass joiningClass = (elmExpr.getLogicSetExpression() == null ? elementTable : (DatastoreClass)elmExpr.getLogicSetExpression().getMainTable());
JavaTypeMapping elementTableID = joiningClass.getIDMapping();
/* TODO this comment is no longer valid, since we use sub queries
* if elementType == filteredElementType
* INNER JOIN ELEMENT THIS_FILTER_ELEMENT_VARIABLE
* ON THIS_SETTABLE.ELEMENT_EID = THIS_FILTER_ELEMENT_VARIABLE.ELEMENT_ID
*
* else if elementType != filteredElementType but filteredElementType is a superclass of elementType
*
* INNER JOIN FILTER_ELEMENT_TYPE THIS_FILTER_ELEMENT_VARIABLE
* ON THIS_SETTABLE.ELEMENT_EID = THIS_FILTER_ELEMENT_VARIABLE.FILTER_ELEMENT_TYPE_ID */
LogicSetExpression elmTblExpr = stmt.getTableExpression(elementTableAlias);
if (elmTblExpr==null)
{
elmTblExpr = stmt.newTableExpression(elementTable,elementTableAlias);
}
ScalarExpression elmSetExpr = elementMapping.newScalarExpression(stmt, stmt.getTableExpression(listTableAlias));