use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class QueryParserAstBasedTest method testError.
@Test
public void testError() throws Exception {
DomainModel model = prepareDomainModel();
try {
QueryParserAstBased parser = new QueryParserAstBased(model, "select u from sec$Constraint");
parser.getEntityAlias();
fail();
} catch (JpqlSyntaxException e) {
// OK
}
try {
QueryParserAstBased parser = new QueryParserAstBased(model, "select u from sec$GroupHierarchy where u.createdBy = 'createdBy'");
parser.getEntityAlias();
fail();
} catch (JpqlSyntaxException e) {
// OK
}
try {
QueryParserAstBased parser = new QueryParserAstBased(model, "select u from sec$GroupHierarchy u where u.createdBy != 'createdBy'");
parser.getEntityAlias();
fail();
} catch (JpqlSyntaxException e) {
// OK
}
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel 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);
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class QueryParserAstBasedTest method testIsEntitySelect.
@Test
public void testIsEntitySelect() throws Exception {
DomainModel model = prepareDomainModel();
QueryParserAstBased parser = new QueryParserAstBased(model, "select h from sec$Constraint u, sec$GroupHierarchy h where h.userGroup = :par");
assertTrue(parser.isEntitySelect("sec$GroupHierarchy"));
parser = new QueryParserAstBased(model, "select h.createdBy, h.parent from sec$Constraint u, sec$GroupHierarchy h where h.userGroup = :par");
assertFalse(parser.isEntitySelect("sec$GroupHierarchy"));
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel in project cuba by cuba-platform.
the class QueryParserAstBasedTest method testScalarExpressionInSelect.
@Test
public void testScalarExpressionInSelect() throws Exception {
DomainModel model = prepareDomainModel();
QueryParserAstBased transformer = new QueryParserAstBased(model, "select c.int1 + c.int2 * c.int1 from sec$User u");
transformer.getParamNames();
}
use of com.haulmont.cuba.core.sys.jpql.DomainModel 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");
}
Aggregations