* @param fromStr The from expression string
* @return Class Expression for this part of the FROM
*/
protected ClassExpression compileFromExpression(String fromStr)
{
ClassExpression expr = null;
p = new JPQLParser(fromStr, imports);
if (p.parseStringIgnoreCase("IN"))
{
// "IN(...) [AS] alias"
if (!p.parseChar('('))
{
throw new QueryCompilerSyntaxException("Expected: '(' but got " + p.remaining(),
p.getIndex(), p.getInput());
}
// Find what we are joining to
String name = p.parseIdentifier();
if (p.nextIsDot())
{
p.parseChar('.');
name += ".";
name += p.parseName();
}
if (!p.parseChar(')'))
{
throw new QueryCompilerSyntaxException("Expected: ')' but got " + p.remaining(),
p.getIndex(), p.getInput());
}
p.parseStringIgnoreCase("AS"); // Optional
String alias = p.parseName();
// Return as part of ClassExpression joining candidate class to this collection field
expr = new ClassExpression(qs, candidateClass);
expr.as(candidateAlias);
JoinExpression joinExpr = new JoinExpression(qs, name, false, false);
joinExpr.as(alias);
expr.join(joinExpr);
// Update with any subsequent JOIN expressions
compileFromJoinExpressions(expr);
}
else
{
// "<candidate_expression> [AS] alias"
String id = p.parseIdentifier();
String name = id;
if (p.nextIsDot())
{
p.parseChar('.');
name += ".";
name += p.parseName();
}
if (parentExpr != null)
{
// Subquery, so calculate any candidate expression
Class cls = null;
cls = getClassForSubqueryCandidateExpression(name);
expr = new ClassExpression(qs, cls);
id = p.parseIdentifier();
if (id != null)
{
// Add alias to class/class.field
if (id.equalsIgnoreCase("AS"))
{
id = p.parseIdentifier();
}
if (id != null)
{
expr.as(id);
}
}
}
else
{
Class cls = query.resolveClassDeclaration(name);
expr = new ClassExpression(qs, cls);
id = p.parseIdentifier();
if (id != null)
{
// Add alias to class/class.field
if (id.equalsIgnoreCase("AS"))
{
id = p.parseIdentifier();
}
if (id != null)
{
expr.as(id);
}
}
}
// Update with any subsequent JOIN expressions