00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00029 #ifndef _SQLDRIVER_H
00030 #define _SQLDRIVER_H
00031
00032 #include <boost/thread/mutex.hpp>
00033 #include "lib/lru_cache/lru_cache.h"
00034 #include "container/MultiType.h"
00035 #include "pattern/Singleton.h"
00036 #include "BaseClass.h"
00037
00039 #define METRIVIS_DEFAULT_CACHE_SIZE 1<<29
00040
00041 namespace metrivis {
00042
00053 class SQLDriver : public BaseClass {
00054
00055 public:
00056
00057
00062 SQLDriver(unsigned int max_cache_size = METRIVIS_DEFAULT_CACHE_SIZE);
00063
00064
00068 ~SQLDriver();
00069
00081 MultiTypePtr Insert(std::string table_name, std::string values);
00082
00083
00096 MultiTypePtr Insert(std::string table_name, std::string columns,
00097 std::string values);
00098
00099
00111 MultiTypePtr Delete(std::string table_name, std::string where);
00112
00113
00125 MultiTypePtr Select(std::vector<std::string> columns, std::string table_name);
00126
00127
00139 MultiTypePtr SelectString(std::vector<std::string> columns,
00140 std::string table_name);
00141
00155 MultiTypePtr SelectString(std::vector<std::string> columns,
00156 std::string table_name, std::string where);
00157
00169 MultiTypePtr Select(std::vector<std::string> columns, std::string table_name,
00170 std::string where);
00171
00172
00192 MultiTypePtr SelectCached(std::vector<std::string> columns,
00193 std::string table_name);
00194
00195
00215 MultiTypePtr SelectStringCached(std::vector<std::string> columns,
00216 std::string table_name);
00217
00218
00237 void PreCacheSelectString(std::vector<std::string> columns,
00238 std::string table_name);
00239
00240
00241
00260 void PreCacheSelect(std::vector<std::string> columns, std::string table_name);
00261
00262
00270 inline void set_max_cache_size(long max_cache_size) {
00271 max_cache_size_ = max_cache_size;
00272 cache_.clear();
00273 cache_.set_max_size(max_cache_size);
00274 }
00275
00276
00281 inline long max_cache_size() const {
00282 return max_cache_size_;
00283 }
00284
00289 inline long cache_size() const {
00290 return cache_size_;
00291 }
00292
00297 inline void set_db_file_name(const std::string& db_file_name) {
00298 db_file_name_ = db_file_name;
00299 }
00300
00301
00302 private:
00303
00307 SQLDriver(const SQLDriver& sql_driver);
00308
00309
00310 private:
00311
00312 LRUCache<std::string, MultiTypePtr> cache_;
00313 boost::mutex cache_mutex_;
00314
00315 long cache_size_;
00316 long max_cache_size_;
00317
00318 std::string db_file_name_;
00319 };
00320
00321
00323 typedef Singleton<SQLDriver> SQL;
00324
00325 }
00326 #endif