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