@Test public void filterStatementWhenStatementContainsOrderByAndGroupBy() { assertEquals("select count(doc.fullName) from XWikiDocument doc group by doc.web", this.filter.filterStatement("select doc.fullName from XWikiDocument doc order by doc.name group by doc.web", Query.HQL) ); }
@Override public String filterStatement(String statement, String language) { String result = statement.trim(); String lcOriginal = result.toLowerCase(); String original = result; if (Query.HQL.equals(language) && isFilterable(lcOriginal)) { String distinct = getSelectColumns(statement).contains(DISTINCT_FULLNAME_COLUMN) ? "distinct " : ""; result = "select count(" + distinct + "doc.fullName) " + result.substring(lcOriginal.indexOf("from xwikidocument")); int oidx = StringUtils.indexOfIgnoreCase(result, "order by "); int gidx = StringUtils.indexOfIgnoreCase(result, "group by "); if (oidx > -1) { if (gidx > -1 && gidx > oidx) { result = result.substring(0, oidx) + result.substring(gidx); } else { result = result.substring(0, oidx); } } } if (!original.equals(result)) { logger.debug("Query [{}] has been transformed into [{}]", original, result); } return result; }
CountDocumentFilter extends AbstractQueryFilter { @Override public String filterStatement(String statement, String language) { String result = statement.trim(); String lcOriginal = result.toLowerCase(); String original = result; if (Query.HQL.equals(language) && isFilterable(lcOriginal)) { String distinct = getSelectColumns(statement).contains(DISTINCT_FULLNAME_COLUMN) ? "distinct " : ""; result = "select count(" + distinct + "doc.fullName) " + result.substring(lcOriginal.indexOf("from xwikidocument")); int oidx = StringUtils.indexOfIgnoreCase(result, "order by "); int gidx = StringUtils.indexOfIgnoreCase(result, "group by "); if (oidx > -1) { if (gidx > -1 && gidx > oidx) { result = result.substring(0, oidx) + result.substring(gidx); } else { result = result.substring(0, oidx); } } } if (!original.equals(result)) { logger.debug("Query [{}] has been transformed into [{}]", original, result); } return result; } }
CountDocumentFilter extends AbstractQueryFilter { @Override public String filterStatement(String statement, String language) { String result = statement.trim(); String lcOriginal = result.toLowerCase(); String original = result; if (Query.HQL.equals(language) && isFilterable(lcOriginal)) { String distinct = getSelectColumns(statement).contains(DISTINCT_FULLNAME_COLUMN) ? "distinct " : ""; result = "select count(" + distinct + "doc.fullName) " + result.substring(lcOriginal.indexOf("from xwikidocument")); int oidx = StringUtils.indexOfIgnoreCase(result, "order by "); int gidx = StringUtils.indexOfIgnoreCase(result, "group by "); if (oidx > -1) { if (gidx > -1 && gidx > oidx) { result = result.substring(0, oidx) + result.substring(gidx); } else { result = result.substring(0, oidx); } } } if (!original.equals(result)) { logger.debug("Query [{}] has been transformed into [{}]", original, result); } return result; }  }
CountDocumentFilter extends AbstractQueryFilter { @Override public String filterStatement(String statement, String language) { String result = statement.trim(); String lcOriginal = result.toLowerCase(); String original = result; if (Query.HQL.equals(language) && isFilterable(lcOriginal)) { String distinct = getSelectColumns(statement).contains(DISTINCT_FULLNAME_COLUMN) ? "distinct " : ""; result = "select count(" + distinct + "doc.fullName) " + result.substring(lcOriginal.indexOf("from xwikidocument")); int oidx = StringUtils.indexOfIgnoreCase(result, "order by "); int gidx = StringUtils.indexOfIgnoreCase(result, "group by "); if (oidx > -1) { if (gidx > -1 && gidx > oidx) { result = result.substring(0, oidx) + result.substring(gidx); } else { result = result.substring(0, oidx); } } } if (!original.equals(result)) { logger.debug("Query [{}] has been transformed into [{}]", original, result); } return result; }  @Override String filterStatement(String statement, String language); @Override List filterResults(List results); }
CountDocumentFilter extends AbstractQueryFilter { @Override public String filterStatement(String statement, String language) { String result = statement.trim(); String lcOriginal = result.toLowerCase(); String original = result; if (Query.HQL.equals(language) && isFilterable(lcOriginal)) { String distinct = getSelectColumns(statement).contains(DISTINCT_FULLNAME_COLUMN) ? "distinct " : ""; result = "select count(" + distinct + "doc.fullName) " + result.substring(lcOriginal.indexOf("from xwikidocument")); int oidx = StringUtils.indexOfIgnoreCase(result, "order by "); int gidx = StringUtils.indexOfIgnoreCase(result, "group by "); if (oidx > -1) { if (gidx > -1 && gidx > oidx) { result = result.substring(0, oidx) + result.substring(gidx); } else { result = result.substring(0, oidx); } } } if (!original.equals(result)) { logger.debug("Query [{}] has been transformed into [{}]", original, result); } return result; }  @Override String filterStatement(String statement, String language); @Override List filterResults(List results);  }