throw new IncompatibleQueryElementTypeException(valueType, filteredValueType==null ? null : filteredValueType.getName());
}
// Join the map table on the owner ID column
LogicSetExpression mapTblExpr = stmt.newTableExpression(mapTable, mapTableAlias);
ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt,ownerTe);
ScalarExpression ownerMapExpr = this.ownerMapping.newScalarExpression(stmt, stmt.getTableExpression(mapTableAlias));
if( !parentStmt.hasCrossJoin(mapTblExpr) )
{
stmt.crossJoin(mapTblExpr, true);
}
stmt.andCondition(ownerExpr.eq(ownerMapExpr),true);
if (storeMgr.getMappedTypeManager().isSupportedMappedType(filteredValueType.getName()))
{
// Value = Non-PC(embedded)
return valueMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
}
else if (valuesAreEmbedded || valuesAreSerialised)
{
// Value = PC(embedded), PC(serialised)
return valueMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
}
else
{
// Value = PC
// Join the value table on the value ID column
DatastoreClass valueTable=storeMgr.getDatastoreClass(filteredValueType.getName(), stmt.getClassLoaderResolver());
JavaTypeMapping valueTableID = valueTable.getIDMapping();
LogicSetExpression valueTblExpr = stmt.getTableExpression(valueTableAlias);
if (valueTblExpr == null)
{
valueTblExpr = stmt.newTableExpression(valueTable,valueTableAlias);
}
ScalarExpression valueMapExpr = valueMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
if (!parentStmt.hasCrossJoin(valueTblExpr))
{
stmt.crossJoin(valueTblExpr, true);
}
if (valExpr == null)
{
valExpr = valueTableID.newScalarExpression(stmt, stmt.getTableExpression(valueTableAlias));
}
if (valExpr.getLogicSetExpression() != null &&
!valueTable.equals(valExpr.getLogicSetExpression().getMainTable()))
{
//valExpr might express a FK in another to the VALUE table
stmt.andCondition(valueMapExpr.eq(valExpr),true);
return this.valueMapping.newScalarExpression(stmt,stmt.getTableExpression(mapTableAlias));
}
else
{
//valExpr might be a PK of the VALUE table
ScalarExpression valueExpr = valueTableID.newScalarExpression(stmt, stmt.getTableExpression(valueTableAlias));
stmt.andCondition(valueMapExpr.eq(valueExpr),true);
return valueExpr;
}
}
}