libQtCassandra 0.3.2
|
00001 /* 00002 * Text: 00003 * QCassandraColumnDefinition.cpp 00004 * 00005 * Description: 00006 * Handling of the cassandra::ColumnDef. 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/QCassandraColumnDefinition.h" 00038 #include "thrift-gencpp-cassandra/cassandra_types.h" 00039 #include <stdexcept> 00040 00041 namespace QtCassandra 00042 { 00043 00103 class QCassandraColumnDefinitionPrivate : public org::apache::cassandra::ColumnDef {}; 00104 00105 00106 00107 00108 00109 00121 QCassandraColumnDefinition::QCassandraColumnDefinition(QCassandraTable *table, const QString& column_name) 00122 : f_private(new QCassandraColumnDefinitionPrivate), 00123 f_table(table) 00124 { 00125 // we save the name and at this point we prevent it from being changed. 00126 f_private->__set_name(column_name.toUtf8().data()); 00127 } 00128 00134 QCassandraColumnDefinition::~QCassandraColumnDefinition() 00135 { 00136 } 00137 00147 QString QCassandraColumnDefinition::columnName() const 00148 { 00149 return f_private->name.c_str(); 00150 } 00151 00159 void QCassandraColumnDefinition::setValidationClass(const QString& name) 00160 { 00161 f_private->__set_validation_class(name.toUtf8().data()); 00162 } 00163 00170 QString QCassandraColumnDefinition::validationClass() const 00171 { 00172 return f_private->validation_class.c_str(); 00173 } 00174 00190 void QCassandraColumnDefinition::setIndexType(index_type_t index_type) 00191 { 00192 switch(index_type) { 00193 case INDEX_TYPE_KEYS: 00194 f_private->__set_index_type(org::apache::cassandra::IndexType::KEYS); 00195 break; 00196 00197 default: 00198 throw std::runtime_error("unrecognized index_type value in QCassandraColumnDefinition::set_index_type()"); 00199 00200 } 00201 } 00202 00209 void QCassandraColumnDefinition::unsetIndexType() 00210 { 00211 f_private->__isset.index_type = false; 00212 } 00213 00224 QCassandraColumnDefinition::index_type_t QCassandraColumnDefinition::indexType() const 00225 { 00226 if(!f_private->__isset.index_type) { 00227 return INDEX_TYPE_UNDEFINED; 00228 } 00229 switch(f_private->index_type) { 00230 case org::apache::cassandra::IndexType::KEYS: 00231 return INDEX_TYPE_KEYS; 00232 00233 default: 00234 return INDEX_TYPE_UNKNOWN; 00235 00236 } 00237 } 00238 00245 void QCassandraColumnDefinition::setIndexName(const QString& name) 00246 { 00247 f_private->__set_index_name(name.toUtf8().data()); 00248 } 00249 00254 void QCassandraColumnDefinition::unsetIndexName() 00255 { 00256 f_private->__isset.index_name = false; 00257 } 00258 00267 QString QCassandraColumnDefinition::indexName() const 00268 { 00269 if(!f_private->__isset.index_name) { 00270 return ""; 00271 } 00272 return f_private->index_name.c_str(); 00273 } 00274 00281 void QCassandraColumnDefinition::parseColumnDefinition(const void *data) 00282 { 00283 const org::apache::cassandra::ColumnDef *col = reinterpret_cast<const org::apache::cassandra::ColumnDef *>(data); 00284 00285 // column name 00286 if(col->name != f_private->name) { 00287 // what do we do here? 00288 throw std::logic_error("ColumnDef and QCassandraColumnDefinitionPrivate names don't match"); 00289 } 00290 00291 // validation class 00292 f_private->__set_validation_class(col->validation_class); 00293 00294 // index type 00295 if(col->__isset.index_type) { 00296 f_private->__set_index_type(col->index_type); 00297 } 00298 else { 00299 f_private->__isset.index_type = false; 00300 } 00301 00302 // index name 00303 if(col->__isset.index_name) { 00304 f_private->__set_index_name(col->index_name); 00305 } 00306 else { 00307 f_private->__isset.index_name = false; 00308 } 00309 } 00310 00318 void QCassandraColumnDefinition::prepareColumnDefinition(void *data) const 00319 { 00320 org::apache::cassandra::ColumnDef *col = reinterpret_cast<org::apache::cassandra::ColumnDef *>(data); 00321 *col = *f_private; 00322 00323 // no special handling in this one! 00324 } 00325 00326 } // namespace QtCassandra 00327 // vim: ts=4 sw=4 et
This document is part of the libQtCassandra Project.
Copyright by Made to Order Software Corp.