MetriVis Overview | Download | User Manual | Development
Reference Overview | Design Documentation | Reference Backend | Reference Frontend

src/SQLDriver.h

Go to the documentation of this file.
00001 /*
00002  *   MetriVis - Metrics Visualization Application
00003  *
00004  *
00005  *   License notice:
00006  *
00007  *   This program is free software: you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation, either version 3 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
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 } // namespace metrivis
00326 #endif

Generated on Fri Feb 29 16:47:19 2008 for MetriVis by  doxygen 1.5.3