libQtCassandra 0.3.2
|
00001 /* 00002 * Header: 00003 * QCassandraContext.h 00004 * 00005 * Description: 00006 * Handling of the cassandra::KsDef. 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_CONTEXT_H 00037 #define QCASSANDRA_CONTEXT_H 00038 00039 #include "QCassandraTable.h" 00040 #include "QCassandraColumnPredicate.h" 00041 00042 namespace QtCassandra 00043 { 00044 00045 class QCassandraContextPrivate; 00046 class QCassandra; 00047 00048 // Cassandra KsDef object 00049 class QCassandraContext : public QObject 00050 { 00051 public: 00052 typedef QMap<QString, QString> QCassandraContextOptions; 00053 00054 virtual ~QCassandraContext(); 00055 00056 QString contextName() const; 00057 00058 void setStrategyClass(const QString& strategy_class); 00059 QString strategyClass() const; 00060 00061 void setDescriptionOptions(const QCassandraContextOptions& options); 00062 const QCassandraContextOptions& descriptionOptions() const; 00063 void setDescriptionOption(const QString& option, const QString& value); 00064 QString descriptionOption(const QString& option) const; 00065 00066 // tables 00067 QSharedPointer<QCassandraTable> table(const QString& table_name); 00068 const QCassandraTables& tables() const; 00069 00070 QSharedPointer<QCassandraTable> findTable(const QString& table_name) const; 00071 QCassandraTable& operator[] (const QString& table_name); 00072 const QCassandraTable& operator[] (const QString& table_name) const; 00073 00074 // replication 00075 void setReplicationFactor(int32_t factor); 00076 void unsetReplicationFactor(); 00077 int32_t replicationFactor() const; 00078 void setDurableWrites(bool durable_writes); 00079 void unsetDurableWrites(); 00080 bool durableWrites() const; 00081 00082 // handling 00083 void create(); 00084 void update(); 00085 void drop(); 00086 void dropTable(const QString& table_name); 00087 void clearCache(); 00088 00089 private: 00090 void makeCurrent(); 00091 QCassandraContext(QCassandra *cassandra, const QString& context_name); 00092 00093 // internal functions 00094 void parseContextDefinition(const void *data); 00095 void prepareContextDefinition(void *data) const; 00096 void createTable(const QCassandraTable *table); 00097 void updateTable(const QCassandraTable *table); 00098 void truncateTable(const QCassandraTable *table); 00099 void insertValue(const QString& table_name, const QByteArray& row_key, const QByteArray& column_key, const QCassandraValue& value); 00100 void getValue(const QString& table_name, const QByteArray& row_key, const QByteArray& column_key, QCassandraValue& value); 00101 int32_t getCellCount(const QString& table_name, const QByteArray& row_key, const QCassandraColumnPredicate& column_predicate); 00102 void getColumnSlice(QCassandraTable& table, const QByteArray& row_key, const QCassandraColumnPredicate& column_predicate); 00103 void remove(const QString& table_name, const QByteArray& row_key, const QByteArray& column_key, int64_t timestamp, consistency_level_t consistency_level); 00104 uint32_t getRowSlices(QCassandraTable& table, const QCassandraRowPredicate& row_predicate); 00105 void unparent(); 00106 00107 friend class QCassandra; 00108 friend class QCassandraPrivate; 00109 friend class QCassandraContextPrivate; 00110 friend class QCassandraTable; 00111 00112 std::auto_ptr<QCassandraContextPrivate> f_private; 00113 // f_cassandra is a parent that has a strong shared pointer over us so it 00114 // cannot disappear before we do, thus only a bare pointer is enough here 00115 // (there isn't a need to use a QWeakPointer or QPointer either) 00116 QCassandra * f_cassandra; 00117 QCassandraContextOptions f_options; 00118 QCassandraTables f_tables; 00119 }; 00120 00121 typedef QMap<QString, QSharedPointer<QCassandraContext> > QCassandraContexts; 00122 00123 00124 } // namespace QtCassandra 00125 #endif 00126 //#ifndef QCASSANDRA_CONTEXT_H 00127 // vim: ts=4 sw=4 et
This document is part of the libQtCassandra Project.
Copyright by Made to Order Software Corp.