Search in sources :

Example 76 with DomainModel

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

Example 77 with DomainModel

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

Example 78 with DomainModel

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

the class QueryTransformerAstBasedTest method getResult_noChangesMade_withDistinct.

@Test
public void getResult_noChangesMade_withDistinct() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel personEntity = builder.produceImmediately("Person", "personName");
    builder.startNewEntity("Team");
    builder.addStringAttribute("name");
    builder.addStringAttribute("owner");
    builder.addReferenceAttribute("manager", "Person");
    JpqlEntityModel teamEntity = builder.produce();
    builder.startNewEntity("Player");
    builder.addStringAttribute("name");
    builder.addStringAttribute("nickname");
    builder.addReferenceAttribute("team", "Team");
    builder.addReferenceAttribute("agent", "Person");
    JpqlEntityModel playerEntity = builder.produce();
    builder.startNewEntity("League");
    builder.addStringAttribute("name");
    builder.addCollectionReferenceAttribute("teams", "Team");
    JpqlEntityModel leagueEntity = builder.produce();
    builder.startNewEntity("Country");
    builder.addStringAttribute("flag");
    builder.addReferenceAttribute("league", "League");
    JpqlEntityModel countryEntity = builder.produce();
    DomainModel model = new DomainModel(teamEntity, playerEntity, leagueEntity, personEntity, countryEntity);
    assertTransformsToSame(model, "select distinct m from Player p left join p.team.manager m");
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) Test(org.junit.Test)

Example 79 with DomainModel

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

Example 80 with DomainModel

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

Aggregations

DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)94 Test (org.junit.Test)86 EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)49 JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)45 QueryTransformerAstBased (com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased)37 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)21 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)20 QueryTreeTransformer (com.haulmont.cuba.core.sys.jpql.transform.QueryTreeTransformer)8 CommonTree (org.antlr.runtime.tree.CommonTree)7 VariableEntityReference (com.haulmont.cuba.core.sys.jpql.transform.VariableEntityReference)5 JpqlEntityModelImpl (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl)4 JpqlSyntaxException (com.haulmont.cuba.core.sys.jpql.JpqlSyntaxException)3 Tree (org.antlr.runtime.tree.Tree)3 DomainModelBuilder (com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 TreeToQuery (com.haulmont.cuba.core.sys.jpql.TreeToQuery)1 PathEntityReference (com.haulmont.cuba.core.sys.jpql.transform.PathEntityReference)1 HintRequest (com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest)1 Option (com.haulmont.cuba.gui.components.autocomplete.impl.Option)1 ArrayList (java.util.ArrayList)1