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);
}
}
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));
}
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);
}
}
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);
}
}
Aggregations