use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_withMultiEntitySelect.
@Test
public void getResult_noChangesMade_withMultiEntitySelect() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel teamEntity = builder.produceImmediately("Team");
JpqlEntityModel playerEntity = builder.produceImmediately("Player");
DomainModel model = new DomainModel(playerEntity, teamEntity);
assertTransformsToSame(model, "SELECT p, t FROM Player p, Team t");
}
use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_subqueries.
// The following functions are not supported by JPA2 JPQL (see jpql21.bnf)
// @Test
// public void getResult_noChangesMade_withSubqueries() throws RecognitionException {
// EntityBuilder builder = new EntityBuilder();
// JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name", "owner");
//
// builder.startNewEntity("Player");
// builder.addStringAttribute("name");
// builder.addStringAttribute("nickname");
// builder.addReferenceAttribute("team", "Team");
// JpqlEntityModel playerEntity = builder.produce();
//
// DomainModel model = new DomainModel(playerEntity, teamEntity);
//
// assertTransformsToSame(model, "select p.name from (select t.name from Team t) p");
// assertTransformsToSame(model, "select p.owner from (select t.name, t.owner from Team t) p");
// assertTransformsToSame(model, "select g.owner from (select t.name, t.owner from Team t) p, (select t.name from Team t) g");
// }
// The following functions are not supported by JPA2 JPQL (see jpql21.bnf)
// @Test
// public void getResult_noChangesMade_severalLevelsOfSubquery() throws RecognitionException {
// EntityBuilder builder = new EntityBuilder();
// JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name", "owner");
//
// builder.startNewEntity("Player");
// builder.addStringAttribute("name");
// builder.addStringAttribute("nickname");
// builder.addReferenceAttribute("team", "Team");
// JpqlEntityModel playerEntity = builder.produce();
//
// DomainModel model = new DomainModel(playerEntity, teamEntity);
//
// assertTransformsToSame(model, "select p.owner from (select t from Team t where t.name in (select a.name from Player a)) p");
// // 'as' skipped
// QueryTransformerAstBased transformerAstBased = new QueryTransformerAstBased(model, "select p.owner from (select t.owner from Team as t where t.name = '1') p", "AsdfAsdfAsdf");
// String result = transformerAstBased.getResult();
// assertEquals("select p.owner from (select t.owner from Team t where t.name = '1') p", result);
// }
@Test
public void getResult_noChangesMade_subqueries() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name", "owner");
builder.startNewEntity("Player");
builder.addStringAttribute("name");
builder.addStringAttribute("nickname");
builder.addReferenceAttribute("team", "Team");
JpqlEntityModel playerEntity = builder.produce();
DomainModel model = new DomainModel(playerEntity, teamEntity);
assertTransformsToSame(model, "select p.owner from Player pl where exists (select t from Team t where t.name = 'Team1' and pl.team.id = t.id)");
assertTransformsToSame(model, "select p.owner from Player pl where pl.team.id in (select t.id from Team t where t.name = 'Team1')");
assertTransformsToSame(model, "select t.name from Team t where (select count(p) from Player p where p.team.id = t.id) > 10");
}
use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_withAggregateExpression.
@Test
public void getResult_noChangesMade_withAggregateExpression() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name");
builder.startNewEntity("Player");
builder.addSingleValueAttribute(Integer.class, "age");
builder.addReferenceAttribute("team", "Team");
JpqlEntityModel playerEntity = builder.produce();
DomainModel model = new DomainModel(playerEntity, teamEntity);
assertTransformsToSame(model, "SELECT count(p) FROM Player p");
assertTransformsToSame(model, "SELECT max(p.age) FROM Player p");
assertTransformsToSame(model, "SELECT min(p.age) FROM Player p");
assertTransformsToSame(model, "SELECT avg(p.age) FROM Player p");
assertTransformsToSame(model, "SELECT avg(p.age)*4.1 FROM Player p");
assertTransformsToSame(model, "SELECT sum(p.age) FROM Player p");
assertTransformsToSame(model, "SELECT max(p.age), t FROM Player p join p.team t group by t");
assertTransformsToSame(model, "SELECT max(p.age), t.name FROM Player p join p.team t group by t.name");
}
use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_withJoin.
@Test
public void getResult_noChangesMade_withJoin() 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);
QueryTransformerAstBased transformerAstBased = new QueryTransformerAstBased(model, "select m.personName from Player p left join p.team.manager as m");
String result = transformerAstBased.getResult();
assertEquals("select m.personName from Player p left join p.team.manager m", result);
transformerAstBased = new QueryTransformerAstBased(model, "select c.flag from Country c join c.league.teams as t join t.manager m");
assertEquals("select c.flag from Country c join c.league.teams t join t.manager m", transformerAstBased.getResult());
}
use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_AsInSelect.
@Test
public void getResult_noChangesMade_AsInSelect() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel playerEntity = builder.produceImmediately("Player", "name", "nickname", "level");
DomainModel model = new DomainModel(playerEntity);
assertTransformsToSame(model, "select p.name as name, p.nickname as nickname from Player p");
assertTransformsToSame(model, "select p.name as name from Player p");
}
Aggregations