예제 #1
0
파일: Rows.c 프로젝트: hscale/php-driver
PHP_METHOD(Rows, nextPageAsync)
{
  cassandra_rows* self = NULL;
  cassandra_session* session = NULL;
  CassFuture* future = NULL;
  cassandra_future_rows* future_rows = NULL;

  if (zend_parse_parameters_none() == FAILURE)
    return;

  self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (!(self->result && cass_result_has_more_pages(self->result))) {
    object_init_ex(return_value, cassandra_future_value_ce);
    return;
  }

  ASSERT_SUCCESS(cass_statement_set_paging_state(self->statement->statement, self->result));

  session = (cassandra_session*) zend_object_store_get_object(self->session TSRMLS_CC);
  future = cass_session_execute(session->session, self->statement->statement);

  object_init_ex(return_value, cassandra_future_rows_ce);
  future_rows = (cassandra_future_rows*) zend_object_store_get_object(return_value TSRMLS_CC);

  Z_ADDREF_P(self->session);
  future_rows->session   = self->session;
  future_rows->statement = php_cassandra_add_ref(self->statement);
  future_rows->future    = future;
}
예제 #2
0
static int
cassandra_results_stream_end_of_stream(void* context)
{

    cassandra_results_stream* scontext;
    scontext = (cassandra_results_stream*)context;

    if (scontext->at_end) {

	if (scontext->more_pages) {

	    CassError rc;
	    rc = cass_statement_set_paging_state(scontext->stmt,
						 scontext->result);
	    if (rc != CASS_OK) {
		fprintf(stderr, "Cassandra: %s\n", cass_error_desc(rc));
		return -1;
	    }
	    
	    cass_result_free(scontext->result);
	    scontext->result = 0;

	    CassFuture* future =
		cass_session_execute(scontext->cassandra_context->session,
				     scontext->stmt);

	    rc = cass_future_error_code(future);
	    
	    if (rc != CASS_OK) {
		fprintf(stderr, "Cassandra: %s\n", cass_error_desc(rc));
		const char* msg;
		size_t msg_len;
		cass_future_error_message(future, &msg, &msg_len);
		fprintf(stderr, "Cassandra: %*s\n", msg_len, msg);
		cass_future_free(future);
		return -1;
	    }

	    scontext->result = cass_future_get_result(future);

	    cass_future_free(future);

	    scontext->iter = cass_iterator_from_result(scontext->result);

	    scontext->more_pages = cass_result_has_more_pages(scontext->result);

	    scontext->at_end = !cass_iterator_next(scontext->iter);

	}
	
    }

    return (scontext->at_end);

}
예제 #3
0
파일: Rows.c 프로젝트: hscale/php-driver
PHP_METHOD(Rows, nextPage)
{
  zval* timeout = NULL;
  cassandra_session* session = NULL;
  CassFuture* future = NULL;
  const CassResult* result = NULL;
  cassandra_rows* rows = NULL;

  cassandra_rows* self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (!(self->result && cass_result_has_more_pages(self->result)))
    return;

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &timeout) == FAILURE) {
    return;
  }

  ASSERT_SUCCESS(cass_statement_set_paging_state(self->statement->statement, self->result));

  session = (cassandra_session*) zend_object_store_get_object(self->session TSRMLS_CC);
  future = cass_session_execute(session->session, self->statement->statement);

  if (php_cassandra_future_wait_timed(future, timeout TSRMLS_CC) == FAILURE) {
    return;
  }

  if (php_cassandra_future_is_error(future TSRMLS_CC) == FAILURE) {
    return;
  }

  result = cass_future_get_result(future);

  if (!result) {
    zend_throw_exception_ex(cassandra_runtime_exception_ce, 0 TSRMLS_CC,
                            "Future doesn't contain a result.");
    return;
  }

  object_init_ex(return_value, cassandra_rows_ce);
  rows = (cassandra_rows*) zend_object_store_get_object(return_value TSRMLS_CC);

  if (php_cassandra_get_result(result, &rows->rows TSRMLS_CC) == FAILURE) {
    cass_result_free(result);
    zval_dtor(return_value);
    return;
  }

  Z_ADDREF_P(self->session);
  rows->statement = php_cassandra_add_ref(self->statement);
  rows->session   = self->session;
  rows->result    = result;
}
예제 #4
0
파일: Rows.c 프로젝트: NSRagu/php-driver
PHP_METHOD(Rows, nextPageAsync)
{
  cassandra_rows* self = NULL;
  cassandra_session* session = NULL;
  CassFuture* future = NULL;
  cassandra_future_rows* future_rows = NULL;
  cassandra_future_value* future_value;

  if (zend_parse_parameters_none() == FAILURE)
    return;

  self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (self->future_next_page) {
    RETURN_ZVAL(self->future_next_page, 1, 0);
  }

  if (self->next_page) {
    Z_ADDREF_P(self->next_page);
    object_init_ex(self->future_next_page, cassandra_future_value_ce);
    future_value = (cassandra_future_value*) zend_object_store_get_object(self->future_next_page TSRMLS_CC);
    future_value->value = self->next_page;
    RETURN_ZVAL(self->future_next_page, 1, 0);
  }

  if (self->result == NULL) {
    object_init_ex(return_value, cassandra_future_value_ce);
    return;
  }

  ASSERT_SUCCESS(cass_statement_set_paging_state((CassStatement*) self->statement->data, self->result));

  session = (cassandra_session*) zend_object_store_get_object(self->session TSRMLS_CC);
  future = cass_session_execute(session->session, (CassStatement*) self->statement->data);

  object_init_ex(self->future_next_page, cassandra_future_rows_ce);
  future_rows = (cassandra_future_rows*) zend_object_store_get_object(self->future_next_page TSRMLS_CC);

  Z_ADDREF_P(self->session);
  future_rows->session   = self->session;
  future_rows->statement = php_cassandra_add_ref(self->statement);
  future_rows->future    = future;

  php_cassandra_rows_clear(self);
  RETURN_ZVAL(self->future_next_page, 1, 0);
}
void CassDriver::Retrieve(
    std::tr1::function<void(bool success, Wrapper* data)> cob,
    const std::string& receiver_id, Wrapper* data_wrapper) {
  CassStatement* statement = cass_prepared_bind(select_prepared_);
  cass_statement_bind_string(statement, 0,
                             cass_string_init(receiver_id.c_str()));
  cass_statement_set_paging_size(statement, FLAGS_page_size);

  CassFuture* future = cass_session_execute(session_, statement);
  auto retrieve_cb = [](CassFuture* future, void* data) {
    CassError rc = cass_future_error_code(future);
    Wrapper* wrapper = (Wrapper*)data;
    if (rc == CASS_OK) {
      const CassResult* result = cass_future_get_result(future);
      if (cass_result_row_count(result)) {
        CassIterator* iterator = cass_iterator_from_result(result);
        CassString cass_receiver, cass_time, cass_msg_id,
                   cass_group_id, cass_msg, cass_sender;
        while (cass_iterator_next(iterator)) {
          const CassRow* row = cass_iterator_get_row(iterator);
          cass_value_get_string(cass_row_get_column(row, 0), &cass_receiver);
          cass_value_get_string(cass_row_get_column(row, 1), &cass_time);
          cass_value_get_string(cass_row_get_column(row, 2), &cass_msg_id);
          cass_value_get_string(cass_row_get_column(row, 3), &cass_group_id);
          cass_value_get_string(cass_row_get_column(row, 4), &cass_msg);
          cass_value_get_string(cass_row_get_column(row, 5), &cass_sender);
            
          std::string receiver(cass_receiver.data, cass_receiver.length);
          std::string time(cass_time.data, cass_time.length);
          std::string msg_id(cass_msg_id.data, cass_msg_id.length);
          std::string group_id(cass_group_id.data, cass_group_id.length);
          std::string msg(cass_msg.data, cass_msg.length);
          std::string sender(cass_sender.data, cass_sender.length);

          boost::shared_ptr<Message> message(new Message());
          message->__set_receiver_id(receiver);
          message->__set_timestamp(time);
          message->__set_msg_id(msg_id);
          message->__set_group_id(group_id);
          message->__set_msg(msg);
          message->__set_sender_id(sender);
          wrapper->pmsgs->push_back(message);
        }
        cass_bool_t has_more_pages = cass_result_has_more_pages(result);
        if (has_more_pages) {
          cass_statement_set_paging_state(wrapper->statement, result);
          (wrapper->func)();
        } else {
          cass_statement_free(wrapper->statement);
          CassStatement* statement =
              cass_prepared_bind(wrapper->this_obj->delete_prepared_);
          cass_statement_bind_string(statement, 0, cass_receiver);
          CassFuture* delete_future =
              cass_session_execute(wrapper->this_obj->session_, statement);
          cass_future_free(delete_future);
          cass_statement_free(statement);

          (wrapper->cob)(true, wrapper);
        }
        cass_iterator_free(iterator);
      } else {
        cass_statement_free(wrapper->statement);
        (wrapper->cob)(true, wrapper);
      }
      cass_result_free(result);
    } else {
      cass_statement_free(wrapper->statement);
      wrapper->this_obj->PrintError(future);
      (wrapper->cob)(false, wrapper);
    }
  };

  data_wrapper->this_obj = this;
  data_wrapper->cob = cob;
  data_wrapper->statement = statement;
  data_wrapper->func = [=]() {
    CassFuture* future = cass_session_execute(session_, statement);
    cass_future_set_callback(future, retrieve_cb, data_wrapper);
    cass_future_free(future);
  };

  cass_future_set_callback(future, retrieve_cb, data_wrapper);
  cass_future_free(future);
}
예제 #6
0
파일: Rows.c 프로젝트: NSRagu/php-driver
PHP_METHOD(Rows, nextPage)
{
  zval* timeout = NULL;
  cassandra_session* session = NULL;
  CassFuture* future = NULL;
  const CassResult* result = NULL;
  cassandra_rows* rows = NULL;
  cassandra_future_rows* future_rows = NULL;

  cassandra_rows* self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (self->next_page) {
    RETURN_ZVAL(self->next_page, 1, 0);
  }

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &timeout) == FAILURE) {
    return;
  }

  if (self->future_next_page) {
    if (!instanceof_function(Z_OBJCE_P(self->future_next_page),
                             cassandra_future_rows_ce TSRMLS_CC)) {
      zend_throw_exception_ex(cassandra_runtime_exception_ce, 0 TSRMLS_CC,
                              "Unexpected future instance.");
      return;
    }

    future_rows = (cassandra_future_rows*) zend_object_store_get_object(self->future_next_page TSRMLS_CC);

    if (php_cassandra_future_wait_timed(future_rows->future, timeout TSRMLS_CC) == FAILURE) {
      return;
    }

    if (php_cassandra_future_is_error(future_rows->future TSRMLS_CC) == FAILURE) {
      return;
    }

    result = cass_future_get_result(future_rows->future);
  } else {
    if (self->result == NULL) {
      return;
    }

    ASSERT_SUCCESS(cass_statement_set_paging_state((CassStatement*) self->statement->data, self->result));

    session = (cassandra_session*) zend_object_store_get_object(self->session TSRMLS_CC);
    future = cass_session_execute(session->session, (CassStatement*) self->statement->data);

    if (php_cassandra_future_wait_timed(future, timeout TSRMLS_CC) == FAILURE) {
      return;
    }

    if (php_cassandra_future_is_error(future TSRMLS_CC) == FAILURE) {
      return;
    }

    result = cass_future_get_result(future);
    cass_future_free(future);
  }

  if (!result) {
    zend_throw_exception_ex(cassandra_runtime_exception_ce, 0 TSRMLS_CC,
                            "Future doesn't contain a result.");
    return;
  }

  MAKE_STD_ZVAL(self->next_page);
  object_init_ex(self->next_page, cassandra_rows_ce);
  rows = (cassandra_rows*) zend_object_store_get_object(self->next_page TSRMLS_CC);

  if (php_cassandra_get_result(result, &rows->rows TSRMLS_CC) == FAILURE) {
    cass_result_free(result);
    zval_dtor(self->next_page);
    self->next_page = NULL;
    return;
  }

  if (self->future_next_page) {
    zval_ptr_dtor(&self->future_next_page);
    self->future_next_page = NULL;
  }

  if (cass_result_has_more_pages(result)) {
    Z_ADDREF_P(self->session);
    rows->statement = php_cassandra_add_ref(self->statement);
    rows->session   = self->session;
    rows->result    = result;
  } else {
    cass_result_free(result);
  }

  php_cassandra_rows_clear(self);
  RETURN_ZVAL(self->next_page, 1, 0);
}