public DefaultOrmQuery<T> setQuery(String queryString) throws PersistenceException { this.query = queryString; OrmQueryDetailParser parser = new OrmQueryDetailParser(queryString); parser.parse(); parser.assign(this); return this; }
private void processInitial() { if (parser.isMatch("select")) { readSelect(); } else if (parser.isMatch("find")) { OrmQueryProperties props = readFindFetch(); detail.setBase(props); } else { process(); } while (!parser.isFinished()) { process(); } }
public void parse() throws PersistenceException { parser.nextWord(); processInitial(); }
public TunedQueryInfo(Origin origin) { this.origin = origin; this.tunedDetail = new OrmQueryDetailParser(origin.getDetail()).parse(); }
private void processInitial() { if (parser.isMatch("find")) { OrmQueryProperties props = readFindFetch(); detail.setBase(props); } else { process(); } while (!parser.isFinished()) { process(); } }
private void process() { if (isFetch()) { OrmQueryProperties props = readFindFetch(); detail.putFetchPath(props); } else if (parser.isMatch("where")) { readWhere(); } else if (parser.isMatch("order", "by")) { readOrderBy(); } else if (parser.isMatch("limit")) { readLimit(); } else { throw new PersistenceException("Query expected 'fetch', 'where','order by' or 'limit' keyword but got [" + parser.getWord() + "] \r " + parser.getOql()); } }
private void process() { if (isFetch()) { detail.fetch(readFindFetch()); } else { throw new PersistenceException("Query expected 'fetch', 'where','order by' or 'limit' keyword but got [" + parser.getWord() + "] \r " + parser.getOql()); } }
private void readWhere() { int nextMode = 0; StringBuilder sb = new StringBuilder(); while ((parser.nextWord()) != null) { if (parser.isMatch("order", "by")) { nextMode = 1; break; } else if (parser.isMatch("limit")) { nextMode = 2; break; } else { sb.append(" ").append(parser.getWord()); } } String whereClause = sb.toString().trim(); if (whereClause.length() > 0) { rawWhereClause = whereClause; } if (nextMode == 1) { readOrderBy(); } else if (nextMode == 2) { readLimit(); } }
private boolean isFindFetchEnd() { if (isFetch()) { return true; } if (parser.isMatch("where")) { return true; } if (parser.isMatch("order", "by")) { return true; } return false; } }
private OrmQueryProperties readFindFetch() { boolean readAlias = false; String props = null; String path = parser.nextWord(); String token; while ((token = parser.nextWord()) != null) { if (!readAlias && parser.isMatch("as")) { // next token is alias parser.nextWord(); readAlias = true; } else if ('(' == token.charAt(0)) { props = token; parser.nextWord(); break; } else if (isFindFetchEnd()) { break; } else if (!readAlias) { readAlias = true; } else { throw new PersistenceException("Expected (props) or new 'fetch' 'where' but got " + token); } } if (props != null) { props = props.substring(1, props.length() - 1); } return new OrmQueryProperties(path, props); }
private void readSelect() { String props = parser.nextWord(); if (props.startsWith("(")) { props = props.substring(1, props.length() - 1); OrmQueryProperties base = new OrmQueryProperties(null, props); detail.setBase(base); parser.nextWord(); } else { process(); } }
private void readOrderBy() { // read the by parser.nextWord(); StringBuilder sb = new StringBuilder(); while (parser.nextWord() != null) { if (parser.isMatch("limit")) { break; } else { String w = parser.getWord(); if (!w.startsWith("(")) { sb.append(" "); } sb.append(w); } } rawOrderBy = sb.toString().trim(); if (!parser.isFinished()) { readLimit(); } }
private void process() { if (isFetch()) { OrmQueryProperties props = readFindFetch(); detail.putFetchPath(props); } else if (parser.isMatch("where")) { readWhere(); } else if (parser.isMatch("order", "by")) { readOrderBy(); } else if (parser.isMatch("limit")) { readLimit(); } else { throw new PersistenceException("Query expected 'fetch', 'where','order by' or 'limit' keyword but got [" + parser.getWord() + "] \r " + parser.getOql()); } }
private void processInitial() { if (parser.isMatch("find")) { OrmQueryProperties props = readFindFetch(); detail.setBase(props); } else { process(); } while (!parser.isFinished()) { process(); } }
private void readWhere() { int nextMode = 0; StringBuilder sb = new StringBuilder(); while ((parser.nextWord()) != null) { if (parser.isMatch("order", "by")) { nextMode = 1; break; } else if (parser.isMatch("limit")) { nextMode = 2; break; } else { sb.append(" ").append(parser.getWord()); } } String whereClause = sb.toString().trim(); if (whereClause.length() > 0) { rawWhereClause = whereClause; } if (nextMode == 1) { readOrderBy(); } else if (nextMode == 2) { readLimit(); } }
private boolean isFindFetchEnd() { if (isFetch()) { return true; } if (parser.isMatch("where")) { return true; } if (parser.isMatch("order", "by")) { return true; } return false; } }
private OrmQueryProperties readFindFetch() { boolean readAlias = false; String props = null; String path = parser.nextWord(); String token = null; while ((token = parser.nextWord()) != null) { if (!readAlias && parser.isMatch("as")) { // next token is alias parser.nextWord(); readAlias = true; } else if ('(' == token.charAt(0)) { props = token; parser.nextWord(); break; } else if (isFindFetchEnd()) { break; } else if (!readAlias) { readAlias = true; } else { throw new PersistenceException("Expected (props) or new 'fetch' 'where' but got " + token); } } if (props != null) { props = props.substring(1, props.length() - 1); } return new OrmQueryProperties(path, props); }
private void readOrderBy() { // read the by parser.nextWord(); StringBuilder sb = new StringBuilder(); while (parser.nextWord() != null) { if (parser.isMatch("limit")) { break; } else { String w = parser.getWord(); if (!w.startsWith("(")) { sb.append(" "); } sb.append(w); } } rawOrderBy = sb.toString().trim(); if (!parser.isFinished()) { readLimit(); } }
public DefaultOrmQuery<T> setQuery(String queryString) throws PersistenceException { this.query = queryString; OrmQueryDetailParser parser = new OrmQueryDetailParser(queryString); parser.parse(); parser.assign(this); return this; }
private boolean isFindFetchEnd() { return isFetch() || parser.isMatch("where") || parser.isMatch("order", "by"); } }