Search in sources :

Example 36 with EntityBuilder

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

the class QueryTransformerAstBasedTest method getResult_noChangesMade_withLeft_InnerJoinFetch.

@Test
public void getResult_noChangesMade_withLeft_InnerJoinFetch() 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();
    DomainModel model = new DomainModel(teamEntity, playerEntity, personEntity);
    QueryTransformerAstBased transformerAstBased = new QueryTransformerAstBased(model, "select p.name from Player p join fetch p.team left join fetch p.agent");
    assertEquals("select p.name from Player p join fetch p.team left join fetch p.agent", transformerAstBased.getResult());
    transformerAstBased = new QueryTransformerAstBased(model, "select p.name from Player p left outer join fetch p.team inner join fetch p.agent");
    assertEquals("select p.name from Player p left outer join fetch p.team inner join fetch p.agent", transformerAstBased.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 37 with EntityBuilder

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

the class QueryTransformerAstBasedTest method getResult_noChangesMade_withWhere.

@Test
public void getResult_noChangesMade_withWhere() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name");
    builder.startNewEntity("Player");
    builder.addReferenceAttribute("team", "Team");
    builder.addStringAttribute("name");
    JpqlEntityModel playerEntity = builder.produce();
    DomainModel model = new DomainModel(playerEntity, teamEntity);
    assertTransformsToSame(model, "SELECT p FROM Player p where p.name = 'de Souza'");
    QueryTransformerAstBased transformerAstBased = new QueryTransformerAstBased(model, "SELECT p FROM Player p left join p.team as t WHERE t.name = 'KS FC'");
    String result = transformerAstBased.getResult();
    assertEquals("SELECT p FROM Player p left join p.team t WHERE t.name = 'KS FC'", 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 38 with EntityBuilder

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

the class QueryTransformerAstBasedTest method getResult_noChangesMade_orderBySeveralFields.

@Test
public void getResult_noChangesMade_orderBySeveralFields() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name");
    builder.startNewEntity("Player");
    builder.addSingleValueAttribute(Date.class, "birthDate");
    builder.addStringAttribute("surname");
    builder.addReferenceAttribute("team", "Team");
    JpqlEntityModel playerEntity = builder.produce();
    DomainModel model = new DomainModel(playerEntity, teamEntity);
    QueryTransformerAstBased transformerAstBased = new QueryTransformerAstBased(model, "SELECT p FROM Player p order by p.birthDate, p.surname");
    String result = transformerAstBased.getResult();
    assertEquals("SELECT p FROM Player p order by p.birthDate, p.surname", 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 39 with EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder 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 40 with EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder 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)

Aggregations

EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)50 DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)49 JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)46 Test (org.junit.Test)44 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)20 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)19 QueryTransformerAstBased (com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased)9 JpqlEntityModelImpl (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl)4 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 QueryTreeTransformer (com.haulmont.cuba.core.sys.jpql.transform.QueryTreeTransformer)1 VariableEntityReference (com.haulmont.cuba.core.sys.jpql.transform.VariableEntityReference)1 CommonTree (org.antlr.runtime.tree.CommonTree)1