@Test public void testParseSelect() { final MinijaxCriteriaQuery<Widget> query = Parser.parse( em.getCriteriaBuilder(), Widget.class, Tokenizer.tokenize("SELECT w FROM Widget w WHERE id = :id")); assertNotNull(query); }
private MinijaxCriteriaQuery<T> parseSelect() { consume(TokenType.KEYWORD_SELECT); query = cb.createQuery(resultType); while (getCurr().getTokenType() != TokenType.KEYWORD_FROM) { index++; } consume(TokenType.KEYWORD_FROM); final MinijaxEntityType<T> resultEntityType = cb.getMetamodel().entity(resultType); final String entityTypeName = consume(TokenType.SYMBOL).getValue(); if (!resultEntityType.getName().equals(entityTypeName)) { throw new PersistenceException( "Result type does not match entity type name (resultEntityType=" + resultEntityType.getName() + ", entityTypeName=" + entityTypeName + ")"); } root = query.from(resultType); final String entityTypeAlias = consume(TokenType.SYMBOL).getValue(); root.alias(entityTypeAlias); while (!eof()) { final Token curr = getCurr(); switch (curr.getTokenType()) { case KEYWORD_WHERE: parseWhere(); break; case KEYWORD_ORDER: parseOrderBy(); break; default: throw new PersistenceException("Unexpected token: " + curr); } } return query; }
Parser { private MinijaxCriteriaQuery<T> parseSelect() { consume(TokenType.KEYWORD_SELECT); query = cb.createQuery(resultType); while (getCurr().getTokenType() != TokenType.KEYWORD_FROM) { index++; } consume(TokenType.KEYWORD_FROM); final MinijaxEntityType<T> resultEntityType = cb.getMetamodel().entity(resultType); final String entityTypeName = consume(TokenType.SYMBOL).getValue(); if (!resultEntityType.getName().equals(entityTypeName)) { throw new PersistenceException( "Result type does not match entity type name (resultEntityType=" + resultEntityType.getName() + ", entityTypeName=" + entityTypeName + ")"); } root = query.from(resultType); final String entityTypeAlias = consume(TokenType.SYMBOL).getValue(); root.alias(entityTypeAlias); while (!eof()) { final Token curr = getCurr(); switch (curr.getTokenType()) { case KEYWORD_WHERE: parseWhere(); break; case KEYWORD_ORDER: parseOrderBy(); break; default: throw new PersistenceException("Unexpected token: " + curr); } } return query; } }
Parser { private MinijaxCriteriaQuery<T> parseSelect() { consume(TokenType.KEYWORD_SELECT); query = cb.createQuery(resultType); while (getCurr().getTokenType() != TokenType.KEYWORD_FROM) { index++; } consume(TokenType.KEYWORD_FROM); final MinijaxEntityType<T> resultEntityType = cb.getMetamodel().entity(resultType); final String entityTypeName = consume(TokenType.SYMBOL).getValue(); if (!resultEntityType.getName().equals(entityTypeName)) { throw new PersistenceException( "Result type does not match entity type name (resultEntityType=" + resultEntityType.getName() + ", entityTypeName=" + entityTypeName + ")"); } root = query.from(resultType); final String entityTypeAlias = consume(TokenType.SYMBOL).getValue(); root.alias(entityTypeAlias); while (!eof()) { final Token curr = getCurr(); switch (curr.getTokenType()) { case KEYWORD_WHERE: parseWhere(); break; case KEYWORD_ORDER: parseOrderBy(); break; default: throw new PersistenceException("Unexpected token: " + curr); } } return query; } private  Parser(final MinijaxCriteriaBuilder cb, final Class<T> resultType, final List<Token> tokens); }
Parser { private MinijaxCriteriaQuery<T> parseSelect() { consume(TokenType.KEYWORD_SELECT); query = cb.createQuery(resultType); while (getCurr().getTokenType() != TokenType.KEYWORD_FROM) { index++; } consume(TokenType.KEYWORD_FROM); final MinijaxEntityType<T> resultEntityType = cb.getMetamodel().entity(resultType); final String entityTypeName = consume(TokenType.SYMBOL).getValue(); if (!resultEntityType.getName().equals(entityTypeName)) { throw new PersistenceException( "Result type does not match entity type name (resultEntityType=" + resultEntityType.getName() + ", entityTypeName=" + entityTypeName + ")"); } root = query.from(resultType); final String entityTypeAlias = consume(TokenType.SYMBOL).getValue(); root.alias(entityTypeAlias); while (!eof()) { final Token curr = getCurr(); switch (curr.getTokenType()) { case KEYWORD_WHERE: parseWhere(); break; case KEYWORD_ORDER: parseOrderBy(); break; default: throw new PersistenceException("Unexpected token: " + curr); } } return query; } private  Parser(final MinijaxCriteriaBuilder cb, final Class<T> resultType, final List<Token> tokens); static MinijaxCriteriaQuery<T> parse(final MinijaxCriteriaBuilder cb, final Class<T> resultType, final List<Token> tokens); }
Parser { private MinijaxCriteriaQuery<T> parseSelect() { consume(TokenType.KEYWORD_SELECT); query = cb.createQuery(resultType); while (getCurr().getTokenType() != TokenType.KEYWORD_FROM) { index++; } consume(TokenType.KEYWORD_FROM); final MinijaxEntityType<T> resultEntityType = cb.getMetamodel().entity(resultType); final String entityTypeName = consume(TokenType.SYMBOL).getValue(); if (!resultEntityType.getName().equals(entityTypeName)) { throw new PersistenceException( "Result type does not match entity type name (resultEntityType=" + resultEntityType.getName() + ", entityTypeName=" + entityTypeName + ")"); } root = query.from(resultType); final String entityTypeAlias = consume(TokenType.SYMBOL).getValue(); root.alias(entityTypeAlias); while (!eof()) { final Token curr = getCurr(); switch (curr.getTokenType()) { case KEYWORD_WHERE: parseWhere(); break; case KEYWORD_ORDER: parseOrderBy(); break; default: throw new PersistenceException("Unexpected token: " + curr); } } return query; } private  Parser(final MinijaxCriteriaBuilder cb, final Class<T> resultType, final List<Token> tokens); static MinijaxCriteriaQuery<T> parse(final MinijaxCriteriaBuilder cb, final Class<T> resultType, final List<Token> tokens);  }