Search in sources :

Example 26 with EntityBuilder

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

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

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

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

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

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