use of com.haulmont.cuba.core.sys.jpql.DomainModel 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.DomainModel 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.DomainModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_withJoinAndAsAndMemberField.
@Test
public void getResult_noChangesMade_withJoinAndAsAndMemberField() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name");
builder.startNewEntity("Player");
builder.addReferenceAttribute("as", "Team");
builder.addReferenceAttribute("member", "Team");
JpqlEntityModel playerEntity = builder.produce();
DomainModel model = new DomainModel(playerEntity, teamEntity);
assertTransformsToSame(model, "SELECT p FROM Player p JOIN p.as t");
assertTransformsToSame(model, "SELECT p FROM Player p JOIN p.member t");
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel 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.DomainModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_withJoinAndSeveralJoinConditions.
@Test
public void getResult_noChangesMade_withJoinAndSeveralJoinConditions() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name");
builder.startNewEntity("Player");
builder.addStringAttribute("name");
builder.addReferenceAttribute("as", "Team");
builder.addReferenceAttribute("member", "Team");
JpqlEntityModel playerEntity = builder.produce();
DomainModel model = new DomainModel(playerEntity, teamEntity);
assertTransformsToSame(model, "SELECT p FROM Player p JOIN Team t on p.member = t and p.name = :param");
}
Aggregations