views:

71

answers:

0

I have a HQL query:

query = select item.itemNumber from items item where item.stock>0 and item.price<100.00

i like to parse this query and convert it into a tree structure:

AST queryTree = parse(query);

than i like to iterate through the nodes, change some values, and convert the tree back to a string represenation:

Iterator<ASTNode> it = queryTree.nodeIterator();
while(it.hasNext())
{
  ASTNode node = it.next();
  System.out.println( node.text() + "->" + node.value() );
}
query = queryTree.toString();

it would be nice if the parse method would throw Exceptions in case the HQL grammer is violated, but its not necessary. Has anyone an idea how this can be accomplished? Are there any API methods offered by hibernate to accomplish that task?

Thanks,