Search in sources :

Example 21 with QueryTransformerAstBased

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);
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) Test(org.junit.Test)

Example 22 with QueryTransformerAstBased

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);
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) Test(org.junit.Test)

Example 23 with QueryTransformerAstBased

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);
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) Test(org.junit.Test)

Example 24 with QueryTransformerAstBased

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);
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) Test(org.junit.Test)

Example 25 with QueryTransformerAstBased

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);
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) Test(org.junit.Test)

Aggregations

QueryTransformerAstBased (com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased)39 DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)37 Test (org.junit.Test)37 EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)9 JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)9 JpqlSyntaxException (com.haulmont.cuba.core.sys.jpql.JpqlSyntaxException)2