コード例 #1
0
 private void executeQuery(JsonGenerator jg, Query query) throws IOException {
   query.setStart(System.currentTimeMillis());
   try (Transaction ignored = database.beginTx();
       Result result = database.execute(query.toCypher())) {
     query.setEnd(System.currentTimeMillis());
     jg.writeNumberField("duration", query.getDuration());
     if (!query.isCountQuery()) jg.writeArrayFieldStart(query.getResultHeader());
     while (result.hasNext()) {
       Map<String, Object> row = result.next();
       if (!query.isCountQuery()) jg.writeStartObject();
       for (Entry<String, Object> column : row.entrySet()) {
         writeField(column, jg);
       }
       if (!query.isCountQuery()) jg.writeEndObject();
     }
     if (!query.isCountQuery()) jg.writeEndArray();
   }
 }
コード例 #2
0
  private void writeQueryDetails(JsonGenerator jg, Query query) throws IOException {
    if (query.getView() != 20) {
      jg.writeStringField("id", query.getId());
      System.out.print("{ id: " + query.getId());
      jg.writeStringField("cql", query.toCQL());
      System.out.print(", cql: " + query.toCQL());
      if (query.toJSON() != null) jg.writeStringField("json", query.toJSON().toString());
      jg.writeStringField("within", query.getWithin());
      System.out.print(", within: " + query.getWithin());
      jg.writeNumberField("number", query.getLimit());
      System.out.print(", number: " + String.valueOf(query.getLimit()));
      jg.writeNumberField("offset", query.getSkip());
      System.out.print(", offset: " + String.valueOf(query.getSkip()));
    }
    jg.writeStringField("filter", query.getFilter());
    System.out.print(", filter: " + query.getFilter());
    jg.writeNumberField("view", query.getView());
    System.out.print(", view: " + String.valueOf(query.getView()));

    String group = query.getGroup();
    if (group != null && group.length() > 0) {
      jg.writeStringField("group", group);
      System.out.print(", group: " + group);
    }

    if (query.getView() != 20) {
      String sort = query.getSort();
      if (sort != null && sort.length() > 0) {
        jg.writeStringField("sort", sort);
        System.out.print(", sort: " + sort);
      }

      String order = query.getOrder();
      if (order != null && order.length() > 0) {
        jg.writeStringField("order", order);
        System.out.print(", order: " + order);
      }

      String docPid = query.getDocpid();
      if (docPid != null && docPid.length() > 0) {
        jg.writeStringField("docpid", docPid);
        System.out.print(", docpid: " + docPid);
      }
      System.out.print(", count: " + String.valueOf(query.isCountQuery()) + " }");
      System.out.println("");
    }

    jg.writeStringField("cypher", query.toCypher());
    jg.flush();
  }