if (hasDiscriminator && restrictDiscriminator)
{
// Add the discriminator required values to the WHERE clause
// Loop through each possible candidate type and add the discrim values for each branch
boolean multipleDiscriminatorValues = candidateTypes.length > 1 ? true: false;
BooleanExpression discExpr = null;
for (int i=0; i<candidateTypes.length; i++)
{
// For this candidate type, go through the possible classes persistable in this table and add an OR to the WHERE clause
String candidateName = candidateTypes[i].getName();
BooleanExpression discExprCand = getExpressionForDiscriminatorForClass(stmt, candidateName,
dismd, discriminatorMapping, discrimTableExpr, storeMgr);
if (discExpr != null)
{
discExpr = discExpr.ior(discExprCand);
}
else
{
discExpr = discExprCand;
}
if (includeSubclasses)
{
Iterator iterator = storeMgr.getSubClassesForClass(candidateName, true, clr).iterator();
while (iterator.hasNext())
{
String subCandidateType = (String)iterator.next();
BooleanExpression discExprSub = getExpressionForDiscriminatorForClass(stmt,
subCandidateType, dismd, discriminatorMapping, discrimTableExpr, storeMgr);
discExpr = discExpr.ior(discExprSub);
if (!multipleDiscriminatorValues)
{
multipleDiscriminatorValues = true;
}
}
}
}
if (allowNulls)
{
// Allow for null value of discriminator
ScalarExpression expr = discriminatorMapping.newScalarExpression(stmt, discrimTableExpr);
ScalarExpression val = new NullLiteral(stmt);
BooleanExpression nullDiscExpr = expr.eq(val);
discExpr = discExpr.ior(nullDiscExpr);
if (!multipleDiscriminatorValues)
{
multipleDiscriminatorValues = true;
}