Search in sources :

Example 16 with JpqlEntityModel

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);
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)

Example 17 with JpqlEntityModel

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");
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) Test(org.junit.Test)

Example 18 with JpqlEntityModel

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");
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) Test(org.junit.Test)

Example 19 with JpqlEntityModel

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);
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) Test(org.junit.Test)

Example 20 with JpqlEntityModel

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());
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) Test(org.junit.Test)

Aggregations

JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)57 EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)46 DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)45 Test (org.junit.Test)40 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)17 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)16 QueryTransformerAstBased (com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased)9 ArrayList (java.util.ArrayList)5 Attribute (com.haulmont.cuba.core.sys.jpql.model.Attribute)4 PathNode (com.haulmont.cuba.core.sys.jpql.tree.PathNode)4 IdentificationVariableNode (com.haulmont.cuba.core.sys.jpql.tree.IdentificationVariableNode)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 UnknownEntityNameException (com.haulmont.cuba.core.sys.jpql.UnknownEntityNameException)2 NoJpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.NoJpqlEntityModel)2 Pointer (com.haulmont.cuba.core.sys.jpql.pointer.Pointer)2 List (java.util.List)2 CommonTree (org.antlr.runtime.tree.CommonTree)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 JPA2RecognitionException (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2RecognitionException)1 VirtualJpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.VirtualJpqlEntityModel)1