/*
   * (non-Javadoc)
   * @see benchmark.testdriver.ServerConnection#executeValidation(benchmark.testdriver.Query, byte, java.lang.String[])
   * Gather information about the result a query returns.
   */
  public QueryResult executeValidation(Query query, byte queryType) {
    String queryString = query.getQueryString();
    String parametrizedQueryString = query.getParametrizedQueryString();
    String encodedParamString = query.getEncodedParamString();
    int queryNr = query.getNr();
    String[] rowNames = query.getRowNames();
    boolean sorted = queryString.toLowerCase().contains("order by");
    QueryResult queryResult = null;
    NetQuery qe;
    if (query.isParametrized)
      qe =
          new NetQuery(
              serverURL, parametrizedQueryString, encodedParamString, queryType, defaultGraph, 0);
    else qe = new NetQuery(serverURL, queryString, "", queryType, defaultGraph, 0);
    InputStream is = qe.exec();
    Document doc = getXMLDocument(is);
    XMLOutputter outputter = new XMLOutputter();
    logResultInfo(query, outputter.outputString(doc));

    if (queryType == Query.SELECT_TYPE)
      queryResult = gatherResultInfoForSelectQuery(queryString, queryNr, sorted, doc, rowNames);

    if (queryResult != null) queryResult.setRun(query.getQueryMix().getRun());
    return queryResult;
  }
  public void executeQuery(CompiledQuery query, CompiledQueryMix queryMix) {
    double timeInSeconds;

    String queryString = query.getQueryString();
    String parametrizedQueryString = query.getParametrizedQueryString();
    String encodedParamString = query.getEncodedParamString();
    byte queryType = query.getQueryType();
    int queryNr = query.getNr();
    NetQuery qe;
    if (query.source.isParametrized)
      qe =
          new NetQuery(
              serverURL,
              parametrizedQueryString,
              encodedParamString,
              queryType,
              defaultGraph,
              timeout);
    else qe = new NetQuery(serverURL, queryString, "", queryType, defaultGraph, timeout);
    int queryMixRun = queryMix.getRun() + 1;

    InputStream is = qe.exec();

    if (is == null) { // then Timeout!
      double t = this.timeout / 1000.0;
      System.out.println("Query " + queryNr + ": " + t + " seconds timeout!");
      queryMix.reportTimeOut(); // inc. timeout counter
      queryMix.setCurrent(0, t);
      qe.close();
      return;
    }

    int resultCount = 0;

    try {
      // Write XML result into result
      if (queryType == Query.SELECT_TYPE) resultCount = countResults(is);
      else resultCount = countBytes(is);

      timeInSeconds = qe.getExecutionTimeInSeconds();
    } catch (SocketTimeoutException e) {
      double t = this.timeout / 1000.0;
      System.out.println("Query " + queryNr + ": " + t + " seconds timeout!");
      queryMix.reportTimeOut(); // inc. timeout counter
      queryMix.setCurrent(0, t);
      qe.close();
      return;
    }

    if (logger.isEnabledFor(Level.ALL) && queryMixRun > 0)
      logResultInfo(queryNr, queryMixRun, timeInSeconds, queryString, queryType, resultCount);

    queryMix.setCurrent(resultCount, timeInSeconds);
    qe.close();
  }