use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method prepareDomainModel.
private DomainModel prepareDomainModel() {
EntityBuilder builder = new EntityBuilder();
builder.startNewEntity("sec$GroupHierarchy");
builder.addStringAttribute("group");
builder.addStringAttribute("createdBy");
builder.addReferenceAttribute("parent", "sec$GroupHierarchy");
builder.addReferenceAttribute("other", "sec$GroupHierarchy");
builder.addReferenceAttribute("token", "fake$EmbeddedToken", "token", true);
builder.addCollectionReferenceAttribute("constraints", "sec$Constraint");
JpqlEntityModel groupHierarchy = builder.produce();
builder = new EntityBuilder();
builder.startNewEntity("sec$Constraint");
builder.addReferenceAttribute("group", "sec$GroupHierarchy");
JpqlEntityModel constraintEntity = builder.produce();
JpqlEntityModel userEntity = builder.produceImmediately("sec$User", "login");
builder = new EntityBuilder();
builder.startNewEntity("fake$EmbeddedToken");
builder.addStringAttribute("name");
builder.addStringAttribute("code");
builder.addReferenceAttribute("manager", "sec$User");
builder.addReferenceAttribute("parentToken", "fake$EmbeddedToken", "parentToken", true);
JpqlEntityModel token = builder.produce();
return new DomainModel(groupHierarchy, constraintEntity, userEntity, token);
}
use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel in project cuba by cuba-platform.
the class QueryTransformerAstBasedTest method getResult_noChangesMade_withParameters.
@Test
public void getResult_noChangesMade_withParameters() throws RecognitionException {
EntityBuilder builder = new EntityBuilder();
JpqlEntityModel playerEntity = builder.produceImmediately("Player", "name", "nickname");
DomainModel model = new DomainModel(playerEntity);
assertTransformsToSame(model, "select p.nickname from Player p where p.name = :name");
assertTransformsToSame(model, "select p.nickname from Player p where p.name = :name or p.name = :name2");
assertTransformsToSame(model, "select p.nickname from Player p where p.name = ?1 or p.name = ?2");
assertTransformsToSame(model, "select p.nickname from Player p where p.name like :component$playersFilter.name52981");
}
use of com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel 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.model.JpqlEntityModel 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.model.JpqlEntityModel 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());
}
Aggregations