Search in sources :

Example 46 with DomainModel

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

the class QueryTransformationTest 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.addCollectionReferenceAttribute("constraints", "sec$Constraint");
    JpqlEntityModel groupHierarchy = builder.produce();
    JpqlEntityModel constraintEntity = builder.produceImmediately("sec$Constraint");
    return new DomainModel(groupHierarchy, constraintEntity);
}
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 47 with DomainModel

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

the class CustomConditionFrame method requestHintParamWhere.

protected List<Suggestion> requestHintParamWhere(SourceCodeEditor sender, String text, int senderCursorPosition) {
    String whereStr = entityParamWhereField.getValue();
    MetaClass metaClass = entitySelect.getValue();
    if (metaClass == null) {
        return new ArrayList<>();
    }
    // CAUTION: the magic entity name!  The length is three character to match "{E}" length in query
    String entityAlias = "a39";
    int queryPosition = -1;
    String queryStart = "select " + entityAlias + " from " + metaClass.getName() + " " + entityAlias + " ";
    StringBuilder queryBuilder = new StringBuilder(queryStart);
    if (whereStr != null && !whereStr.equals("")) {
        queryPosition = queryBuilder.length() + WHERE.length() + senderCursorPosition - 1;
        queryBuilder.append(WHERE).append(whereStr);
    }
    String query = queryBuilder.toString();
    query = query.replace("{E}", entityAlias);
    DomainModelBuilder builder = AppBeans.get(DomainModelWithCaptionsBuilder.NAME);
    DomainModel domainModel = builder.produce();
    return JpqlSuggestionFactory.requestHint(query, queryPosition, sender.getAutoCompleteSupport(), senderCursorPosition, new ExtHintProvider(domainModel));
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) DomainModelBuilder(com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)

Example 48 with DomainModel

use of com.haulmont.cuba.core.sys.jpql.DomainModel 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 49 with DomainModel

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

the class QueryParserAstBasedTest method testEnumMacro.

@Test
public void testEnumMacro() {
    DomainModel model = prepareDomainModel();
    QueryParserAstBased parser = new QueryParserAstBased(model, "select r from sec$Role r where r.type = @enum(com.haulmont.cuba.security.entity.RoleType.STANDARD)");
    parser.getEntityName();
    parser = new QueryParserAstBased(model, "select r from sec$Role r where (select r1.type from sec$Role r1 where r1.id = r.id) = @enum(com.haulmont.cuba.security.entity.RoleType.STANDARD)");
    parser.getEntityName();
    parser = new QueryParserAstBased(model, "select r from sec$Role r where r.type in (@enum(com.haulmont.cuba.security.entity.RoleType.STANDARD), @enum(com.haulmont.cuba.security.entity.RoleType.SUPER))");
    parser.getEntityName();
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) Test(org.junit.Test)

Example 50 with DomainModel

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

the class QueryParserAstBasedTest method testNestedEntityGroupBy.

@Test
public void testNestedEntityGroupBy() throws Exception {
    DomainModel model = prepareDomainModel();
    QueryTransformerAstBased transformer = new QueryTransformerAstBased(model, "select c.group, count(c.id) from sec$Constraint c group by c.group");
    transformer.replaceWithSelectEntityVariable("tempEntityAlias");
    transformer.addFirstSelectionSource(String.format("%s tempEntityAlias", "sec$Group"));
    transformer.addWhereAsIs(String.format("tempEntityAlias.id = %s.id", "c.group"));
    transformer.addEntityInGroupBy("tempEntityAlias");
    System.out.println(transformer.getResult());
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) QueryTransformerAstBased(com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased) Test(org.junit.Test)

Aggregations

DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)94 Test (org.junit.Test)86 EntityBuilder (com.haulmont.cuba.core.sys.jpql.model.EntityBuilder)49 JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)45 QueryTransformerAstBased (com.haulmont.cuba.core.sys.jpql.transform.QueryTransformerAstBased)37 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)21 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)20 QueryTreeTransformer (com.haulmont.cuba.core.sys.jpql.transform.QueryTreeTransformer)8 CommonTree (org.antlr.runtime.tree.CommonTree)7 VariableEntityReference (com.haulmont.cuba.core.sys.jpql.transform.VariableEntityReference)5 JpqlEntityModelImpl (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModelImpl)4 JpqlSyntaxException (com.haulmont.cuba.core.sys.jpql.JpqlSyntaxException)3 Tree (org.antlr.runtime.tree.Tree)3 DomainModelBuilder (com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 TreeToQuery (com.haulmont.cuba.core.sys.jpql.TreeToQuery)1 PathEntityReference (com.haulmont.cuba.core.sys.jpql.transform.PathEntityReference)1 HintRequest (com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest)1 Option (com.haulmont.cuba.gui.components.autocomplete.impl.Option)1 ArrayList (java.util.ArrayList)1