!clr.isAssignableFrom(filteredKeyType, keyType))
{
throw new IncompatibleQueryElementTypeException(keyType, filteredKeyType.getName());
}
ScalarExpression ownerExpr = ownerMapping.newScalarExpression(stmt,te);
DatastoreIdentifier containerRangeVar = mapTableAlias;
if (stmt.getTableExpression(containerRangeVar) == null)
{
containerRangeVar = keyTableAlias;
}
// Join the map table on the owner ID column
stmt.newTableExpression(mapTable, containerRangeVar);
ScalarExpression ownerMapExpr = this.ownerMapping.newScalarExpression(stmt,stmt.getTableExpression(containerRangeVar));
stmt.andCondition(ownerExpr.eq(ownerMapExpr),true);
// This depends on whether we have a separate key table or not
if (!storeMgr.getMappedTypeManager().isSupportedMappedType(filteredKeyType.getName()))
{
// Join the key table on the key ID column (if theres a key table)
DatastoreContainerObject filteredKeyTable = storeMgr.getDatastoreClass(filteredKeyType.getName(), stmt.getClassLoaderResolver());
JavaTypeMapping keyTableID = filteredKeyTable.getIDMapping();
stmt.newTableExpression(filteredKeyTable, keyTableAlias);
ScalarExpression keyMapExpr = keyMapping.newScalarExpression(stmt,stmt.getTableExpression(containerRangeVar));
ScalarExpression keyExpr = keyTableID.newScalarExpression(stmt, stmt.getTableExpression(keyTableAlias));
stmt.innerJoin(keyExpr,keyMapExpr,stmt.getTableExpression(keyTableAlias), true, true);
return keyTableID.newScalarExpression(stmt, stmt.getTableExpression(keyTableAlias));
}
else