Hi all,
I have modify checkOrderClause in ParseTreeWalker.java to allow the use of
sql function in order by clause ( for e.g, select a from mypackage.myclass a
order by Upper(a.name) ). My changes are mark by the tag //{{lowhs and
//lowhs}}. May be someone can review this and see whether it is appropriate
to be incorporated into cvs.
Regards,
Low Heng Sin ( [EMAIL PROTECTED] )
/**
* Traverses the order by clause sub-tree and checks for errors.
*
* @throws QueryException if an error is detected.
*/
private void checkOrderClause(ParseTreeNode orderClause)
throws QueryException {
if ( orderClause.getToken().getTokenType() != KEYWORD_ORDER )
throw new QueryException( "checkOrderClause was called on a subtree which is not
an order clause.");
//{{lowhs
ParseTreeNode prevChild = null;
//lowhs}}
for (Enumeration e = orderClause.children(); e.hasMoreElements(); ) {
ParseTreeNode curChild = (ParseTreeNode) e.nextElement();
int tokenType = curChild.getToken().getTokenType();
switch (tokenType) {
case KEYWORD_ASC:
case KEYWORD_DESC:
// iterate on child
curChild = curChild.getChild(0);
tokenType = curChild.getToken().getTokenType();
}
switch (tokenType) {
case DOT:
checkProjection( curChild, false, false );
break;
case IDENTIFIER:
//{{lowhs
if ( curChild.children().hasMoreElements() ) {
if ( curChild.getChild(0).getToken().getTokenType() == LPAREN ) {
// A function, skip to next element
Enumeration arguments = curChild.getChild(0).children();
while(arguments.hasMoreElements()) {
ParseTreeNode nn = (ParseTreeNode)arguments.nextElement();
checkWhereClause(nn);
}
}
} else {
checkField(curChild);
}
//lowhs}}
break;
//{{lowhs
case LPAREN:
if ( ( prevChild == null ) || ( prevChild.getToken().getTokenType() !=
IDENTIFIER ) )
throw new QueryException("Illegal use of left parenthesis in ORDER BY
clause.");
break;
//lowhs}}
default:
throw new QueryException( "Only identifiers, path expressions, and the
keywords ASC and DESC are allowed in the ORDER BY clause." );
}
//{{lowhs
prevChild = curChild;
//lowhs}}
}
}