use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method testDoubleJoins.
@Test
public void testDoubleJoins() throws Exception {
DomainModel model = prepareDomainModel();
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select h from sec$GroupHierarchy h where h.group = :par");
transformer.reset();
transformer.addJoinAndWhere("join h.parent.constraints c1 join h.constraints c2", "c.createdBy = :par2");
String res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h join h.parent.constraints c1 join h.constraints c2 where (h.group = :par) and (c.createdBy = :par2)", res);
transformer.reset();
transformer.addJoinAndWhere("join {E}.parent p join p.constraints cr", "c.createdBy = :par2");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h join h.parent p join p.constraints cr where (h.group = :par) and (c.createdBy = :par2)", res);
transformer.reset();
transformer.addJoinAndWhere("join replaceEntity.parent p join p.constraints cr", "c.createdBy = :par2");
res = transformer.getResult();
assertEquals("select h from sec$GroupHierarchy h join h.parent p join p.constraints cr where (h.group = :par) and (c.createdBy = :par2)", res);
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_with_in_collections.
@Test
public void getResult_noChangesMade_with_in_collections() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel driver = builder.produceImmediately("Driver", "name", "signal");
builder.startNewEntity("HomeBase");
builder.addStringAttribute("city");
JpqlEntityModel homeBase = builder.produce();
builder.startNewEntity("Car");
builder.addStringAttribute("model");
builder.addCollectionReferenceAttribute("drivers", "Driver");
builder.addReferenceAttribute("station", "HomeBase");
JpqlEntityModel car = builder.produce();
DomainModel model = new DomainModel(car, driver, homeBase);
assertTransformsToSame(model, "select d.name from Car c, in(c.drivers) d where d.name = ?1");
assertTransformsToSame(model, "select d.name from Car c join c.station s, in(c.drivers) d where d.name = ?1 and s.city = :par2");
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method transformationsUsingSelectedEntity.
@Test
public void transformationsUsingSelectedEntity() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
builder.startNewEntity("sec$Car");
builder.addStringAttribute("model");
builder.addReferenceAttribute("colour", "sec$Colour");
JpqlEntityModel car = builder.produce();
builder.startNewEntity("sec$Colour");
builder.addStringAttribute("name");
builder.addStringAttribute("createdBy");
builder.addSingleValueAttribute(Integer.class, "version");
builder.addReferenceAttribute("manufacturer", "Manufacturer");
JpqlEntityModel colour = builder.produce();
JpqlEntityModel manufacturer = builder.produceImmediately("Manufacturer", "companyName");
DomainModel model = new DomainModel(car, colour, manufacturer);
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select c.colour from sec$Car c where c.colour.createdBy = :p");
transformer.addWhere("{E}.colour.createdBy = :session$userLogin");
String res = transformer.getResult();
assertEquals("select c.colour from sec$Car c where (c.colour.createdBy = :p) and (c.colour.createdBy = :session$userLogin)", res);
transformer = new QueryTransformerAstBased(model, "select c.colour from sec$Car c where c.colour.createdBy = :p");
transformer.addJoinAndWhere("join {E}.manufacturer m", "m.companyName = :par1");
res = transformer.getResult();
assertEquals("select c.colour from sec$Car c join c.manufacturer m where (c.colour.createdBy = :p) and (m.companyName = :par1)", res);
// todo eude: fix the following
// transformer = new QueryTransformerAstBased(model,
// "select c.colour from sec$Car c where c.colour.createdBy = :p");
// transformer.mergeWhere("select gh from sec$Colour gh where gh.version between 1 and 2");
//
// res = transformer.getResult();
// assertEquals(
// "select c.colour from sec$Car c where (c.colour.createdBy = :p) and (c.colour.version between 1 and 2)",
// res);
// transformer = new QueryTransformerAstBased(model,
// "select c.colour from sec$Car c where c.colour.createdBy = :p order by c.colour.name");
// transformer.replaceOrderBy(true, "version");
//
// res = transformer.getResult();
// assertEquals(
// "select c.colour from sec$Car c left join c.colour c_colour where c.colour.createdBy = :p order by c_colour.version desc",
// res);
//
//
// transformer = new QueryTransformerAstBased(model,
// "select c.colour from sec$Car c where c.colour.createdBy = :p");
// transformer.replaceWithCount();
//
// res = transformer.getResult();
// assertEquals(
// "select count(c.colour) from sec$Car c where c.colour.createdBy = :p",
// res);
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_update.
@Test
public void getResult_noChangesMade_update() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
builder.startNewEntity("sec$Car");
builder.addStringAttribute("model");
builder.addStringAttribute("vin");
JpqlEntityModel car = builder.produce();
DomainModel model = new DomainModel(car);
QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "update sec$Car c set c.model = :model, c.vin = :vin");
assertEquals("update sec$Car c set c.model=:model,c.vin=:vin", transformer.getResult());
transformer = new QueryTransformerAstBased(model, "update sec$Car c set c.model = :model, c.vin = :vin where c.vin = :oldVin");
assertEquals("update sec$Car c set c.model=:model,c.vin=:vin where c.vin = :oldVin", transformer.getResult());
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel 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");
}
Aggregations