if (hasDiscriminator && restrictDiscriminator)
{
// Add the discriminator expression to restrict accepted values
boolean multipleCandidates = false;
BooleanExpression discExpr = null;
if (candidates != null)
{
// Multiple candidates
if (candidates.length > 1)
{
multipleCandidates = true;
}
for (int i=0;i<candidates.length;i++)
{
BooleanExpression discExprCandidate =
SQLStatementHelper.getExpressionForDiscriminatorForClass(stmt,
candidates[i].getName(), dismd, discMapping, discrimSqlTbl, clr);
if (discExpr != null)
{
discExpr = discExpr.ior(discExprCandidate);
}
else
{
discExpr = discExprCandidate;
}
if (includeSubclasses)
{
HashSet<String> subclassNames = storeMgr.getSubClassesForClass(candidateType.getName(), true, clr);
Iterator<String> subclassIter = subclassNames.iterator();
if (!multipleCandidates)
{
multipleCandidates = (subclassNames.size() > 0);
}
while (subclassIter.hasNext())
{
String subclassName = subclassIter.next();
BooleanExpression discExprSub =
SQLStatementHelper.getExpressionForDiscriminatorForClass(stmt, subclassName,
dismd, discMapping, discrimSqlTbl, clr);
discExpr = discExpr.ior(discExprSub);
}
}
}
}
else
{
// Single candidate
discExpr = SQLStatementHelper.getExpressionForDiscriminatorForClass(stmt,
candidateType.getName(), dismd, discMapping, discrimSqlTbl, clr);
if (includeSubclasses)
{
HashSet<String> subclassNames = storeMgr.getSubClassesForClass(candidateType.getName(), true, clr);
Iterator<String> subclassIter = subclassNames.iterator();
multipleCandidates = (subclassNames.size() > 0);
while (subclassIter.hasNext())
{
String subclassName = subclassIter.next();
BooleanExpression discExprCandidate =
SQLStatementHelper.getExpressionForDiscriminatorForClass(stmt, subclassName,
dismd, discMapping, discrimSqlTbl, clr);
discExpr = discExpr.ior(discExprCandidate);
}
}
}
if (hasOption(OPTION_ALLOW_NULLS))
{
// Allow for null value of discriminator
SQLExpression expr = stmt.getSQLExpressionFactory().newExpression(stmt, discrimSqlTbl,
discMapping);
SQLExpression val = new NullLiteral(stmt, null, null, null);
BooleanExpression nullDiscExpr = expr.eq(val);
discExpr = discExpr.ior(nullDiscExpr);
if (!multipleCandidates)
{
multipleCandidates = true;
}