libQtCassandra 0.3.2
|
00001 /* 00002 * Text: 00003 * QCassandraColumnPredicate.cpp 00004 * 00005 * Description: 00006 * Definition of column predicates to get row slices. 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/QCassandraColumnPredicate.h" 00038 //#include "QtCassandra/QCassandraTable.h" 00039 #include "thrift-gencpp-cassandra/cassandra_types.h" 00040 #include <stdexcept> 00041 00042 namespace QtCassandra 00043 { 00044 00087 QCassandraColumnPredicate::QCassandraColumnPredicate() 00088 //: f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init 00089 { 00090 } 00091 00106 consistency_level_t QCassandraColumnPredicate::consistencyLevel() const 00107 { 00108 return f_consistency_level; 00109 } 00110 00123 void QCassandraColumnPredicate::setConsistencyLevel(consistency_level_t consistency_level) 00124 { 00125 f_consistency_level = consistency_level; 00126 } 00127 00139 void QCassandraColumnPredicate::toPredicate(void *data) const 00140 { 00141 org::apache::cassandra::SlicePredicate *slice_predicate = reinterpret_cast<org::apache::cassandra::SlicePredicate *>(data); 00142 00143 // using empty strings for the start & end make the slice range 00144 // return all the columns; although this way we're not offering 00145 // a limit and the reversed flag... 00146 slice_predicate->__isset.slice_range = true; 00147 } 00148 00149 00150 00151 00152 00153 00154 00155 00156 00186 QCassandraColumnNamePredicate::QCassandraColumnNamePredicate() 00187 //: QCassandraColumnPredicate() -- auto-init 00188 // f_column_keys() -- auto-init 00189 { 00190 } 00191 00198 void QCassandraColumnNamePredicate::clearColumns() 00199 { 00200 f_column_keys.clear(); 00201 } 00202 00213 void QCassandraColumnNamePredicate::addColumnName(const QString& column_name) 00214 { 00215 addColumnKey(column_name.toUtf8()); 00216 } 00217 00228 void QCassandraColumnNamePredicate::addColumnKey(const QByteArray& column_key) 00229 { 00230 if(column_key.size() > 65535) { 00231 throw std::runtime_error("the column key is more than 64Kb"); 00232 } 00233 f_column_keys.append(column_key); 00234 } 00235 00246 const QCassandraColumnNamePredicate::QCassandraColumnKeys& QCassandraColumnNamePredicate::columnKeys() const 00247 { 00248 return f_column_keys; 00249 } 00250 00262 void QCassandraColumnNamePredicate::toPredicate(void *data) const 00263 { 00264 org::apache::cassandra::SlicePredicate *slice_predicate = reinterpret_cast<org::apache::cassandra::SlicePredicate *>(data); 00265 00266 slice_predicate->column_names.clear(); 00267 for(QCassandraColumnKeys::const_iterator 00268 it = f_column_keys.begin(); 00269 it != f_column_keys.end(); 00270 ++it) 00271 { 00272 std::string key(it->data(), it->size()); 00273 slice_predicate->column_names.push_back(key); 00274 } 00275 slice_predicate->__isset.column_names = true; 00276 slice_predicate->__isset.slice_range = false; 00277 } 00278 00279 00280 00281 00282 00283 00284 00285 00364 QCassandraColumnRangePredicate::QCassandraColumnRangePredicate() 00365 //: QCassandraColumnPredicate() -- auto-init 00366 // f_start_column() -- auto-init 00367 // f_end_column() -- auto-init 00368 // f_reversed(false) -- auto-init 00369 // f_count(100) -- auto-init 00370 { 00371 } 00372 00381 QString QCassandraColumnRangePredicate::startColumnName() const 00382 { 00383 return QString::fromUtf8(f_start_column.data()); 00384 } 00385 00394 void QCassandraColumnRangePredicate::setStartColumnName(const QString& column_name) 00395 { 00396 setStartColumnKey(column_name.toUtf8()); 00397 } 00398 00405 const QByteArray& QCassandraColumnRangePredicate::startColumnKey() const 00406 { 00407 return f_start_column; 00408 } 00409 00416 void QCassandraColumnRangePredicate::setStartColumnKey(const QByteArray& column_key) 00417 { 00418 if(column_key.size() > 65535) { 00419 throw std::runtime_error("the start column key is more than 64Kb"); 00420 } 00421 f_start_column = column_key; 00422 } 00423 00434 QString QCassandraColumnRangePredicate::endColumnName() const 00435 { 00436 return QString::fromUtf8(f_end_column.data()); 00437 } 00438 00446 void QCassandraColumnRangePredicate::setFinishColumnName(const QString& column_name) 00447 { 00448 setFinishColumnKey(column_name.toUtf8()); 00449 } 00450 00458 const QByteArray& QCassandraColumnRangePredicate::endColumnKey() const 00459 { 00460 return f_end_column; 00461 } 00462 00472 void QCassandraColumnRangePredicate::setFinishColumnKey(const QByteArray& column_key) 00473 { 00474 if(column_key.size() > 65535) { 00475 throw std::runtime_error("the end column key is more than 64Kb"); 00476 } 00477 f_end_column = column_key; 00478 } 00479 00491 bool QCassandraColumnRangePredicate::reversed() const 00492 { 00493 return f_reversed; 00494 } 00495 00505 void QCassandraColumnRangePredicate::setReversed(bool reversed) 00506 { 00507 f_reversed = reversed; 00508 } 00509 00519 int32_t QCassandraColumnRangePredicate::count() const 00520 { 00521 return f_count; 00522 } 00523 00539 void QCassandraColumnRangePredicate::setCount(int32_t count) 00540 { 00541 f_count = count; 00542 } 00543 00555 void QCassandraColumnRangePredicate::toPredicate(void *data) const 00556 { 00557 org::apache::cassandra::SlicePredicate *slice_predicate = reinterpret_cast<org::apache::cassandra::SlicePredicate *>(data); 00558 00559 slice_predicate->slice_range.__set_start(f_start_column.data()); 00560 slice_predicate->slice_range.__set_finish(f_end_column.data()); 00561 slice_predicate->slice_range.__set_reversed(f_reversed); 00562 slice_predicate->slice_range.__set_count(f_count); 00563 slice_predicate->__isset.slice_range = true; 00564 slice_predicate->__isset.column_names = false; 00565 } 00566 00567 00568 } // namespace QtCassandra 00569 // vim: ts=4 sw=4 et
This document is part of the libQtCassandra Project.
Copyright by Made to Order Software Corp.