libQtCassandra 0.3.2
|
Private data for the QCassandra class. More...
#include <QCassandraPrivate.h>
Public Member Functions | |
QCassandraPrivate (QCassandra *parent) | |
Initialize the private QCassandra object. | |
~QCassandraPrivate () | |
Clean up the object. | |
QString | clusterName () const |
Retrieve the name of the cluster. | |
bool | connect (const QString &host, int port) |
Connect to the Cassandra server. | |
void | contexts () const |
Go through the list of contexts and build a list of such. | |
void | createContext (const QCassandraContext &context) |
Create a new context. | |
void | createTable (const QCassandraTable *table) |
Create a table in the Cassandra server. | |
void | disconnect () |
Disconnect from the Cassandra server. | |
void | dropContext (const QCassandraContext &context) |
Drop an existing context. | |
void | dropTable (const QString &table_name) |
Drop a table from the Cassandra server. | |
int32_t | getCellCount (const QString &table_name, const QByteArray &row_key, const QCassandraColumnPredicate &column_predicate) |
Get a slice of columns from the Cassandra database. | |
void | getColumnSlice (QCassandraTable &table, const QByteArray &row_key, const QCassandraColumnPredicate &column_predicate) |
Get a slice of columns from the Cassandra database. | |
uint32_t | getRowSlices (QCassandraTable &table, const QCassandraRowPredicate &row_predicate) |
This function retrieves a set of rows. | |
void | getValue (const QString &table_name, const QByteArray &row_key, const QByteArray &column_key, QCassandraValue &value) |
Get a value from the Cassandra database. | |
void | insertValue (const QString &table_name, const QByteArray &row_key, const QByteArray &column_key, const QCassandraValue &value) |
Insert a value in the Cassandra database. | |
bool | isConnected () const |
Check whether we're connected. | |
QString | protocolVersion () const |
Retrieve the version of the protocol. | |
void | remove (const QString &table_name, const QByteArray &row_key, const QByteArray &column_key, int64_t timestamp, consistency_level_t consistency_level) |
Remove a cell from the Cassandra database. | |
void | setContext (const QString &context) |
Set the context keyspace name. | |
void | truncateTable (const QCassandraTable *table) |
Truncate a table in the Cassandra server. | |
void | updateContext (const QCassandraContext &context) |
Update an existing context. | |
void | updateTable (const QCassandraTable *table) |
Update a table in the Cassandra server. | |
Private Member Functions | |
QCassandraPrivate (const QCassandraPrivate &) | |
Forbid the copy operator. | |
void | mustBeConnected () const throw (std::runtime_error) |
Check that we're connected. | |
Private Attributes | |
boost::shared_ptr < org::apache::cassandra::CassandraClient > | f_client |
Define a client object. | |
QCassandra * | f_parent |
The pointer to the QCassandra object. | |
boost::shared_ptr < apache::thrift::protocol::TProtocol > | f_protocol |
The protocol between us and the Cassandra server. | |
boost::shared_ptr < apache::thrift::transport::TTransport > | f_socket |
The socket used to connect to the Cassandra server. | |
boost::shared_ptr < apache::thrift::transport::TTransport > | f_transport |
The transport handler. |
This class handles such things as the connection to the Cassandra server and hiding all the thrift definitions.
Definition at line 48 of file QCassandraPrivate.h.
QtCassandra::QCassandraPrivate::QCassandraPrivate | ( | QCassandra * | parent | ) |
This function initialize the QCassandra private object.
[in] | parent | The parent pointer (i.e. QCassandra object) |
Definition at line 117 of file QCassandraPrivate.cpp.
QtCassandra::QCassandraPrivate::~QCassandraPrivate | ( | ) |
This function makes sure we clean up after ourselves.
Definition at line 142 of file QCassandraPrivate.cpp.
References disconnect().
QtCassandra::QCassandraPrivate::QCassandraPrivate | ( | const QCassandraPrivate & | ) | [inline, private] |
By default we forbid the copy operator of the QCassandraPrivate class.
The class includes a network connection and we really do not want to have to clone such a thing.
Note that most of the objects do not define the copy operator since they are QObject's and these are already not copyable.
Definition at line 81 of file QCassandraPrivate.h.
QString QtCassandra::QCassandraPrivate::clusterName | ( | ) | const |
This function sends a message to the Cassandra server to determine the name of the cluster.
Definition at line 262 of file QCassandraPrivate.cpp.
References f_client, and mustBeConnected().
bool QtCassandra::QCassandraPrivate::connect | ( | const QString & | host, |
int | port | ||
) |
This function needs to be called before most of the others.
It is not mentioned on each other function that if the connection is not up then an exception is generated. It will be noted, however, that a connection is required for the function to work.
Note that the main QCassandra object is responsible to test whether the connection valid (isConnected()) and to capture exceptions that should be replaced by a boolean return values and similar approaches.
In the early days expect to see exceptions coming up until we take care of them all.
Note that this function first turns off the existing connection if there is one.
[in] | host | The host of the Cassandra server. |
[in] | port | The port of the Cassandra server. |
Definition at line 173 of file QCassandraPrivate.cpp.
References disconnect(), f_client, f_protocol, f_socket, and f_transport.
void QtCassandra::QCassandraPrivate::contexts | ( | ) | const |
This function creates a list of QCassandraContexts and returns the result.
The function retrieves all the keyspaces from Cassandra, transforms them in QCassandraContext objects, and save the result in a QCassandraContexts map indexed by name and returns that object.
The QCassandra object is responsible for caching the result. The result should not change until we create a new table although if another process on another machine changes the Cassandra cluster structure, it will not be seen until the cache is cleared.
Definition at line 313 of file QCassandraPrivate.cpp.
References QtCassandra::QCassandra::context(), f_client, f_parent, and mustBeConnected().
void QtCassandra::QCassandraPrivate::createContext | ( | const QCassandraContext & | context | ) |
This function creates a new context. Trying to create a context with the name of an existing context will fail. Use the update function instead.
The new context identifier is not returned. I'm not too sure what you could do with it anyway since no function make use of it.
At this time, it looks like you cannot include an array of tables in the context or the create function fails.
[in] | context | The context definition used to create the new context. |
Definition at line 345 of file QCassandraPrivate.cpp.
References f_client, mustBeConnected(), and QtCassandra::QCassandraContext::prepareContextDefinition().
Referenced by QtCassandra::QCassandraContext::create().
void QtCassandra::QCassandraPrivate::createTable | ( | const QCassandraTable * | table | ) |
This function creates a table in the cassandra server transforming a QCassandraTable in a table definition (CfDef) and then calling the system_add_column_family() function.
[in] | table | The table to be created. |
Definition at line 400 of file QCassandraPrivate.cpp.
References f_client, mustBeConnected(), and QtCassandra::QCassandraTable::prepareTableDefinition().
Referenced by QtCassandra::QCassandraContext::createTable().
void QtCassandra::QCassandraPrivate::disconnect | ( | ) |
This function destroys the connection of the Cassandra server.
After calling this function, any other function that require a connection will fail.
Definition at line 211 of file QCassandraPrivate.cpp.
References f_client, f_protocol, f_socket, and f_transport.
Referenced by connect(), and ~QCassandraPrivate().
void QtCassandra::QCassandraPrivate::dropContext | ( | const QCassandraContext & | context | ) |
This function drops an existing context. After this call, do not try to access the context again until you re-create it.
[in] | context | The context to drop from the attached Cassandra cluster. |
Definition at line 384 of file QCassandraPrivate.cpp.
References QtCassandra::QCassandra::clearCurrentContextIf(), QtCassandra::QCassandraContext::contextName(), f_client, f_parent, and mustBeConnected().
Referenced by QtCassandra::QCassandraContext::drop().
void QtCassandra::QCassandraPrivate::dropTable | ( | const QString & | table_name | ) |
This function drops the named table from the cassandra server.
[in] | table_name | The name of the table to be dropped. |
Definition at line 430 of file QCassandraPrivate.cpp.
References f_client, and mustBeConnected().
Referenced by QtCassandra::QCassandraContext::dropTable().
int32_t QtCassandra::QCassandraPrivate::getCellCount | ( | const QString & | table_name, |
const QByteArray & | row_key, | ||
const QCassandraColumnPredicate & | column_predicate | ||
) |
This function retrieves a slice
from the Cassandra database. A slice is an array of column from a specific row.
The result is passed to a QCassndraTable which is expected to save it as a set of rows, cells, and values.
[in] | table_name | Name of the table where the cell counting is processed. |
[in] | row_key | The key used to identify the row. |
[in] | column_predicate | The predicate defining the name of the columns to return. |
Definition at line 578 of file QCassandraPrivate.cpp.
References QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandraColumnPredicate::consistencyLevel(), QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, mustBeConnected(), and QtCassandra::QCassandraColumnPredicate::toPredicate().
Referenced by QtCassandra::QCassandraContext::getCellCount().
void QtCassandra::QCassandraPrivate::getColumnSlice | ( | QCassandraTable & | table, |
const QByteArray & | row_key, | ||
const QCassandraColumnPredicate & | column_predicate | ||
) |
This function retrieves a slice
from the Cassandra database. A slice is an array of column from a specific row.
The result is passed to a QCassndraTable which is expected to save it as a set of rows, cells, and values.
[in,out] | table | The table where values found get inserted. |
[in] | row_key | The key used to identify the row. |
[in] | column_predicate | The predicate defining the name of the columns to return. |
Definition at line 615 of file QCassandraPrivate.cpp.
References QtCassandra::QCassandraTable::assignRow(), QtCassandra::QCassandraValue::assignTimestamp(), QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandraColumnPredicate::consistencyLevel(), QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, mustBeConnected(), QtCassandra::QCassandraValue::setBinaryValue(), QtCassandra::QCassandraValue::setTtl(), QtCassandra::QCassandraTable::tableName(), and QtCassandra::QCassandraColumnPredicate::toPredicate().
Referenced by QtCassandra::QCassandraContext::getColumnSlice().
uint32_t QtCassandra::QCassandraPrivate::getRowSlices | ( | QCassandraTable & | table, |
const QCassandraRowPredicate & | row_predicate | ||
) |
This function retrieves a set of rows filtered by the specified predicate and return the result in the corresponding table.
[in,out] | table | The table requesting the row slices. |
[in] | row_predicate | The predicate to select rows and columns. |
Definition at line 704 of file QCassandraPrivate.cpp.
References QtCassandra::QCassandraTable::assignRow(), QtCassandra::QCassandraValue::assignTimestamp(), QtCassandra::QCassandraRowPredicate::columnPredicate(), QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, mustBeConnected(), QtCassandra::QCassandraValue::setBinaryValue(), QtCassandra::QCassandraValue::setTtl(), QtCassandra::QCassandraTable::tableName(), and QtCassandra::QCassandraRowPredicate::toPredicate().
Referenced by QtCassandra::QCassandraContext::getRowSlices().
void QtCassandra::QCassandraPrivate::getValue | ( | const QString & | table_name, |
const QByteArray & | row_key, | ||
const QByteArray & | column_key, | ||
QCassandraValue & | value | ||
) |
This function retrieves a value
from the Cassandra database.
It is retrieve from the current context, table_name
, row_key
, and column_key
.
[in] | table_name | Name of the table where the value is inserted. |
[in] | row_key | The key used to identify the row. |
[in] | column_key | The key used to identify the column. |
[out] | value | The new value of the cell. |
Definition at line 520 of file QCassandraPrivate.cpp.
References QtCassandra::QCassandraValue::assignTimestamp(), QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandraValue::consistencyLevel(), QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, mustBeConnected(), QtCassandra::QCassandraValue::setBinaryValue(), QtCassandra::QCassandraValue::setNullValue(), and QtCassandra::QCassandraValue::setTtl().
Referenced by QtCassandra::QCassandraContext::getValue().
void QtCassandra::QCassandraPrivate::insertValue | ( | const QString & | table_name, |
const QByteArray & | row_key, | ||
const QByteArray & | column_key, | ||
const QCassandraValue & | value | ||
) |
This function insert the specified value
in the Cassandra database.
It is saved in the current context, table_name
, row_key
, and column_key
.
[in] | table_name | Name of the table where the value is inserted. |
[in] | row_key | The key used to identify the row. |
[in] | column_key | The key used to identify the column. |
[in] | value | The new value of the cell. |
Definition at line 462 of file QCassandraPrivate.cpp.
References QtCassandra::QCassandraValue::binaryValue(), QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandraValue::consistencyLevel(), QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, mustBeConnected(), QtCassandra::QCassandra::timeofday(), QtCassandra::QCassandraValue::timestamp(), QtCassandra::QCassandraValue::TIMESTAMP_MODE_AUTO, QtCassandra::QCassandraValue::TIMESTAMP_MODE_DEFINED, QtCassandra::QCassandraValue::timestampMode(), QtCassandra::QCassandraValue::ttl(), and QtCassandra::QCassandraValue::TTL_PERMANENT.
Referenced by QtCassandra::QCassandraContext::insertValue().
bool QtCassandra::QCassandraPrivate::isConnected | ( | ) | const |
This checks whether an f_client point exists.
Definition at line 233 of file QCassandraPrivate.cpp.
References f_client.
Referenced by mustBeConnected().
void QtCassandra::QCassandraPrivate::mustBeConnected | ( | ) | const throw (std::runtime_error) [private] |
This function verifies that the cassandra server is connected (as in the connect() function was called ans succeeded. If not connected, then an exception is raised.
std::runtime_error | This function raises an exception if the QCassandraPrivate object is not currently connected to a Cassandra server. |
Definition at line 248 of file QCassandraPrivate.cpp.
References isConnected().
Referenced by clusterName(), contexts(), createContext(), createTable(), dropContext(), dropTable(), getCellCount(), getColumnSlice(), getRowSlices(), getValue(), insertValue(), protocolVersion(), remove(), setContext(), truncateTable(), updateContext(), and updateTable().
QString QtCassandra::QCassandraPrivate::protocolVersion | ( | ) | const |
This function sends a message to the Cassandra server to determine the version of the protocol.
Definition at line 277 of file QCassandraPrivate.cpp.
References f_client, and mustBeConnected().
void QtCassandra::QCassandraPrivate::remove | ( | const QString & | table_name, |
const QByteArray & | row_key, | ||
const QByteArray & | column_key, | ||
int64_t | timestamp, | ||
consistency_level_t | consistency_level | ||
) |
This function calls the Cassandra server to remove a cell in the Cassandra database.
[in] | table_name | The name of the column where the row is defined. |
[in] | row_key | The row in which the cell is to be removed. |
[in] | column_key | The cell to be removed, may be empty to remove all the cells. |
[in] | timestamp | The time when the key to be removed was created. |
[in] | consistency_level | The consistency level to use to remove this cell. |
Definition at line 672 of file QCassandraPrivate.cpp.
References QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, and mustBeConnected().
Referenced by QtCassandra::QCassandraContext::remove().
void QtCassandra::QCassandraPrivate::setContext | ( | const QString & | context_name | ) |
The Cassandra database system reacts to commands in a specific keyspace which is managed like a context. This context must be specified before other functions are called or those other functions will fail.
[in] | context_name | The name of the context to use as the current context. |
Definition at line 293 of file QCassandraPrivate.cpp.
References f_client, and mustBeConnected().
void QtCassandra::QCassandraPrivate::truncateTable | ( | const QCassandraTable * | table | ) |
This function truncates (i.e. removes all the rows and their data) a table from the cassandra server.
[in] | table | The table to be created. |
Definition at line 444 of file QCassandraPrivate.cpp.
References f_client, mustBeConnected(), and QtCassandra::QCassandraTable::tableName().
Referenced by QtCassandra::QCassandraContext::truncateTable().
void QtCassandra::QCassandraPrivate::updateContext | ( | const QCassandraContext & | context | ) |
This function updates an existing context. Some options may not be updateable.
The context should be one that you loaded from the cluster to be sure that you start with the right data.
[in] | context | The context to update in the attached Cassandra cluster. |
Definition at line 366 of file QCassandraPrivate.cpp.
References f_client, mustBeConnected(), and QtCassandra::QCassandraContext::prepareContextDefinition().
Referenced by QtCassandra::QCassandraContext::update().
void QtCassandra::QCassandraPrivate::updateTable | ( | const QCassandraTable * | table | ) |
This function updates a table int the cassandra server.
[in] | table | The table to be updated. |
Definition at line 415 of file QCassandraPrivate.cpp.
References f_client, mustBeConnected(), and QtCassandra::QCassandraTable::prepareTableDefinition().
Referenced by QtCassandra::QCassandraContext::updateTable().
QtCassandra::QCassandraPrivate::f_client [private] |
The client object is what we use everywhere to communicate with the Cassandra server. It is a Cassandra Client object that knows how to convert the Cassandra specific messages and send them over the transport object.
To create a client, we need to create a socket, a transport and a protocol. If any one of those steps fails, then you cannot communicate with the Cassandra server.
The main raison for failure is an invalid IP/port combinaison or your Cassandra server isn't running.
Definition at line 90 of file QCassandraPrivate.h.
Referenced by clusterName(), connect(), contexts(), createContext(), createTable(), disconnect(), dropContext(), dropTable(), getCellCount(), getColumnSlice(), getRowSlices(), getValue(), insertValue(), isConnected(), protocolVersion(), remove(), setContext(), truncateTable(), updateContext(), and updateTable().
QtCassandra::QCassandraPrivate::f_parent [private] |
This variable member holds the QCassandra object pointer. This QCassandra object owns the QCassandraPrivate object (it's a 1 to 1.) This is why this pointer is a bare pointer. When the QCassandra goes, so does the QCassandraPriavet. And if the QCassandraPrivate goes, that's because the QCassandra is going.
Definition at line 86 of file QCassandraPrivate.h.
Referenced by contexts(), dropContext(), getCellCount(), getColumnSlice(), getRowSlices(), getValue(), insertValue(), and remove().
This object defines the protocol. In other words, it knows how to send and receive messages (i.e. header, footer, etc.)
Definition at line 89 of file QCassandraPrivate.h.
Referenced by connect(), and disconnect().
QtCassandra::QCassandraPrivate::f_socket [private] |
This pointer holds a Thrift socket used to communicate with the Cassandra server.
At our level we just provide the socket to the framed transport. How it is being used is Thrift responsibility.
It is setup with the IP address and port that one can use to access the Cassandra server.
Definition at line 87 of file QCassandraPrivate.h.
Referenced by connect(), and disconnect().
The transport object of the Thrift system to manage the data being send and received from the Cassandra server.
The socket is attached to the transport system.
Definition at line 88 of file QCassandraPrivate.h.
Referenced by connect(), and disconnect().
This document is part of the libQtCassandra Project.
Copyright by Made to Order Software Corp.