use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser 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");
}
use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser 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()));
}
use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser in project cuba by cuba-platform.
the class Parser method createParser.
private static JPA2Parser createParser(String input) {
if (input.contains("~"))
throw new IllegalArgumentException("Input string cannot contain \"~\"");
CharStream cs = new AntlrNoCaseStringStream(input);
JPA2Lexer lexer = new JPA2Lexer(cs);
TokenStream tstream = new CommonTokenStream(lexer);
return new JPA2Parser(tstream);
}
use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser in project cuba by cuba-platform.
the class Parser method parseWhereClause.
public static CommonTree parseWhereClause(String input) throws RecognitionException {
JPA2Parser parser = createParser(input);
JPA2Parser.where_clause_return aReturn = parser.where_clause();
CommonTree tree = (CommonTree) aReturn.getTree();
checkTreeForExceptions(input, tree);
return tree;
}
use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser in project cuba by cuba-platform.
the class Parser method parseJoinClause.
public static List<JoinVariableNode> parseJoinClause(String join) throws RecognitionException {
JPA2Parser parser = createParser(join);
JPA2Parser.join_section_return aReturn = parser.join_section();
CommonTree tree = (CommonTree) aReturn.getTree();
if (tree == null) {
parser = createParser("join " + join);
aReturn = parser.join_section();
tree = (CommonTree) aReturn.getTree();
}
if (tree instanceof JoinVariableNode) {
checkTreeForExceptions(join, tree);
return Collections.singletonList((JoinVariableNode) tree);
} else {
List<JoinVariableNode> joins = tree.getChildren().stream().filter(node -> node instanceof JoinVariableNode).map(JoinVariableNode.class::cast).collect(Collectors.toList());
checkTreeForExceptions(join, tree);
return joins;
}
}
Aggregations