Search in sources :

Example 71 with DomainModel

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

the class QueryTransformerAstBasedTest method testJoin_WithComma.

@Test
public void testJoin_WithComma() 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 pco, sec$Constraint sc", "1 = 1");
    String res = transformer.getResult();
    assertEquals("select h from sec$GroupHierarchy h join h.parent.constraints pco, sec$Constraint sc where (h.group = :par) and (1 = 1)", res);
    transformer.reset();
    transformer.addJoinAsIs("join h.parent.constraints pco, sec$Constraint sc");
    res = transformer.getResult();
    assertEquals("select h from sec$GroupHierarchy h join h.parent.constraints pco, sec$Constraint sc where h.group = :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 72 with DomainModel

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

the class QueryTransformerAstBasedTest method testAddWhereWithInExpression.

@Test
public void testAddWhereWithInExpression() throws RecognitionException {
    DomainModel model = prepareDomainModel();
    QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select c from sec$Constraint c");
    transformer.addWhere("{E}.group in (select g.id from sec$GroupHierarchy g where {E} in (g.constraints))");
    assertEquals("select c from sec$Constraint c " + "where c.group in (select g.id from sec$GroupHierarchy g where c in ( g.constraints))", transformer.getResult());
    transformer = new QueryTransformerAstBased(model, "select c from sec$Constraint c");
    transformer.addWhere("{E}.group in (select g.id from sec$GroupHierarchy g where {E}.id in (g.constraints.id))");
    assertEquals("select c from sec$Constraint c " + "where c.group in (select g.id from sec$GroupHierarchy g where c.id in ( g.constraints.id))", transformer.getResult());
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) Test(org.junit.Test)

Example 73 with DomainModel

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

the class QueryTransformerAstBasedTest method testNotCorrectEntityAliasInWhere.

@Test
public void testNotCorrectEntityAliasInWhere() {
    DomainModel model = prepareDomainModel();
    QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select c from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by c.level having c.level > 0 order by c.level");
    // since 3.4 we don't check equality of targetEntity and an entity in the query
    transformer.addWhere("a.createdBy = :par1");
    assertEquals("select c from sec$GroupHierarchy h join h.parent.constraints c where (h.group = ?1) and (a.createdBy = :par1) " + "group by c.level having c.level > 0 order by c.level", transformer.getResult());
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) Test(org.junit.Test)

Example 74 with DomainModel

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

the class QueryTransformerAstBasedTest method addWhere_with_child_select.

@Test
public void addWhere_with_child_select() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    builder.startNewEntity("Car");
    builder.addStringAttribute("model");
    builder.addReferenceAttribute("driver", "Person");
    JpqlEntityModel car = builder.produce();
    JpqlEntityModel person = builder.produceImmediately("Person", "fullname");
    DomainModel model = new DomainModel(car, person);
    QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select car.driver from Car car");
    transformer.addWhere("{E}.model = ?1");
    assertEquals("select car.driver from Car car where car.model = ?1", transformer.getResult());
    transformer = new QueryTransformerAstBased(model, "select car.driver from Car car");
    transformer.addWhere("{E}.driver.fullname = ?1");
    assertEquals("select car.driver from Car car where car.driver.fullname = ?1", transformer.getResult());
}
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 75 with DomainModel

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

the class QueryTransformerAstBasedTest method getResult_noChangesMade_delete.

@Test
public void getResult_noChangesMade_delete() throws Exception {
    DomainModel model = prepareDomainModel();
    QueryTransformerAstBased transformerAstBased = new QueryTransformerAstBased(model, "delete from sec$GroupHierarchy g where g.createdBy = :createdBy");
    assertEquals(transformerAstBased.getResult(), "delete from sec$GroupHierarchy g where g.createdBy = :createdBy");
}
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