use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method addWhereAsId.
@Test
public void addWhereAsId() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select c from sec$GroupHierarchy h join h.parent.constraints c where h.userGroup = :par");
transformer.addWhereAsIs("a.createdBy = :par1");
String res = transformer.getResult();
assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where (h.userGroup = :par) " + "and (a.createdBy = :par1)", res);
}
use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method testOrderByAssociatedProperty.
@Test
public void testOrderByAssociatedProperty() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h");
transformer.replaceOrderBy(false, "parent.group");
String res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h left join h.parent h_parent order by h_parent.group", res);
transformer.reset();
transformer.replaceOrderBy(true, "parent.other.group");
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.group desc", res);
transformer.reset();
transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h");
transformer.replaceOrderBy(false, "parent.group", "parent.createdBy");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h left join h.parent h_parent order by h_parent.group, h_parent.createdBy", res);
}
use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_join_fetch.
@Test
public void getResult_noChangesMade_join_fetch() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h join fetch h.parent.constraints where h.userGroup = :par");
String res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h join fetch h.parent.constraints 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 getResult_noChangesMade_parametersWithDot.
@Test
public void getResult_noChangesMade_parametersWithDot() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name");
builder.startNewEntity("Player");
builder.addSingleValueAttribute(Date.class, "birthDate");
builder.addReferenceAttribute("team", "Team");
JpqlEntityModel playerEntity = builder.produce();
DomainModel model = new DomainModel(playerEntity, teamEntity);
QueryTransformerAstBased transformerAstBased = new QueryTransformerAstBased(model, "SELECT p FROM Player p where p.birthDate = :d.option");
String result = transformerAstBased.getResult();
assertEquals("SELECT p FROM Player p where p.birthDate = :d.option", result);
}
use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method testJoin.
@Test
public void testJoin() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h where h.group = :par");
transformer.addJoinAndWhere("join h.parent.constraints c", "c.createdBy = :par2");
String res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h join h.parent.constraints c where (h.group = :par) and (c.createdBy = :par2)", res);
transformer.reset();
transformer.addJoinAndWhere("left join h.parent.constraints c", "c.createdBy = :par2");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h left join h.parent.constraints c where (h.group = :par) and (c.createdBy = :par2)", res);
transformer.reset();
transformer.addJoinAndWhere(",sec$Constraint c", "c.createdBy = :par2");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h, sec$Constraint c where (h.group = :par) and (c.createdBy = :par2)", res);
}
Aggregations