use of org.datanucleus.query.expression.PrimaryExpressionIsClassStaticFieldException in project datanucleus-core by datanucleus.
the class JavaQueryCompiler method compileResult.
public Expression[] compileResult() {
if (result == null) {
return null;
}
Node[] node = parser.parseResult(result);
Expression[] expr = new Expression[node.length];
for (int i = 0; i < node.length; i++) {
ExpressionCompiler comp = new ExpressionCompiler();
comp.setSymbolTable(symtbl);
comp.setMethodAliases(queryMgr.getQueryMethodAliasesByPrefix());
// Find the last child of this node, and check for an alias (type = NAME)
String alias = null;
Node aliasNode = null;
List<Node> childNodes = node[i].getChildNodes();
if (childNodes != null && childNodes.size() > 0) {
Node lastChild = childNodes.get(childNodes.size() - 1);
if (lastChild.getNodeType() == NodeType.NAME) {
// Alias node
aliasNode = lastChild;
}
}
if (aliasNode != null) {
alias = (String) aliasNode.getNodeValue();
node[i].removeChildNode(aliasNode);
}
if (candidateAliasOrig != null) {
swapCandidateAliasNodeName(node[i]);
}
if (parameterSubtitutionMap != null) {
node[i] = swapSubqueryParameters(node[i]);
}
expr[i] = comp.compileExpression(node[i]);
if (alias != null) {
expr[i].setAlias(alias);
}
try {
expr[i].bind(symtbl);
} catch (PrimaryExpressionIsClassLiteralException peil) {
// PrimaryExpression should be swapped for a class Literal
expr[i] = peil.getLiteral();
expr[i].bind(symtbl);
} catch (PrimaryExpressionIsClassStaticFieldException peil) {
// PrimaryExpression should be swapped for a static field Literal
Field fld = peil.getLiteralField();
try {
// Get the value of the static field
Object value = fld.get(null);
expr[i] = new Literal(value);
expr[i].bind(symtbl);
} catch (Exception e) {
throw new NucleusUserException("Error processing static field " + fld.getName(), e);
}
} catch (PrimaryExpressionIsVariableException pive) {
// PrimaryExpression should be swapped for an implicit variable
expr[i] = pive.getVariableExpression();
expr[i].bind(symtbl);
}
if (expr[i] instanceof PrimaryExpression) {
String id = ((PrimaryExpression) expr[i]).getId();
if (isKeyword(id)) {
throw new NucleusUserException(Localiser.msg("021052", getLanguage(), id));
}
} else if (expr[i] instanceof ParameterExpression) {
String id = ((ParameterExpression) expr[i]).getId();
if (isKeyword(id)) {
throw new NucleusUserException(Localiser.msg("021052", getLanguage(), id));
}
} else if (expr[i] instanceof VariableExpression) {
String id = ((VariableExpression) expr[i]).getId();
if (isKeyword(id)) {
throw new NucleusUserException(Localiser.msg("021052", getLanguage(), id));
}
}
}
return expr;
}
Aggregations