Search in sources :

Example 56 with DomainModel

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

Example 57 with DomainModel

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

Example 58 with DomainModel

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");
}
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 59 with DomainModel

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

Example 60 with DomainModel

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");
}
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)

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