// Identifier is not allowed to be a JPQL keyword
throw new QueryCompilerSyntaxException(LOCALISER.msg("021052", language, id),
p.getIndex(), p.getInput());
}
MappedStoreManager srm = (MappedStoreManager)query.getObjectManager().getStoreManager();
ClassLoaderResolver clr = query.getObjectManager().getClassLoaderResolver();
ScalarExpression expr;
if (id.equalsIgnoreCase("CURRENT_DATE"))
{
return new TemporalExpression(qs).currentDateMethod();
}
else if (id.equalsIgnoreCase("CURRENT_TIME"))
{
return new TemporalExpression(qs).currentTimeMethod();
}
else if (id.equalsIgnoreCase("CURRENT_TIMESTAMP"))
{
return new TemporalExpression(qs).currentTimestampMethod();
}
else if (id.equalsIgnoreCase("true"))
{
JavaTypeMapping m = srm.getDatastoreAdapter().getMapping(Boolean.class, srm, clr);
return m.newLiteral(qs, Boolean.TRUE);
}
else if (id.equalsIgnoreCase("false"))
{
JavaTypeMapping m = srm.getDatastoreAdapter().getMapping(Boolean.class, srm, clr);
return m.newLiteral(qs, Boolean.FALSE);
}
else if (id.startsWith(":"))
{
// Named parameters (":param1")
return compileNamedImplicitParameter(id);
}
else if (id.startsWith("?"))
{
// Numbered parameters ("?1")
return compileNumberedImplicitParameter(id);
}
else if (id.equalsIgnoreCase("NEW"))
{
// Found syntax for "new MyObject(param1, param2)" - result expression (JPA1 $4.8.2]
return compileNewObject();
}
else if (query.hasSubqueryForVariable(id))
{
// Variable represented as a subquery (process before explicit variables below)
return compileSubqueryVariable(id);
}
else if (variableNames.contains(id))
{
// Identifier is an explicit variable
return compileExplicitVariable(id);
}
else
{
try
{
// Check if the identifier is a field of the candidate class
expr = qs.getMainTableExpression().newFieldExpression(id);
// What is this doing ? If "id" is a field then it comes to this, so how can it be an alias too ?
if (!id.equalsIgnoreCase(candidateAlias)) // JPQL identifiers are case insensitive
{
// Make a check on whether the field exists in the candidate class (TableExpression only checks the same table).
if (candidateCmd == null)
{
candidateCmd = query.getObjectManager().getMetaDataManager().getMetaDataForClass(
candidateClass, clr);
}
if (candidateCmd.getMetaDataForMember(id) == null)
{
// The field doesnt exist in the candidate class, so no point proceeding
throw new JPOXUserException(LOCALISER.msg("021049", id));
}
}
fieldExpressions.add(expr); // Add to the field expressions list
}
catch (NoSuchPersistentFieldException nspfe)
{
// Not a field of the candidate class, so check if an alias (case insensitive)
AliasJoinInformation aliasInfo = (AliasJoinInformation)aliases.get(id.toUpperCase());
if (aliasInfo == null && parentCompiler != null)
{
// This is a subquery, so try the parent query
aliasInfo = (AliasJoinInformation)parentCompiler.aliases.get(id.toUpperCase());
}
if (aliasInfo != null)
{
DatastoreClass table = srm.getDatastoreClass(aliasInfo.cls.getName(), clr);
if (aliasInfo.tableExpression == null)
{
if (aliasInfo.alias.equalsIgnoreCase(candidateAlias))
{
aliasInfo.tableExpression = qs.getMainTableExpression();
}
else
{
DatastoreIdentifier tableId =
srm.getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, aliasInfo.alias);
aliasInfo.tableExpression = qs.newTableExpression(table, tableId);
}
}
return table.getIDMapping().newScalarExpression(qs, aliasInfo.tableExpression);
}