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