Search in sources :

Example 1 with JPA2Lexer

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

the class Jpa2GrammarTest method testEscape.

@Test
public void testEscape() throws Exception {
    String query = "c.name like :pattern escape '/'";
    CharStream cs = new AntlrNoCaseStringStream(query);
    JPA2Lexer lexer = new JPA2Lexer(cs);
    TokenStream tstream = new CommonTokenStream(lexer);
    JPA2Parser jpa2Parser = new JPA2Parser(tstream);
    JPA2Parser.like_expression_return aReturn = jpa2Parser.like_expression();
    Assert.assertNotNull(aReturn);
    query = "c.name like :pattern escape '.'";
    cs = new AntlrNoCaseStringStream(query);
    lexer = new JPA2Lexer(cs);
    tstream = new CommonTokenStream(lexer);
    jpa2Parser = new JPA2Parser(tstream);
    aReturn = jpa2Parser.like_expression();
    Assert.assertTrue(isValid((CommonTree) aReturn.getTree()));
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser) JPA2Lexer(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer) CharStream(org.antlr.runtime.CharStream) Test(org.junit.Test)

Example 2 with JPA2Lexer

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

the class Jpa2GrammarTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    String query = "update sec$User u set u.group = :group where u.id = :userId";
    CharStream cs = new AntlrNoCaseStringStream(query);
    JPA2Lexer lexer = new JPA2Lexer(cs);
    TokenStream tstream = new CommonTokenStream(lexer);
    JPA2Parser jpa2Parser = new JPA2Parser(tstream);
    JPA2Parser.update_statement_return aReturn = jpa2Parser.update_statement();
    Assert.assertTrue(isValid((CommonTree) aReturn.getTree()));
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser) JPA2Lexer(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer) CharStream(org.antlr.runtime.CharStream) Test(org.junit.Test)

Example 3 with JPA2Lexer

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

the class Jpa2GrammarTest method testTypeField.

@Test
public void testTypeField() throws Exception {
    String query = "where e.model.type = :component$filter.model_type89015";
    CharStream cs = new AntlrNoCaseStringStream(query);
    JPA2Lexer lexer = new JPA2Lexer(cs);
    TokenStream tstream = new CommonTokenStream(lexer);
    JPA2Parser jpa2Parser = new JPA2Parser(tstream);
    JPA2Parser.where_clause_return aReturn = jpa2Parser.where_clause();
    Assert.assertTrue(isValid((CommonTree) aReturn.getTree()));
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser) JPA2Lexer(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer) CharStream(org.antlr.runtime.CharStream) Test(org.junit.Test)

Example 4 with JPA2Lexer

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

the class Jpa2GrammarTest method testMemberOf.

@Test
@Ignore
public void testMemberOf() throws Exception {
    String query = "where p.owner.id = :userParam or (select u from tamsy$User u where u.id = :userParam) member of p.developers";
    CharStream cs = new AntlrNoCaseStringStream(query);
    JPA2Lexer lexer = new JPA2Lexer(cs);
    TokenStream tstream = new CommonTokenStream(lexer);
    JPA2Parser jpa2Parser = new JPA2Parser(tstream);
    JPA2Parser.where_clause_return aReturn = jpa2Parser.where_clause();
    Assert.assertTrue(isValid((CommonTree) aReturn.getTree()));
    testQuery("SELECT d FROM app$Department d WHERE (select e from app$Employee e where e.id = :eParam) MEMBER OF e.employees");
    testQuery("SELECT e FROM app$Employee e WHERE 'write code' MEMBER OF e.codes");
    testQuery("SELECT e FROM app$Employee e WHERE 'write code' NOT MEMBER OF e.codes");
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser) JPA2Lexer(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer) CharStream(org.antlr.runtime.CharStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with JPA2Lexer

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

the class Jpa2GrammarTest method testQuery.

private void testQuery(String query) throws RecognitionException {
    CharStream cs = new AntlrNoCaseStringStream(query);
    JPA2Lexer lexer = new JPA2Lexer(cs);
    TokenStream tstream = new CommonTokenStream(lexer);
    JPA2Parser jpa2Parser = new JPA2Parser(tstream);
    JPA2Parser.ql_statement_return aReturn = jpa2Parser.ql_statement();
    Assert.assertTrue(isValid((CommonTree) aReturn.getTree()));
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser) JPA2Lexer(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer) CharStream(org.antlr.runtime.CharStream)

Aggregations

JPA2Lexer (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer)6 JPA2Parser (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser)6 CharStream (org.antlr.runtime.CharStream)6 CommonTokenStream (org.antlr.runtime.CommonTokenStream)6 TokenStream (org.antlr.runtime.TokenStream)6 CommonTree (org.antlr.runtime.tree.CommonTree)5 Test (org.junit.Test)4 Ignore (org.junit.Ignore)1