libQtCassandra 0.3.2
|
00001 /* 00002 * Header: 00003 * QtCassandraTable.h 00004 * 00005 * Description: 00006 * Handling of the cassandra::CfDef. 00007 * 00008 * Documentation: 00009 * See the corresponding .cpp file. 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 #ifndef QCASSANDRA_TABLE_H 00037 #define QCASSANDRA_TABLE_H 00038 00039 #include "QCassandraColumnDefinition.h" 00040 #include "QCassandraRowPredicate.h" 00041 #include "QCassandraRow.h" 00042 #include <QtCore/QPointer> 00043 // GNU does not officially offer cstdint yet 00044 #include <stdint.h> 00045 00046 namespace QtCassandra 00047 { 00048 00049 class QCassandraTablePrivate; 00050 class QCassandraContext; 00051 00052 00053 // Cassandra Column Family (org::apache::cassandra::CfDef) 00054 class QCassandraTable : public QObject 00055 { 00056 public: 00057 ~QCassandraTable(); 00058 00059 // context name 00060 QString contextName() const; 00061 00062 // column family name & identifier 00063 //void setTableName(const QString& name); 00064 QString tableName() const; 00065 void setIdentifier(int32_t identifier); 00066 void unsetIdentifier(); 00067 int32_t identifier() const; 00068 void setComment(QString comment); 00069 void unsetComment(); 00070 QString comment() const; 00071 00072 // columns information (defaults) 00073 void setColumnType(const QString& column_type); 00074 void unsetColumnType(); 00075 QString columnType() const; 00076 void setDefaultValidationClass(const QString& validation_class); 00077 void unsetDefaultValidationClass(); 00078 QString defaultValidationClass() const; 00079 void setKeyValidationClass(const QString& validation_class); 00080 void unsetKeyValidationClass(); 00081 QString keyValidationClass() const; 00082 void setKeyAlias(const QString& key_alias); 00083 void unsetKeyAlias(); 00084 QString keyAlias() const; 00085 void setComparatorType(const QString& comparator_type); 00086 void unsetComparatorType(); 00087 QString comparatorType() const; 00088 void setSubcomparatorType(const QString& subcomparator_type); 00089 void unsetSubcomparatorType(); 00090 QString subcomparatorType() const; 00091 00092 // columns information (specific) 00093 QSharedPointer<QCassandraColumnDefinition> columnDefinition(const QString& column_name); 00094 const QCassandraColumnDefinitions& columnDefinitions() const; 00095 00096 // cache handling 00097 void setRowCacheSize(double size); 00098 void unsetRowCacheSize(); 00099 double rowCacheSize() const; 00100 void setRowCacheSavePeriodInSeconds(int32_t seconds); 00101 void unsetRowCacheSavePeriodInSeconds(); 00102 int32_t rowCacheSavePeriodInSeconds() const; 00103 void setKeyCacheSize(double size); 00104 void unsetKeyCacheSize(); 00105 double keyCacheSize() const; 00106 void setKeyCacheSavePeriodInSeconds(int32_t seconds); 00107 void unsetKeyCacheSavePeriodInSeconds(); 00108 int32_t keyCacheSavePeriodInSeconds() const; 00109 00110 // ring maintenance 00111 void setReadRepairChance(double repair_chance); 00112 void unsetReadRepairChance(); 00113 double readRepairChance() const; 00114 void setMinCompactionThreshold(int32_t threshold); 00115 void unsetMinCompactionThreshold(); 00116 double minCompactionThreshold() const; 00117 void setMaxCompactionThreshold(int32_t threshold); 00118 void unsetMaxCompactionThreshold(); 00119 double maxCompactionThreshold() const; 00120 void setReplicateOnWrite(bool replicate_on_write); 00121 void unsetReplicateOnWrite(); 00122 bool replicateOnWrite() const; 00123 void setMergeShardsChance(double merge_shards_chance); 00124 void unsetMergeShardsChance(); 00125 double mergeShardsChance() const; 00126 void setRowCacheProvider(const QString& provider); 00127 void unsetRowCacheProvider(); 00128 QString rowCacheProvider() const; 00129 00130 // memory handling 00131 void setGcGraceSeconds(int32_t seconds); 00132 void unsetGcGraceSeconds(); 00133 int32_t gcGraceSeconds() const; 00134 void setMemtableFlushAfterMins(int32_t minutes); 00135 void unsetMemtableFlushAfterMins(); 00136 int32_t memtableFlushAfterMins() const; 00137 void setMemtableThroughputInMb(int32_t megabytes); 00138 void unsetMemtableThroughputInMb(); 00139 int32_t memtableThroughputInMb() const; 00140 void setMemtableOperationsInMillions(int32_t operations); 00141 void unsetMemtableOperationsInMillions(); 00142 int32_t memtableOperationsInMillions() const; 00143 00144 // handling 00145 void create(); 00146 void update(); 00147 void truncate(); 00148 void clearCache(); 00149 00150 // row handling 00151 uint32_t readRows(const QCassandraRowPredicate& row_predicate = QCassandraRowPredicate()); 00152 00153 QSharedPointer<QCassandraRow> row(const QString& row_name); 00154 QSharedPointer<QCassandraRow> row(const QByteArray& row_key); 00155 const QCassandraRows& rows() const; 00156 00157 QSharedPointer<QCassandraRow> findRow(const QString& row_name) const; 00158 QSharedPointer<QCassandraRow> findRow(const QByteArray& row_key) const; 00159 bool exists(const QString& row_name) const; 00160 bool exists(const QByteArray& row_key) const; 00161 QCassandraRow& operator[] (const QString& row_name); 00162 QCassandraRow& operator[] (const QByteArray& row_key); 00163 const QCassandraRow& operator[] (const QString& row_name) const; 00164 const QCassandraRow& operator[] (const QByteArray& row_key) const; 00165 00166 void dropRow(const QByteArray& row_key, QCassandraValue::timestamp_mode_t mode = QCassandraValue::TIMESTAMP_MODE_AUTO, int64_t timestamp = 0, consistency_level_t consistency_level = CONSISTENCY_LEVEL_ALL); 00167 void dropRow(const QString& row_name, QCassandraValue::timestamp_mode_t mode = QCassandraValue::TIMESTAMP_MODE_AUTO, int64_t timestamp = 0, consistency_level_t consistency_level = CONSISTENCY_LEVEL_ALL); 00168 00169 private: 00170 QCassandraTable(QCassandraContext *context, const QString& table_name); 00171 00172 void setFromCassandra(); 00173 void parseTableDefinition(const void *data); 00174 void prepareTableDefinition(void *data) const; 00175 void insertValue(const QByteArray& row_key, const QByteArray& column_key, const QCassandraValue& value); 00176 void getValue(const QByteArray& row_key, const QByteArray& column_key, QCassandraValue& value); 00177 void assignRow(const QByteArray& row_key, const QByteArray& column_key, const QCassandraValue& value); 00178 int32_t getCellCount(const QByteArray& row_key, const QCassandraColumnPredicate& column_predicate); 00179 void getColumnSlice(const QByteArray& row_key, const QCassandraColumnPredicate& column_predicate); 00180 void remove(const QByteArray& row_key, const QByteArray& column_key, int64_t timestamp, consistency_level_t consistency_level); 00181 void unparent(); 00182 00183 friend class QCassandraPrivate; 00184 friend class QCassandraContext; 00185 friend class QCassandraTablePrivate; 00186 friend class QCassandraRow; 00187 00188 controlled_vars::zbool_t f_from_cassandra; 00189 std::auto_ptr<QCassandraTablePrivate> f_private; 00190 // f_context is a parent that has a strong shared pointer over us so it 00191 // cannot disappear before we do, thus only a bare pointer is enough here 00192 // (there isn't a need to use a QWeakPointer or QPointer either) 00193 QCassandraContext * f_context; 00194 QCassandraColumnDefinitions f_column_definitions; 00195 QCassandraRows f_rows; 00196 }; 00197 // list of table definitions mapped against their name (see tableName()) 00198 typedef QMap<QString, QSharedPointer<QCassandraTable> > QCassandraTables; 00199 00200 00201 00202 } // namespace QtCassandra 00203 #endif 00204 //#ifndef QCASSANDRA_TABLE_H 00205 // vim: ts=4 sw=4 et
This document is part of the libQtCassandra Project.
Copyright by Made to Order Software Corp.