use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method testReplaceWithCount.
@Test
public void testReplaceWithCount() throws RecognitionException {
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");
transformer.replaceWithCount();
assertEquals("select count(c) from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by c.level having c.level > 0", transformer.getResult());
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");
transformer.replaceWithCount();
assertEquals("select count(c) from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by c.level having c.level > 0", transformer.getResult());
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel 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.DomainModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method testReplaceWithCount_distinct.
@Test
public void testReplaceWithCount_distinct() throws RecognitionException {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select distinct 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");
transformer.replaceWithCount();
String res = transformer.getResult();
assertEquals("select count(distinct c) from sec$GroupHierarchy h join h.parent.constraints c where h.group = ?1 " + "group by c.level having c.level > 0", res);
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel 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.DomainModel 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);
}
Aggregations