use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method testAddDistinct.
@Test
public void testAddDistinct() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h");
transformer.addDistinct();
String res = transformer.getResult();
assertEquals("select distinct h from sec$GroupHierarchy h", res);
}
use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method addJoinOn.
@Test
public void addJoinOn() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select h from sec$Constraint u, sec$GroupHierarchy h where h.userGroup = :par");
transformer.addJoinAsIs("join sec$Constraint c on c.group.id = h.parent.id");
String res = transformer.getResult();
assertEquals("select h from sec$Constraint u, sec$GroupHierarchy h join sec$Constraint c on c.group.id = h.parent.id where h.userGroup = :par", res);
}
use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method testReplaceName.
@Test
public void testReplaceName() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h");
transformer.replaceEntityName("sec$ExtGroupHierarchy");
String res = transformer.getResult();
assertEquals("select h from sec$ExtGroupHierarchy h", res);
}
use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method testOrderBy.
@Test
public void testOrderBy() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h order by h.level desc");
transformer.replaceOrderBy(false, "group");
String res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h order by h.group", res);
transformer = new QueryTransformerAstBased(model, "select c from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by h.level having h.level > 0 order by h.level desc");
transformer.replaceOrderBy(false, "group");
res = transformer.getResult();
assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by h.level having h.level > 0 order by c.group", res);
transformer.replaceOrderBy(true, "group");
res = transformer.getResult();
assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by h.level having h.level > 0 order by c.group desc", res);
transformer = new QueryTransformerAstBased(model, "select c from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by h.level having h.level > 0 order by h.level desc, h.createdBy");
transformer.replaceOrderBy(false, "group");
res = transformer.getResult();
assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by h.level having h.level > 0 order by c.group", res);
transformer = new QueryTransformerAstBased(model, "select c from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by h.level having h.level > 0 order by h.level desc, h.createdBy");
transformer.replaceOrderBy(true, "group", "createdBy");
res = transformer.getResult();
assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by h.level having h.level > 0 order by c.group desc, c.createdBy desc", res);
transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h where h.group = ?1 order by h.level desc, h.createdBy");
transformer.replaceOrderBy(true, "token.name", "token.code");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h where h.group = ?1 " + "order by h.token.name desc, h.token.code desc", res);
transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h where h.group = ?1 order by h.level desc, h.createdBy");
transformer.replaceOrderBy(true, "token.manager.login");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h left join h.token.manager h_token_manager " + "where h.group = ?1 order by h_token_manager.login desc", res);
transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h where h.group = ?1 order by h.level desc, h.createdBy");
transformer.replaceOrderBy(true, "token.parentToken.name");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h where h.group = ?1 order by h.token.parentToken.name desc", res);
transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h order by h.level desc");
transformer.replaceOrderBy(false, "parent.other.createdBy");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h left join h.parent h_parent left join h_parent.other h_parent_other order by h_parent_other.createdBy", res);
transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h order by h.level desc");
transformer.replaceOrderBy(false, "parent.other.token.name");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h left join h.parent h_parent left join h_parent.other h_parent_other order by h_parent_other.token.name", res);
transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h order by h.level desc nulls first");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h order by h.level desc nulls first", res);
transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h order by h.level desc nulls last");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h order by h.level desc nulls last", res);
}
Aggregations