Exemple #1
0
    public synchronized QueryExplanation explain() throws BeeswaxException {
      assertState(QueryState.INITIALIZED);
      // By manipulating the query, this will make errors harder to find.
      query.query = "EXPLAIN " + query.query;
      checkedCompile();

      int ret;
      if (0 != (ret = driver.execute())) {
        throwException(new RuntimeException("Failed to execute: EXPLAIN " + ret));
      }
      StringBuilder sb = new StringBuilder();
      ArrayList<String> v = new ArrayList<String>();
      try {
        while (driver.getResults(v)) {
          for (String s : v) {
            sb.append(s);
            sb.append("\n");
          }
          v.clear();
        }
      } catch (IOException e) {
        throwException(new RuntimeException(e));
      } finally {
        // Don't let folks re-use the state object.
        state = QueryState.FINISHED;
      }
      return new QueryExplanation(sb.toString());
    }
Exemple #2
0
 /**
  * Executes query. Updates state. (QueryState variable can be polled.)
  *
  * @throws BeeswaxException
  */
 public void execute() throws BeeswaxException {
   synchronized (this) {
     assertState(QueryState.COMPILED);
     state = QueryState.RUNNING;
   }
   int ret = driver.execute();
   try {
     synchronized (this) {
       assertState(QueryState.RUNNING);
       if (ret == 0) {
         state = QueryState.FINISHED;
       } else {
         throwException(
             new BeeswaxException(
                 "Driver returned: " + ret + ".  Errors: " + getErrorStreamAsString(),
                 logContext.getName(),
                 this.handle));
       }
     }
   } finally {
     notifyDone(this);
   }
 }