Пример #1
0
    public ResultSetFuture executeQuery(Message.Request msg, Query query) {
      if (query.isTracing()) msg.setTracingRequested();

      ResultSetFuture future = new ResultSetFuture(this, msg);
      execute(future.callback, query);
      return future;
    }
Пример #2
0
  /**
   * Executes the provided query asynchronously.
   *
   * <p>This method does not block. It returns as soon as the query has been passed to the
   * underlying network stack. In particular, returning from this method does not guarantee that the
   * query is valid or has even been submitted to a live node. Any exception pertaining to the
   * failure of the query will be thrown when accessing the {@link ResultSetFuture}.
   *
   * <p>Note that for queries that doesn't return a result (INSERT, UPDATE and DELETE), you will
   * need to access the ResultSetFuture (that is call one of its get method to make sure the query
   * was successful.
   *
   * @param query the CQL query to execute (that can be either a {@code Statement} or a {@code
   *     BoundStatement}). If it is a {@code BoundStatement}, all variables must have been bound
   *     (the statement must be ready).
   * @return a future on the result of the query.
   * @throws IllegalStateException if {@code query} is a {@code BoundStatement} but {@code
   *     !query.isReady()}.
   */
  public ResultSetFuture executeAsync(Query query) {

    if (query instanceof Statement) {
      return manager.executeQuery(
          new QueryMessage(
              ((Statement) query).getQueryString(),
              ConsistencyLevel.toCassandraCL(query.getConsistencyLevel())),
          query);
    } else {
      assert query instanceof BoundStatement : query;

      BoundStatement bs = (BoundStatement) query;
      return manager.executeQuery(
          new ExecuteMessage(
              bs.statement.id,
              Arrays.asList(bs.values),
              ConsistencyLevel.toCassandraCL(query.getConsistencyLevel())),
          query);
    }
  }
Пример #3
0
  /**
   * Execute the provided query asynchronously.
   *
   * <p>This method does not block. It returns as soon as the query has been successfully sent to a
   * Cassandra node. In particular, returning from this method does not guarantee that the query is
   * valid. Any exception pertaining to the failure of the query will be thrown by the first access
   * to the {@link ResultSet}.
   *
   * <p>Note that for queries that doesn't return a result (INSERT, UPDATE and DELETE), you will
   * need to access the ResultSet (i.e. call any of its method) to make sure the query was
   * successful.
   *
   * @param query the CQL query to execute (that can be either a {@code Statement} or a {@code
   *     BoundStatement}). If it is a {@code BoundStatement}, all variables must have been bound
   *     (the statement must be ready).
   * @return a future on the result of the query.
   * @throws IllegalStateException if {@code query} is a {@code BoundStatement} but {@code
   *     !query.isReady()}.
   */
  public ResultSetFuture executeAsync(Query query) {

    if (query instanceof Statement) {
      return manager.executeQuery(
          new QueryMessage(
              ((Statement) query).getQueryString(),
              ConsistencyLevel.toCassandraCL(query.getConsistencyLevel())),
          query);
    } else {
      assert query instanceof BoundStatement : query;

      BoundStatement bs = (BoundStatement) query;
      if (!bs.isReady())
        throw new IllegalStateException(
            "Some bind variables haven't been bound in the provided statement");

      return manager.executeQuery(
          new ExecuteMessage(
              bs.statement.id,
              Arrays.asList(bs.values),
              ConsistencyLevel.toCassandraCL(query.getConsistencyLevel())),
          query);
    }
  }