Search in sources :

Example 11 with EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder in project cuba by cuba-platform.

the class QueryAnalyzerTest method prepareDomainModel.

private DomainModel prepareDomainModel() {
    EntityBuilder builder = new EntityBuilder();
    builder.startNewEntity("Driver");
    builder.addStringAttribute("name");
    builder.addStringAttribute("signal");
    builder.addReferenceAttribute("car", "Driver");
    JpqlEntityModel driver = builder.produce();
    builder.startNewEntity("Car");
    builder.addStringAttribute("model");
    builder.addStringAttribute("regNumber");
    builder.addCollectionReferenceAttribute("drivers", "Driver");
    JpqlEntityModel car = builder.produce();
    return new DomainModel(car, driver);
}
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 12 with EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder in project cuba by cuba-platform.

the class QueryAnalyzerTest method mixinJoinIntoTree_with_in_collections.

@Test
public void mixinJoinIntoTree_with_in_collections() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    builder.startNewEntity("HomeBase");
    builder.addStringAttribute("name");
    JpqlEntityModel homeBase = builder.produce();
    builder.startNewEntity("Driver");
    builder.addStringAttribute("name");
    builder.addStringAttribute("signal");
    JpqlEntityModel driver = 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);
    JoinVariableNode join = Parser.parseJoinClause("join c.station h").get(0);
    QueryTreeTransformer qa = new QueryTreeTransformer();
    qa.prepare(model, "select d.name from Car c, in(c.drivers) d");
    CommonTree tree = qa.getTree();
    CommonTree sources = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_SOURCES);
    assertEquals(2, sources.getChildCount());
    assertTrue(sources.getChild(0) instanceof SelectionSourceNode);
    CommonTree source0 = (CommonTree) sources.getChild(0);
    assertEquals(1, source0.getChildCount());
    assertTrue(source0.getChild(0) instanceof IdentificationVariableNode);
    assertTrue(sources.getChild(1) instanceof SelectionSourceNode);
    CommonTree source1 = (CommonTree) sources.getChild(1);
    assertTrue(source1.getChild(0) instanceof CollectionMemberNode);
    qa.mixinJoinIntoTree(join, new VariableEntityReference("Car", "c"), true);
    tree = qa.getTree();
    sources = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_SOURCES);
    assertEquals(2, sources.getChildCount());
    assertTrue(sources.getChild(0) instanceof SelectionSourceNode);
    source0 = (CommonTree) sources.getChild(0);
    assertEquals(2, source0.getChildCount());
    assertTrue(source0.getChild(0) instanceof IdentificationVariableNode);
    assertTrue(source0.getChild(1) instanceof JoinVariableNode);
    assertTrue(sources.getChild(1) instanceof SelectionSourceNode);
    source1 = (CommonTree) sources.getChild(1);
    assertTrue(source1.getChild(0) instanceof CollectionMemberNode);
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) CommonTree(org.antlr.runtime.tree.CommonTree) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) QueryTreeTransformer(com.haulmont.cuba.core.sys.jpql.transform.QueryTreeTransformer) VariableEntityReference(com.haulmont.cuba.core.sys.jpql.transform.VariableEntityReference) Test(org.junit.Test)

Example 13 with EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder 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 14 with EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder 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 15 with EntityBuilder

use of com.haulmont.cuba.core.sys.jpql.model.EntityBuilder 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)

Aggregations

EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)50 DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)49 JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)46 Test (org.junit.Test)44 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)20 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)19 QueryTransformerAstBased (com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased)9 JpqlEntityModelImpl (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl)4 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 QueryTreeTransformer (com.haulmont.cuba.core.sys.jpql.transform.QueryTreeTransformer)1 VariableEntityReference (com.haulmont.cuba.core.sys.jpql.transform.VariableEntityReference)1 CommonTree (org.antlr.runtime.tree.CommonTree)1