CQNParser extends QueryParser<O> { @Override public ParseResult<O> parse(String query) { try { if (query == null) { throw new IllegalArgumentException("Query was null"); } CQNGrammarLexer lexer = new CQNGrammarLexer(new ANTLRInputStream(query)); lexer.removeErrorListeners(); lexer.addErrorListener(SYNTAX_ERROR_LISTENER); CommonTokenStream tokens = new CommonTokenStream(lexer); CQNGrammarParser parser = new CQNGrammarParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(SYNTAX_ERROR_LISTENER); CQNGrammarParser.StartContext queryContext = parser.start(); ParseTreeWalker walker = new ParseTreeWalker(); CQNAntlrListener<O> listener = new CQNAntlrListener<O>(this); walker.walk(listener, queryContext); return new ParseResult<O>(listener.getParsedQuery(), listener.getQueryOptions()); } catch (InvalidQueryException e) { throw e; } catch (Exception e) { throw new InvalidQueryException("Failed to parse query", e); } } CQNParser(Class<O> objectType); @Override ParseResult<O> parse(String query); static CQNParser<O> forPojo(Class<O> pojoClass); static CQNParser<O> forPojoWithAttributes(Class<O> pojoClass, Map<String, ? extends Attribute<O, ?>> attributes);  }
@Test public void testOrderBy_NoOrdering() { ParseResult<Car> parseResult = parser.parse("equal(\"manufacturer\", \"Ford\")"); assertQueriesEquals(equal(Car.MANUFACTURER, "Ford"), parseResult.getQuery()); Assert.assertEquals(noQueryOptions(), parseResult.getQueryOptions()); }
@Test public void testOrderBy_SimpleOrdering() { ParseResult<Car> parseResult = parser.parse("equal(\"manufacturer\", \"Ford\"), queryOptions(orderBy(ascending(\"manufacturer\")))"); assertQueriesEquals(equal(Car.MANUFACTURER, "Ford"), parseResult.getQuery()); Assert.assertEquals(queryOptions(orderBy(ascending(Car.MANUFACTURER))), parseResult.getQueryOptions()); }
@Test public void testOrderBy_ComplexOrdering() { ParseResult<Car> parseResult = parser.parse("equal(\"manufacturer\", \"Ford\"), queryOptions(orderBy(ascending(\"manufacturer\"), descending(\"carId\")))"); assertQueriesEquals(equal(Car.MANUFACTURER, "Ford"), parseResult.getQuery()); Assert.assertEquals(queryOptions(orderBy(ascending(Car.MANUFACTURER), descending(Car.CAR_ID))), parseResult.getQueryOptions()); }