libQtCassandra 0.3.2
|
00001 /* 00002 * Text: 00003 * QCassandraRowPredicate.cpp 00004 * 00005 * Description: 00006 * Definition of row (and column) predicates to get row ranges. 00007 * 00008 * Documentation: 00009 * See each function below. 00010 * 00011 * License: 00012 * Copyright (c) 2011 Made to Order Software Corp. 00013 * 00014 * http://snapwebsites.org/ 00015 * contact@m2osw.com 00016 * 00017 * Permission is hereby granted, free of charge, to any person obtaining a 00018 * copy of this software and associated documentation files (the 00019 * "Software"), to deal in the Software without restriction, including 00020 * without limitation the rights to use, copy, modify, merge, publish, 00021 * distribute, sublicense, and/or sell copies of the Software, and to 00022 * permit persons to whom the Software is furnished to do so, subject to 00023 * the following conditions: 00024 * 00025 * The above copyright notice and this permission notice shall be included 00026 * in all copies or substantial portions of the Software. 00027 * 00028 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00029 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00030 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00031 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 00032 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 00033 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 00034 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00035 */ 00036 00037 #include "QtCassandra/QCassandraRowPredicate.h" 00038 //#include "QtCassandra/QCassandraTable.h" 00039 #include "thrift-gencpp-cassandra/cassandra_types.h" 00040 #include <stdexcept> 00041 00042 namespace QtCassandra 00043 { 00044 00170 QCassandraRowPredicate::QCassandraRowPredicate() 00171 //: f_start_row() -- auto-init 00172 // f_end_row() -- auto-init 00173 : f_count(100), 00174 f_wrap(false), 00175 f_column_predicate(new QCassandraColumnPredicate) 00176 { 00177 } 00178 00187 QString QCassandraRowPredicate::startRowName() const 00188 { 00189 return QString::fromUtf8(f_start_row.data()); 00190 } 00191 00206 void QCassandraRowPredicate::setStartRowName(const QString& row_name) 00207 { 00208 setStartRowKey(row_name.toUtf8()); 00209 } 00210 00217 const QByteArray& QCassandraRowPredicate::startRowKey() const 00218 { 00219 return f_start_row; 00220 } 00221 00230 void QCassandraRowPredicate::setStartRowKey(const QByteArray& row_key) 00231 { 00232 if(row_key.size() > 65535) { 00233 throw std::runtime_error("the start row key is more than 64Kb"); 00234 } 00235 f_start_row = row_key; 00236 } 00237 00248 QString QCassandraRowPredicate::endRowName() const 00249 { 00250 return QString::fromUtf8(f_end_row.data()); 00251 } 00252 00263 void QCassandraRowPredicate::setEndRowName(const QString& row_name) 00264 { 00265 setEndRowKey(row_name.toUtf8()); 00266 } 00267 00275 const QByteArray& QCassandraRowPredicate::endRowKey() const 00276 { 00277 return f_end_row; 00278 } 00279 00289 void QCassandraRowPredicate::setEndRowKey(const QByteArray& row_key) 00290 { 00291 if(row_key.size() > 65535) { 00292 throw std::runtime_error("the end row key is more than 64Kb"); 00293 } 00294 f_end_row = row_key; 00295 } 00296 00306 int32_t QCassandraRowPredicate::count() const 00307 { 00308 return f_count; 00309 } 00310 00326 void QCassandraRowPredicate::setCount(int32_t count) 00327 { 00328 f_count = count; 00329 } 00330 00342 bool QCassandraRowPredicate::wrap() const 00343 { 00344 return f_wrap; 00345 } 00346 00360 void QCassandraRowPredicate::setWrap(bool wrap) 00361 { 00362 f_wrap = wrap; 00363 } 00364 00381 QSharedPointer<QCassandraColumnPredicate> QCassandraRowPredicate::columnPredicate() const 00382 { 00383 return f_column_predicate; 00384 } 00385 00402 void QCassandraRowPredicate::setColumnPredicate(QSharedPointer<QCassandraColumnPredicate> column_predicate) 00403 { 00404 f_column_predicate = column_predicate; 00405 } 00406 00418 void QCassandraRowPredicate::toPredicate(void *data) const 00419 { 00420 org::apache::cassandra::KeyRange *key_range = reinterpret_cast<org::apache::cassandra::KeyRange *>(data); 00421 00422 if(f_wrap) { 00423 key_range->__set_start_token(f_start_row.data()); 00424 key_range->__set_end_token(f_end_row.data()); 00425 } 00426 else { 00427 key_range->__set_start_key(f_start_row.data()); 00428 key_range->__set_end_key(f_end_row.data()); 00429 } 00430 key_range->__set_count(f_count); 00431 } 00432 00433 00434 } // namespace QtCassandra 00435 // vim: ts=4 sw=4 et
This document is part of the libQtCassandra Project.
Copyright by Made to Order Software Corp.