Search in sources :

Example 51 with DomainModel

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
    }
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) JpqlSyntaxException(com.haulmont.cuba.core.sys.jpql.JpqlSyntaxException) Test(org.junit.Test)

Example 52 with DomainModel

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);
}
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 53 with DomainModel

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"));
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) Test(org.junit.Test)

Example 54 with DomainModel

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();
}
Also used : DomainModel(com.haulmont.cuba.core.sys.jpql.DomainModel) Test(org.junit.Test)

Example 55 with DomainModel

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