예제 #1
0
  public Message.Response execute(QueryState state) {
    try {
      if (options.getPageSize() == 0) throw new ProtocolException("The page size cannot be 0");

      UUID tracingId = null;
      if (isTracingRequested()) {
        tracingId = UUIDGen.getTimeUUID();
        state.prepareTracingSession(tracingId);
      }

      if (state.traceNextQuery()) {
        state.createTracingSession();

        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        builder.put("query", query);
        if (options.getPageSize() > 0)
          builder.put("page_size", Integer.toString(options.getPageSize()));

        Tracing.instance.begin("Execute CQL3 query", builder.build());
      }

      Message.Response response =
          state.getClientState().getCQLQueryHandler().process(query, state, options);
      if (options.skipMetadata() && response instanceof ResultMessage.Rows)
        ((ResultMessage.Rows) response).result.metadata.setSkipMetadata();

      if (tracingId != null) response.setTracingId(tracingId);

      return response;
    } catch (Exception e) {
      if (!((e instanceof RequestValidationException) || (e instanceof RequestExecutionException)))
        logger.error("Unexpected error during query", e);
      return ErrorMessage.fromException(e);
    } finally {
      Tracing.instance.stopSession();
    }
  }
예제 #2
0
  public Message.Response execute(QueryState state) {
    try {
      UUID tracingId = null;
      if (isTracingRequested()) {
        tracingId = UUIDGen.getTimeUUID();
        state.prepareTracingSession(tracingId);
      }

      if (state.traceNextQuery()) {
        state.createTracingSession();
        Tracing.instance().begin("Preparing CQL3 query", ImmutableMap.of("query", query));
      }

      Message.Response response = QueryProcessor.prepare(query, state.getClientState(), false);

      if (tracingId != null) response.setTracingId(tracingId);

      return response;
    } catch (Exception e) {
      return ErrorMessage.fromException(e);
    } finally {
      Tracing.instance().stopSession();
    }
  }