use of com.haulmont.cuba.core.sys.jpql.transform.PathEntityReference in project cuba by cuba-platform.
the class QueryAnalyzerTest method replaceOrderBy.
@Test
public void replaceOrderBy() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTreeTransformer qa = new QueryTreeTransformer();
qa.prepare(model, "select c from Car c order by c.model");
CommonTree tree = qa.getTree();
CommonTree orderByNode = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_ORDER_BY);
Tree orderByField = orderByNode.getFirstChildWithType(JPA2Lexer.T_ORDER_BY_FIELD);
assertEquals(1, orderByField.getChildCount());
PathNode pathNode = (PathNode) orderByField.getChild(0);
assertEquals("c", pathNode.getEntityVariableName());
assertEquals("model", pathNode.getChild(0).getText());
pathNode = new PathNode(JPA2Lexer.T_SELECTED_FIELD, "c");
pathNode.addDefaultChild("regNumber");
qa.replaceOrderBy(true, new PathEntityReference(pathNode, "Car"));
orderByNode = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_ORDER_BY);
orderByField = orderByNode.getFirstChildWithType(JPA2Lexer.T_ORDER_BY_FIELD);
assertEquals(2, orderByField.getChildCount());
pathNode = (PathNode) orderByField.getChild(0);
assertEquals("c", pathNode.getEntityVariableName());
assertEquals("regNumber", pathNode.getChild(0).getText());
assertEquals("desc", orderByField.getChild(1).getText());
}
Aggregations