Search in sources :

Example 1 with QueryTransformerAstBased

use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.

the class QueryTransformationTest method testAst.

@Test
public void testAst() throws Exception {
    for (int i = 0; i < 1000; i++) {
        QueryTransformerAstBased transformerAstBased = new QueryTransformerAstBased(prepareDomainModel(), "select g from sec$GroupHierarchy g");
        transformerAstBased.addWhere("g.deleteTs is null");
    }
}
Also used : QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) Test(org.junit.Test)

Example 2 with QueryTransformerAstBased

use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.

the class QueryTransformerAstBasedTest method testAddWhereWithSubquery.

@Test
public void testAddWhereWithSubquery() throws Exception {
    DomainModel model = prepareDomainModel();
    QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select u from sec$User u");
    transformer.addWhere("{E}.login not like '[hide]'");
    transformer.addWhere("{E}.group.id in (select h.group.id from sec$GroupHierarchy h " + "where h.group.id = :session$userGroupId or h.parent.id = :session$userGroupId)");
    String res = transformer.getResult();
    assertEquals("select u from sec$User u " + "where (u.login not like '[hide]') " + "and (u.group.id in (" + "select h.group.id from sec$GroupHierarchy h " + "where h.group.id = :session$userGroupId or h.parent.id = :session$userGroupId))", 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 3 with QueryTransformerAstBased

use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.

the class QueryTransformerAstBasedTest method test.

@Test
public void test() 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.addWhere("{E}.createdBy = :par1");
    String res = transformer.getResult();
    assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where (h.userGroup = :par) and (h.createdBy = :par1)", res);
    transformer = new QueryTransformerAstBased(model, "select c from sec$GroupHierarchy h join h.parent.constraints c where h.userGroup = ?1 " + "group by c.level having c.level > 0 order by c.level");
    transformer.addWhere("{E}.createdBy = :par1");
    res = transformer.getResult();
    assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where (h.userGroup = ?1) " + "and (h.createdBy = :par1) group by c.level having c.level > 0 order by c.level", res);
    Set<String> set = transformer.getAddedParams();
    assertEquals(1, set.size());
    assertEquals("par1", set.iterator().next());
    transformer.addWhere("({E}.updatedBy = :par2 and {E}.groupId = :par3)");
    res = transformer.getResult();
    assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where ((h.userGroup = ?1) " + "and (h.createdBy = :par1)) and ((h.updatedBy = :par2 and h.groupId = :par3)) group by c.level having c.level > 0 order by c.level", res);
    set = transformer.getAddedParams();
    assertEquals(3, set.size());
    transformer.reset();
    transformer.mergeWhere("select gh from sec$GroupHierarchy gh where gh.version between 1 and 2");
    res = transformer.getResult();
    assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where (h.userGroup = ?1) " + "and (h.version between 1 and 2) group by c.level having c.level > 0 order by c.level", 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 4 with QueryTransformerAstBased

use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.

the class QueryTransformerAstBasedTest method testAliasPlaceholder.

@Test
public void testAliasPlaceholder() throws RecognitionException {
    DomainModel model = prepareDomainModel();
    QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select c from sec$GroupHierarchy h join h.parent.constraints c where h.group = :par");
    transformer.addWhere("{E}.createdBy = :par1 and {E}.updatedBy = :par2");
    String res = transformer.getResult();
    assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where (h.group = :par) and (h.createdBy = :par1" + " and h.updatedBy = :par2)", res);
    // //////////////////////////////////
    transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h where h.group = :par");
    transformer.addJoinAndWhere("join h.parent.constraints c", "{E}.createdBy = :par1 and {E}.updatedBy = :par2 and c.createTs = :par3");
    res = transformer.getResult();
    assertEquals("select h from sec$GroupHierarchy h join h.parent.constraints c where (h.group = :par) and (h.createdBy = :par1" + " and h.updatedBy = :par2 and c.createTs = :par3)", res);
    // //////////////////////////////////
    transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h where h.group = :par");
    transformer.addJoinAndWhere("join {E}.parent.constraints c", "{E}.createdBy = :par1 and {E}.updatedBy = :par2 and c.createTs = :par3");
    res = transformer.getResult();
    assertEquals("select h from sec$GroupHierarchy h join h.parent.constraints c where (h.group = :par) and (h.createdBy = :par1" + " and h.updatedBy = :par2 and c.createTs = :par3)", 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 5 with QueryTransformerAstBased

use of com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased in project cuba by cuba-platform.

the class QueryTransformerAstBasedTest method testDoubleJoins.

@Test
public void testDoubleJoins() throws Exception {
    DomainModel model = prepareDomainModel();
    QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h where h.group = :par");
    transformer.reset();
    transformer.addJoinAndWhere("join h.parent.constraints c1 join h.constraints c2", "c.createdBy = :par2");
    String res = transformer.getResult();
    assertEquals("select h from sec$GroupHierarchy h join h.parent.constraints c1 join h.constraints c2 where (h.group = :par) and (c.createdBy = :par2)", res);
    transformer.reset();
    transformer.addJoinAndWhere("join {E}.parent p join p.constraints cr", "c.createdBy = :par2");
    res = transformer.getResult();
    assertEquals("select h from sec$GroupHierarchy h join h.parent p join p.constraints cr where (h.group = :par) and (c.createdBy = :par2)", res);
    transformer.reset();
    transformer.addJoinAndWhere("join replaceEntity.parent p join p.constraints cr", "c.createdBy = :par2");
    res = transformer.getResult();
    assertEquals("select h from sec$GroupHierarchy h join h.parent p join p.constraints cr 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