libQtCassandra 0.3.2

QCassandraCell.cpp

Go to the documentation of this file.
00001 /*
00002  * Text:
00003  *      QCassandraCell.cpp
00004  *
00005  * Description:
00006  *      Handling of cell. There is no class representing a row in Cassandra.
00007  *      A row is just a key. We have this object to allow for our C++ array
00008  *      syntax to access the Cassandra data.
00009  *
00010  * Documentation:
00011  *      See each function below.
00012  *
00013  * License:
00014  *      Copyright (c) 2011 Made to Order Software Corp.
00015  * 
00016  *      http://snapwebsites.org/
00017  *      contact@m2osw.com
00018  * 
00019  *      Permission is hereby granted, free of charge, to any person obtaining a
00020  *      copy of this software and associated documentation files (the
00021  *      "Software"), to deal in the Software without restriction, including
00022  *      without limitation the rights to use, copy, modify, merge, publish,
00023  *      distribute, sublicense, and/or sell copies of the Software, and to
00024  *      permit persons to whom the Software is furnished to do so, subject to
00025  *      the following conditions:
00026  *
00027  *      The above copyright notice and this permission notice shall be included
00028  *      in all copies or substantial portions of the Software.
00029  *
00030  *      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00031  *      OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *      MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00033  *      IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00034  *      CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00035  *      TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00036  *      SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  */
00038 
00039 #include "QtCassandra/QCassandraCell.h"
00040 #include "QtCassandra/QCassandraRow.h"
00041 #include <stdexcept>
00042 
00043 namespace QtCassandra
00044 {
00045 
00046 
00126 QCassandraCell::QCassandraCell(QCassandraRow *row, const QByteArray& column_key)
00127     : f_row(row),
00128       f_key(column_key)
00129       //f_cached(false) -- auto-init
00130       //f_value() -- auto-init to NULL
00131 {
00132     if(f_key.size() > 65535) {
00133         throw std::runtime_error("the cell binary column key is more than 64Kb");
00134     }
00135 }
00136 
00142 QCassandraCell::~QCassandraCell()
00143 {
00144 }
00145 
00165 QString QCassandraCell::columnName() const
00166 {
00167     return QString::fromUtf8(f_key.data());
00168 }
00169 
00183 const QByteArray& QCassandraCell::columnKey() const
00184 {
00185     return f_key;
00186 }
00187 
00203 const QCassandraValue& QCassandraCell::value() const
00204 {
00205     if(!f_cached) {
00206         if(f_row == NULL) {
00207             throw std::runtime_error("this cell was dropped, it cannot be used anymore.");
00208         }
00209         f_row->getValue(f_key, const_cast<QCassandraValue&>(f_value));
00210         f_cached = true;
00211     }
00212     return f_value;
00213 }
00214 
00230 void QCassandraCell::setValue(const QCassandraValue& value)
00231 {
00232     if(!f_cached || f_value != value) {
00233         if(f_row == NULL) {
00234             throw std::runtime_error("this cell was dropped, it cannot be used anymore.");
00235         }
00236         f_value = value;
00237         f_row->insertValue(f_key, f_value);
00238     }
00239     f_cached = true;
00240 }
00241 
00278 void QCassandraCell::assignValue(const QCassandraValue& value)
00279 {
00280     f_value = value;
00281     f_cached = true;
00282 }
00283 
00305 QCassandraCell& QCassandraCell::operator = (const QCassandraValue& value)
00306 {
00307     setValue(value);
00308     return *this;
00309 }
00310 
00331 QCassandraCell::operator QCassandraValue () const
00332 {
00333     return value();
00334 }
00335 
00353 void QCassandraCell::clearCache()
00354 {
00355     f_cached = false;
00356     f_value.setNullValue();
00357 }
00358 
00366 void QCassandraCell::unparent()
00367 {
00368     f_row = NULL;
00369     clearCache();
00370 }
00371 
00372 } // namespace QtCassandra
00373 // vim: ts=4 sw=4 et
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

This document is part of the libQtCassandra Project.

Copyright by Made to Order Software Corp.