* Convenience method to process the candidates for this query.
* Processes the "candidateClassName" and "candidateClass" and sets up "candidates".
*/
protected void compileCandidates()
{
ObjectManager om = query.getObjectManager();
if (parentExpr != null)
{
// Subquery, so cater for different ways of specifying the candidate class
if (subqueryCandidateExpr != null)
{
// Query being treated as a subquery for this compilation
if (query.getCandidateClassName() == null)
{
// No candidate class specified for subquery somehow, so derive from candidate-expression
Class candCls = getClassForSubqueryCandidateExpression();
query.setCandidateClassName(candCls.getName());
}
}
else
{
// Single-string subquery
String from = query.getFrom();
if (from != null)
{
if (from.indexOf(' ') > 0)
{
// "<candidate-expression> alias"
String candidateExpr = from.substring(0, from.indexOf(' ')).trim();
if (candidateExpr.startsWith("this"))
{
// <candidate-expression> is an expression for joining to the parent query
subqueryCandidateExpr = candidateExpr.trim();
Class cls = getClassForSubqueryCandidateExpression();
query.setCandidateClassName(cls.getName());
}
else
{
// <candidate-expression> is a class
query.setCandidateClassName(candidateExpr);
}
this.candidateAlias = from.substring(from.indexOf(' ')+1).trim();
this.subqueryAliasSet = true;
}
else
{
if (from.startsWith("this"))
{
// <candidate-expression> is an expression for joining to the parent query
subqueryCandidateExpr = from.trim();
Class cls = getClassForSubqueryCandidateExpression();
query.setCandidateClassName(cls.getName());
}
else
{
// <candidate-expression> is a class
query.setCandidateClassName(from);
}
}
}
}
if (this.candidateAlias.equals("this"))
{
// Cant use "this" in subquery so replace with something else
this.candidateAlias = "SUB"; // TODO Parameterise this as a config option
}
}
// Check the candidate class existence
String candidateClassName = query.getCandidateClassName();
if (candidateClass == null && candidateClassName != null)
{
try
{
candidateClass = om.getClassLoaderResolver().classForName(candidateClassName, true);
}
catch (JPOXException jpe)
{
candidateClass = query.resolveClassDeclaration(candidateClassName);
}
}
// Set the "candidates"
Extent candidateExtent = ((AbstractJavaQuery)query).getCandidateExtent();
Collection candidateCollection = ((AbstractJavaQuery)query).getCandidateCollection();
if (candidateExtent != null)
{
candidates = (Queryable)candidateExtent;
}
else if (candidateCollection != null)
{
candidates = new CollectionCandidates(om, candidateClass, candidateCollection);
}
else
{
if (candidateClass == null)
{
throw new JPOXUserException(LOCALISER.msg("042001"));
}
candidates = (Queryable)om.getExtent(candidateClass, query.isSubclasses());
}
String result = query.getResult();
if (result != null)
{