Class: Ilios::Cassandra::Session

Inherits:
Object
  • Object
show all
Defined in:
ext/ilios/ilios.c

Instance Method Summary collapse

Instance Method Details

#execute(statement) ⇒ Cassandra::Result

Executes a given statement.

Parameters:

Returns:

Raises:

  • (Cassandra::ExecutionError)

    If there is something wrong with the session.

  • (TypeError)

    If the invalid object is given.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'ext/ilios/session.c', line 105

static VALUE session_execute(VALUE self, VALUE statement)
{
    CassandraSession *cassandra_session;
    CassandraStatement *cassandra_statement;
    CassandraResult *cassandra_result;
    CassFuture *result_future;
    VALUE cassandra_result_obj;

    GET_SESSION(self, cassandra_session);
    GET_STATEMENT(statement, cassandra_statement);

    result_future = nogvl_session_execute(cassandra_session->session, cassandra_statement->statement);

    cassandra_result_obj = CREATE_RESULT(cassandra_result);
    cassandra_result->future = result_future;
    cassandra_result->statement_obj = statement;

    result_await(cassandra_result);
    return cassandra_result_obj;
}

#execute_async(statement) ⇒ Cassandra::Future

Executes a given statement asynchronously and returns a future result.

Parameters:

Returns:

Raises:

  • (TypeError)

    If the invalid object is given.



84
85
86
87
88
89
90
91
92
93
94
95
# File 'ext/ilios/session.c', line 84

static VALUE session_execute_async(VALUE self, VALUE statement)
{
    CassandraSession *cassandra_session;
    CassandraStatement *cassandra_statement;
    CassFuture *result_future;

    GET_SESSION(self, cassandra_session);
    GET_STATEMENT(statement, cassandra_statement);

    result_future = nogvl_session_execute(cassandra_session->session, cassandra_statement->statement);
    return future_create(result_future, self, execute_async);
}

#prepare(query) ⇒ Cassandra::Statement

Prepares a given query.

Parameters:

  • query (String)

    A query to prepare.

Returns:

Raises:

  • (Cassandra::ExecutionError)

    If the query is invalid or there is something wrong with the session.

  • (TypeError)

    If the query is not a string.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/ilios/session.c', line 46

static VALUE session_prepare(VALUE self, VALUE query)
{
    CassandraSession *cassandra_session;
    CassandraStatement *cassandra_statement;
    CassFuture *prepare_future;
    VALUE cassandra_statement_obj;

    GET_SESSION(self, cassandra_session);

    prepare_future = nogvl_session_prepare(cassandra_session->session, query);
    nogvl_future_wait(prepare_future);

    if (cass_future_error_code(prepare_future) != CASS_OK) {
        char error[4096] = { 0 };

        strncpy(error, cass_error_desc(cass_future_error_code(prepare_future)), sizeof(error) - 1);
        cass_future_free(prepare_future);
        rb_raise(eExecutionError, "Unable to prepare query: %s", error);
    }

    cassandra_statement_obj = CREATE_STATEMENT(cassandra_statement);

    cassandra_statement->prepared = cass_future_get_prepared(prepare_future);
    cassandra_statement->statement = cass_prepared_bind(cassandra_statement->prepared);
    cassandra_statement->session_obj = self;
    cass_future_free(prepare_future);

    statement_default_config(cassandra_statement);
    return cassandra_statement_obj;
}

#prepare_async(query) ⇒ Cassandra::Future

Prepares a given query asynchronously and returns a future prepared statement.

Parameters:

  • query (String)

    A query to prepare.

Returns:

Raises:

  • (TypeError)

    If the query is not a string.



27
28
29
30
31
32
33
34
35
36
# File 'ext/ilios/session.c', line 27

static VALUE session_prepare_async(VALUE self, VALUE query)
{
    CassandraSession *cassandra_session;
    CassFuture *prepare_future;

    GET_SESSION(self, cassandra_session);

    prepare_future = nogvl_session_prepare(cassandra_session->session, query);
    return future_create(prepare_future, self, prepare_async);
}