diff options
-rw-r--r-- | common/index.cpp | 2 | ||||
-rw-r--r-- | common/storage.h | 2 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 28 | ||||
-rw-r--r-- | tests/storagetest.cpp | 16 |
4 files changed, 20 insertions, 28 deletions
diff --git a/common/index.cpp b/common/index.cpp index 75ffe3f..f752f5f 100644 --- a/common/index.cpp +++ b/common/index.cpp | |||
@@ -2,7 +2,7 @@ | |||
2 | #include <QDebug> | 2 | #include <QDebug> |
3 | 3 | ||
4 | Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode) | 4 | Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode) |
5 | : mTransaction(Akonadi2::Storage(storageRoot, name, mode, true).createTransaction(mode)), | 5 | : mTransaction(Akonadi2::Storage(storageRoot, name, mode).createTransaction(mode)), |
6 | mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Akonadi2::Storage::Error &)>(), true)) | 6 | mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Akonadi2::Storage::Error &)>(), true)) |
7 | { | 7 | { |
8 | 8 | ||
diff --git a/common/storage.h b/common/storage.h index 4b0604e..8a2e51f 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -146,7 +146,7 @@ public: | |||
146 | Private *d; | 146 | Private *d; |
147 | }; | 147 | }; |
148 | 148 | ||
149 | Storage(const QString &storageRoot, const QString &name, AccessMode mode = ReadOnly, bool allowDuplicates = false); | 149 | Storage(const QString &storageRoot, const QString &name, AccessMode mode = ReadOnly); |
150 | ~Storage(); | 150 | ~Storage(); |
151 | 151 | ||
152 | Transaction createTransaction(AccessMode mode = ReadWrite, | 152 | Transaction createTransaction(AccessMode mode = ReadWrite, |
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 3c153fc..7fed830 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -233,10 +233,9 @@ int Storage::NamedDatabase::scan(const QByteArray &k, | |||
233 | class Storage::Transaction::Private | 233 | class Storage::Transaction::Private |
234 | { | 234 | { |
235 | public: | 235 | public: |
236 | Private(bool _requestRead, bool _allowDuplicates, const std::function<void(const Storage::Error &error)> &_defaultErrorHandler, const QString &_name, MDB_env *_env) | 236 | Private(bool _requestRead, const std::function<void(const Storage::Error &error)> &_defaultErrorHandler, const QString &_name, MDB_env *_env) |
237 | : env(_env), | 237 | : env(_env), |
238 | requestedRead(_requestRead), | 238 | requestedRead(_requestRead), |
239 | allowDuplicates(_allowDuplicates), | ||
240 | defaultErrorHandler(_defaultErrorHandler), | 239 | defaultErrorHandler(_defaultErrorHandler), |
241 | name(_name), | 240 | name(_name), |
242 | implicitCommit(false), | 241 | implicitCommit(false), |
@@ -254,7 +253,6 @@ public: | |||
254 | MDB_txn *transaction; | 253 | MDB_txn *transaction; |
255 | MDB_dbi dbi; | 254 | MDB_dbi dbi; |
256 | bool requestedRead; | 255 | bool requestedRead; |
257 | bool allowDuplicates; | ||
258 | std::function<void(const Storage::Error &error)> defaultErrorHandler; | 256 | std::function<void(const Storage::Error &error)> defaultErrorHandler; |
259 | QString name; | 257 | QString name; |
260 | bool implicitCommit; | 258 | bool implicitCommit; |
@@ -345,7 +343,7 @@ bool Storage::Transaction::write(const QByteArray &key, const QByteArray &value, | |||
345 | d->error = true; | 343 | d->error = true; |
346 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); | 344 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); |
347 | }; | 345 | }; |
348 | openDatabase("default", eHandler, d->allowDuplicates).write(key, value, eHandler); | 346 | openDatabase("default", eHandler).write(key, value, eHandler); |
349 | d->implicitCommit = true; | 347 | d->implicitCommit = true; |
350 | 348 | ||
351 | return !d->error; | 349 | return !d->error; |
@@ -358,7 +356,7 @@ void Storage::Transaction::remove(const QByteArray &k, | |||
358 | d->error = true; | 356 | d->error = true; |
359 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); | 357 | errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); |
360 | }; | 358 | }; |
361 | openDatabase("default", eHandler, d->allowDuplicates).remove(k, eHandler); | 359 | openDatabase("default", eHandler).remove(k, eHandler); |
362 | d->implicitCommit = true; | 360 | d->implicitCommit = true; |
363 | } | 361 | } |
364 | 362 | ||
@@ -366,7 +364,7 @@ int Storage::Transaction::scan(const QByteArray &k, | |||
366 | const std::function<bool(const QByteArray &key, const QByteArray &value)> &resultHandler, | 364 | const std::function<bool(const QByteArray &key, const QByteArray &value)> &resultHandler, |
367 | const std::function<void(const Storage::Error &error)> &errorHandler) const | 365 | const std::function<void(const Storage::Error &error)> &errorHandler) const |
368 | { | 366 | { |
369 | auto db = openDatabase("default", std::function<void(const Storage::Error &error)>(), d->allowDuplicates); | 367 | auto db = openDatabase("default", std::function<void(const Storage::Error &error)>()); |
370 | if (db) { | 368 | if (db) { |
371 | return db.scan(k, resultHandler, errorHandler); | 369 | return db.scan(k, resultHandler, errorHandler); |
372 | } | 370 | } |
@@ -384,7 +382,7 @@ int Storage::Transaction::scan(const QByteArray &k, | |||
384 | class Storage::Private | 382 | class Storage::Private |
385 | { | 383 | { |
386 | public: | 384 | public: |
387 | Private(const QString &s, const QString &n, AccessMode m, bool duplicates); | 385 | Private(const QString &s, const QString &n, AccessMode m); |
388 | ~Private(); | 386 | ~Private(); |
389 | 387 | ||
390 | QString storageRoot; | 388 | QString storageRoot; |
@@ -392,9 +390,6 @@ public: | |||
392 | 390 | ||
393 | MDB_env *env; | 391 | MDB_env *env; |
394 | AccessMode mode; | 392 | AccessMode mode; |
395 | bool readTransaction; | ||
396 | bool firstOpen; | ||
397 | bool allowDuplicates; | ||
398 | static QMutex sMutex; | 393 | static QMutex sMutex; |
399 | static QHash<QString, MDB_env*> sEnvironments; | 394 | static QHash<QString, MDB_env*> sEnvironments; |
400 | }; | 395 | }; |
@@ -402,14 +397,11 @@ public: | |||
402 | QMutex Storage::Private::sMutex; | 397 | QMutex Storage::Private::sMutex; |
403 | QHash<QString, MDB_env*> Storage::Private::sEnvironments; | 398 | QHash<QString, MDB_env*> Storage::Private::sEnvironments; |
404 | 399 | ||
405 | Storage::Private::Private(const QString &s, const QString &n, AccessMode m, bool duplicates) | 400 | Storage::Private::Private(const QString &s, const QString &n, AccessMode m) |
406 | : storageRoot(s), | 401 | : storageRoot(s), |
407 | name(n), | 402 | name(n), |
408 | env(0), | 403 | env(0), |
409 | mode(m), | 404 | mode(m) |
410 | readTransaction(false), | ||
411 | firstOpen(true), | ||
412 | allowDuplicates(duplicates) | ||
413 | { | 405 | { |
414 | const QString fullPath(storageRoot + '/' + name); | 406 | const QString fullPath(storageRoot + '/' + name); |
415 | QFileInfo dirInfo(fullPath); | 407 | QFileInfo dirInfo(fullPath); |
@@ -464,8 +456,8 @@ Storage::Private::~Private() | |||
464 | // } | 456 | // } |
465 | } | 457 | } |
466 | 458 | ||
467 | Storage::Storage(const QString &storageRoot, const QString &name, AccessMode mode, bool allowDuplicates) | 459 | Storage::Storage(const QString &storageRoot, const QString &name, AccessMode mode) |
468 | : d(new Private(storageRoot, name, mode, allowDuplicates)) | 460 | : d(new Private(storageRoot, name, mode)) |
469 | { | 461 | { |
470 | } | 462 | } |
471 | 463 | ||
@@ -494,7 +486,7 @@ Storage::Transaction Storage::createTransaction(AccessMode type, const std::func | |||
494 | return Transaction(); | 486 | return Transaction(); |
495 | } | 487 | } |
496 | 488 | ||
497 | return Transaction(new Transaction::Private(requestedRead, d->allowDuplicates, defaultErrorHandler(), d->name, d->env)); | 489 | return Transaction(new Transaction::Private(requestedRead, defaultErrorHandler(), d->name, d->env)); |
498 | } | 490 | } |
499 | 491 | ||
500 | qint64 Storage::diskUsage() const | 492 | qint64 Storage::diskUsage() const |
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 6ba4bcd..2e69634 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp | |||
@@ -221,7 +221,7 @@ private Q_SLOTS: | |||
221 | { | 221 | { |
222 | bool gotResult = false; | 222 | bool gotResult = false; |
223 | bool gotError = false; | 223 | bool gotError = false; |
224 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, false); | 224 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); |
225 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | 225 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); |
226 | auto db = transaction.openDatabase("default", nullptr, false); | 226 | auto db = transaction.openDatabase("default", nullptr, false); |
227 | db.write("key","value"); | 227 | db.write("key","value"); |
@@ -244,7 +244,7 @@ private Q_SLOTS: | |||
244 | { | 244 | { |
245 | bool gotResult = false; | 245 | bool gotResult = false; |
246 | bool gotError = false; | 246 | bool gotError = false; |
247 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | 247 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); |
248 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | 248 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); |
249 | auto db = transaction.openDatabase("default", nullptr, true); | 249 | auto db = transaction.openDatabase("default", nullptr, true); |
250 | db.write("key","value1"); | 250 | db.write("key","value1"); |
@@ -294,8 +294,8 @@ private Q_SLOTS: | |||
294 | void testWriteDuplicatesToNamedDb() | 294 | void testWriteDuplicatesToNamedDb() |
295 | { | 295 | { |
296 | bool gotError = false; | 296 | bool gotError = false; |
297 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | 297 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); |
298 | store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test").write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { | 298 | store.createTransaction(Akonadi2::Storage::ReadWrite).openDatabase("test", nullptr, true).write("key1", "value1", [&](const Akonadi2::Storage::Error &error) { |
299 | qDebug() << error.message; | 299 | qDebug() << error.message; |
300 | gotError = true; | 300 | gotError = true; |
301 | }); | 301 | }); |
@@ -305,9 +305,9 @@ private Q_SLOTS: | |||
305 | //By default we want only exact matches | 305 | //By default we want only exact matches |
306 | void testSubstringKeys() | 306 | void testSubstringKeys() |
307 | { | 307 | { |
308 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | 308 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); |
309 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | 309 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); |
310 | auto db = transaction.openDatabase(); | 310 | auto db = transaction.openDatabase("test", nullptr, true); |
311 | db.write("sub","value1"); | 311 | db.write("sub","value1"); |
312 | db.write("subsub","value2"); | 312 | db.write("subsub","value2"); |
313 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { | 313 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { |
@@ -320,9 +320,9 @@ private Q_SLOTS: | |||
320 | //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys. | 320 | //Ensure we don't retrieve a key that is greater than the current key. We only want equal keys. |
321 | void testKeyRange() | 321 | void testKeyRange() |
322 | { | 322 | { |
323 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); | 323 | Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); |
324 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); | 324 | auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); |
325 | auto db = transaction.openDatabase(); | 325 | auto db = transaction.openDatabase("test", nullptr, true); |
326 | db.write("sub1","value1"); | 326 | db.write("sub1","value1"); |
327 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { | 327 | int numValues = db.scan("sub", [&](const QByteArray &key, const QByteArray &value) -> bool { |
328 | return true; | 328 | return true; |