diff DBCache.hpp @ 58:7b7e84356b39

Introduce API for fine tuning inserts. Reduce the amount of rebuilds.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Fri, 14 Sep 2012 00:04:24 +0200
parents f711ddb56ae7
children 74be5a2f49db
line wrap: on
line diff
--- a/DBCache.hpp	Thu Sep 13 23:53:35 2012 +0200
+++ b/DBCache.hpp	Fri Sep 14 00:04:24 2012 +0200
@@ -18,6 +18,15 @@
 
 #include <boost/optional.hpp>
 
+#include <QtCore/QString>
+
+template<typename Key, typename Value>
+struct InsertRegulator {
+  static void start() {}
+  static void finish() {}
+  static void next() {}
+};
+
 template<typename T>
 struct SQLGenerator
 {
@@ -264,11 +273,15 @@
       if (!query.exec(repopulateQuery)) {
 	throw SQLException(query);
       }
+      InsertRegulator<Key, Value> regulator;
+      regulator.start();
       while (query.next()) {
 	Key key = *SQLGenerator<Key>::extract(query, "key");
 	Value value = *SQLGenerator<Value>::extract(query, "value");
 	memoryMap.insert(key, value);
+	regulator.next();
       }
+      regulator.finish();
     }
     QString queryString = QString("INSERT into %1 (%2, %3) VALUES(%4, %5);")
       .arg(dictName)