Example #1
0
  /** Execute query */
  private ResultSet executeQuery(Session session, Query query, int offset, int limit)
      throws RepositoryException {
    log.debug("executeQuery({}, {}, {}, {})", new Object[] {session, query, offset, limit});
    ResultSet rs = new ResultSet();

    try {
      ArrayList<QueryResult> al = new ArrayList<QueryResult>();

      // http://n4.nabble.com/Query-performance-for-large-query-results-td531360.html
      ((QueryImpl) query).setLimit(limit);
      ((QueryImpl) query).setOffset(offset);
      QueryResultImpl result = (QueryResultImpl) query.execute();
      RowIterator rit = result.getRows();
      rs.setTotal(result.getTotalSize());

      while (rit.hasNext()) {
        Row row = rit.nextRow();
        QueryResult qr = queryRowResultDigester(session, row);
        al.add(qr);
      }

      rs.setResults(al);
    } catch (javax.jcr.RepositoryException e) {
      log.error(e.getMessage(), e);
      throw new RepositoryException(e.getMessage(), e);
    }

    log.debug("executeQuery: {}", rs);
    return rs;
  }
Example #2
0
  /** Execute simple query */
  private ResultSet executeSimpleQuery(Session session, String statement, int offset, int limit)
      throws RepositoryException {
    log.debug(
        "executeSimpleQuery({}, {}, {}, {})", new Object[] {session, statement, offset, limit});
    ResultSet rs = new ResultSet();

    if (statement != null && !statement.equals("")) {
      if (!statement.contains("path:")) {
        statement = "path:\"/" + Repository.ROOT + "\" " + statement;
      }

      if (!statement.contains("limit:") && limit < Config.MAX_SEARCH_RESULTS) {
        StringBuilder sb = new StringBuilder();
        sb.append("limit:").append(offset).append("..").append(offset + limit);
        statement = statement.concat(" ").concat(sb.toString());
      }

      try {
        ArrayList<QueryResult> al = new ArrayList<QueryResult>();
        log.info("Statement: {}", statement);
        RowIterator rit = GQL.execute(statement, session);
        rs.setTotal(rit.getSize());

        while (rit.hasNext()) {
          Row row = rit.nextRow();
          QueryResult qr = queryRowResultDigester(session, row);
          al.add(qr);
        }

        rs.setResults(al);
      } catch (javax.jcr.RepositoryException e) {
        log.error(e.getMessage(), e);
        throw new RepositoryException(e.getMessage(), e);
      }
    }

    log.debug("executeSimpleQuery: {}", rs);
    return rs;
  }