Search in sources :

Example 31 with JpqlEntityModel

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

the class DomainModelBuilder method produce.

public DomainModel produce() {
    Collection<MetaClass> classes = metadata.getSession().getClasses();
    DomainModel result = new DomainModel(extendedEntities);
    EntityBuilder builder = new EntityBuilder();
    for (MetaClass aClass : classes) {
        builder.startNewEntity(aClass.getName());
        Collection<MetaProperty> props = aClass.getProperties();
        for (MetaProperty prop : props) {
            if (metadataTools.isPersistent(prop))
                addProperty(builder, aClass, prop);
        }
        JpqlEntityModel entity = builder.produce();
        result.add(entity);
    }
    return result;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) EntityBuilder(com.haulmont.cuba.core.sys.jpql.model.EntityBuilder) MetaProperty(com.haulmont.chile.core.model.MetaProperty) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)

Example 32 with JpqlEntityModel

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

the class QueryTransformerAstSoftDeleteBugsTest method createDomainModel.

private DomainModel createDomainModel() {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel debtorEntity = builder.produceImmediately("dn$Debtor", "id", "id");
    JpqlEntityModel agentEntity = builder.produceImmediately("dn$Agent", "id", "id");
    JpqlEntityModel userEntity = builder.produceImmediately("sec$User", "active", "deleteTs");
    JpqlEntityModel agentAllocation = builder.produceImmediately("dn$AgentAllocation", "agent", "debtor");
    JpqlEntityModel scheduleOperation = builder.produceImmediately("dn$ScheduleOperation");
    JpqlEntityModel bailiffDaySchedule = builder.produceImmediately("dn$BailiffDaySchedule", "day");
    scheduleOperation.addReferenceAttribute("dn$BailiffDaySchedule", "bailiffDaySchedule", "bailiffDaySchedule", false);
    scheduleOperation.addReferenceAttribute("dn$Debtor", "debtor", "debtor", false);
    return new DomainModel(userEntity, agentAllocation, scheduleOperation, bailiffDaySchedule, debtorEntity);
}
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 33 with JpqlEntityModel

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

the class QueryParserAstBasedTest method prepareDomainModel.

private DomainModel prepareDomainModel() {
    EntityBuilder builder = new EntityBuilder();
    builder.startNewEntity("sec$GroupHierarchy");
    builder.addReferenceAttribute("group", "sec$Group");
    builder.addReferenceAttribute("as", "sec$Group");
    builder.addStringAttribute("createdBy");
    builder.addReferenceAttribute("parent", "sec$GroupHierarchy");
    builder.addReferenceAttribute("other", "sec$GroupHierarchy");
    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 groupEntity = builder.produceImmediately("sec$Group", "name", "group");
    builder = new EntityBuilder();
    builder.startNewEntity("sec$User");
    builder.addStringAttribute("login");
    builder.addSingleValueAttribute(Integer.class, "int1");
    builder.addSingleValueAttribute(Integer.class, "int2");
    builder.addReferenceAttribute("group", "sec$Group");
    JpqlEntityModel userEntity = builder.produce();
    return new DomainModel(groupHierarchy, constraintEntity, userEntity, groupEntity);
}
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 34 with JpqlEntityModel

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

the class QueryTransformerAstBasedTest method getResult_noChangesMade_withMultiFieldSelect.

@Test
public void getResult_noChangesMade_withMultiFieldSelect() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    builder.startNewEntity("Team");
    builder.addStringAttribute("name");
    JpqlEntityModel teamEntity = builder.produce();
    builder.startNewEntity("Player");
    builder.addStringAttribute("nickname");
    builder.addReferenceAttribute("team", "Team");
    JpqlEntityModel playerEntity = builder.produce();
    DomainModel model = new DomainModel(playerEntity, teamEntity);
    assertTransformsToSame(model, "SELECT p.team.name, p.nickname FROM Player p");
}
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 35 with JpqlEntityModel

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

the class QueryTransformerAstBasedTest method getResult_noChangesMade_withJoinAndAsAndMemberField.

@Test
public void getResult_noChangesMade_withJoinAndAsAndMemberField() throws RecognitionException {
    EntityBuilder builder = new EntityBuilder();
    JpqlEntityModel teamEntity = builder.produceImmediately("Team", "name");
    builder.startNewEntity("Player");
    builder.addReferenceAttribute("as", "Team");
    builder.addReferenceAttribute("member", "Team");
    JpqlEntityModel playerEntity = builder.produce();
    DomainModel model = new DomainModel(playerEntity, teamEntity);
    assertTransformsToSame(model, "SELECT p FROM Player p JOIN p.as t");
    assertTransformsToSame(model, "SELECT p FROM Player p JOIN p.member t");
}
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

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