Search in sources :

Example 1 with DomainModelBuilder

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

the class JpqlSuggestionFactory method requestHint.

public static List<Suggestion> requestHint(String query, int queryPosition, AutoCompleteSupport sender, int senderCursorPosition, @Nullable HintProvider provider) {
    DomainModelBuilder builder = AppBeans.get(DomainModelWithCaptionsBuilder.NAME);
    DomainModel domainModel = builder.produce();
    if (provider == null) {
        provider = new HintProvider(domainModel);
    }
    try {
        HintRequest request = new HintRequest();
        request.setQuery(query);
        request.setPosition(queryPosition);
        HintResponse response = provider.requestHint(request);
        String prefix = response.getLastWord();
        List<Option> options = response.getOptionObjects();
        List<Suggestion> result = new ArrayList<>();
        for (Option option : options) {
            Suggestion suggestion = JpqlSuggestionFactory.produce(sender, option.getValue(), option.getDescription(), senderCursorPosition, prefix == null ? 0 : prefix.length());
            result.add(suggestion);
        }
        return result;
    } catch (org.antlr.runtime.RecognitionException e) {
        throw new RuntimeException(e);
    }
}
Also used : HintRequest(com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest) DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) ArrayList(java.util.ArrayList) HintProvider(com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider) HintResponse(com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse) DomainModelBuilder(com.haulmont.cuba.core.sys.jpql.DomainModelBuilder) Option(com.haulmont.cuba.gui.components.autocomplete.impl.Option)

Example 2 with DomainModelBuilder

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

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

the class QueryTransformerFactory method transformer.

public QueryTransformer transformer(String query) {
    if (useAst) {
        if (domainModel == null) {
            DomainModelBuilder builder = AppBeans.get(DomainModelBuilder.NAME);
            domainModel = builder.produce();
        }
        return AppBeans.getPrototype(QueryTransformer.NAME, domainModel, query);
    } else {
        return new QueryTransformerRegex(query);
    }
}
Also used : DomainModelBuilder(com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)

Example 4 with DomainModelBuilder

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

the class QueryTransformerFactory method parser.

public QueryParser parser(String query) {
    if (useAst) {
        if (domainModel == null) {
            DomainModelBuilder builder = AppBeans.get(DomainModelBuilder.NAME);
            domainModel = builder.produce();
        }
        return AppBeans.getPrototype(QueryParser.NAME, domainModel, query);
    } else {
        return new QueryParserRegex(query);
    }
}
Also used : DomainModelBuilder(com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)

Aggregations

DomainModelBuilder (com.haulmont.cuba.core.sys.jpql.DomainModelBuilder)4 DomainModel (com.haulmont.cuba.core.sys.jpql.DomainModel)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 HintProvider (com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider)1 HintRequest (com.haulmont.cuba.gui.components.autocomplete.impl.HintRequest)1 HintResponse (com.haulmont.cuba.gui.components.autocomplete.impl.HintResponse)1 Option (com.haulmont.cuba.gui.components.autocomplete.impl.Option)1 ArrayList (java.util.ArrayList)1