From 9c3d000e11d3b1fc6c6c205fe9e7ea26c11092c6 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 23 Aug 2015 23:57:09 +0200 Subject: Removed convenience API --- common/entitystorage.cpp | 2 +- common/messagequeue.cpp | 6 +++--- common/pipeline.cpp | 8 ++++---- common/pipeline.h | 2 +- common/storage.h | 7 ------- common/storage_common.cpp | 4 ++-- common/storage_lmdb.cpp | 34 ---------------------------------- 7 files changed, 11 insertions(+), 52 deletions(-) (limited to 'common') diff --git a/common/entitystorage.cpp b/common/entitystorage.cpp index 22fd9e6..8a3391e 100644 --- a/common/entitystorage.cpp +++ b/common/entitystorage.cpp @@ -21,7 +21,7 @@ static void scan(const Akonadi2::Storage::Transaction &transaction, const QByteArray &key, std::function callback) { - transaction.scan(key, [=](const QByteArray &key, const QByteArray &value) -> bool { + transaction.openDatabase().scan(key, [=](const QByteArray &key, const QByteArray &value) -> bool { //Skip internals if (Akonadi2::Storage::isInternalKey(key)) { return true; diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp index f8bcd46..8e3d7d7 100644 --- a/common/messagequeue.cpp +++ b/common/messagequeue.cpp @@ -76,7 +76,7 @@ void MessageQueue::enqueue(const QByteArray &value) } const qint64 revision = Akonadi2::Storage::maxRevision(mWriteTransaction) + 1; const QByteArray key = QString("%1").arg(revision).toUtf8(); - mWriteTransaction.write(key, value); + mWriteTransaction.openDatabase().write(key, value); Akonadi2::Storage::setMaxRevision(mWriteTransaction, revision); if (implicitTransaction) { commit(); @@ -90,7 +90,7 @@ void MessageQueue::processRemovals() } auto transaction = std::move(mStorage.createTransaction(Akonadi2::Storage::ReadWrite)); for (const auto &key : mPendingRemoval) { - transaction.remove(key); + transaction.openDatabase().remove(key); } transaction.commit(); mPendingRemoval.clear(); @@ -117,7 +117,7 @@ KAsync::Job MessageQueue::dequeueBatch(int maxBatchSize, const std::functi return KAsync::start([this, maxBatchSize, resultHandler, resultCount](KAsync::Future &future) { int count = 0; QList > waitCondition; - mStorage.createTransaction(Akonadi2::Storage::ReadOnly).scan("", [this, resultHandler, resultCount, &count, maxBatchSize, &waitCondition](const QByteArray &key, const QByteArray &value) -> bool { + mStorage.createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan("", [this, resultHandler, resultCount, &count, maxBatchSize, &waitCondition](const QByteArray &key, const QByteArray &value) -> bool { if (Akonadi2::Storage::isInternalKey(key) || mPendingRemoval.contains(key)) { return true; } diff --git a/common/pipeline.cpp b/common/pipeline.cpp index c5e36ee..8ef6187 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -165,7 +165,7 @@ KAsync::Job Pipeline::newEntity(void const *command, size_t size) flatbuffers::FlatBufferBuilder fbb; EntityBuffer::assembleEntityBuffer(fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize(), entity->resource()->Data(), entity->resource()->size(), entity->local()->Data(), entity->local()->size()); - d->transaction.write(key, QByteArray::fromRawData(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize())); + d->transaction.openDatabase().write(key, QByteArray::fromRawData(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize())); Akonadi2::Storage::setMaxRevision(d->transaction, newRevision); Log() << "Pipeline: wrote entity: " << key << newRevision; @@ -220,7 +220,7 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) auto diff = adaptorFactory->createAdaptor(*diffEntity); QSharedPointer current; - storage().createTransaction(Akonadi2::Storage::ReadOnly).scan(key, [¤t, adaptorFactory](const QByteArray &key, const QByteArray &data) -> bool { + storage().createTransaction(Akonadi2::Storage::ReadOnly).openDatabase().scan(key, [¤t, adaptorFactory](const QByteArray &key, const QByteArray &data) -> bool { Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); if (!buffer.isValid()) { Warning() << "Read invalid buffer from disk"; @@ -265,7 +265,7 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) adaptorFactory->createBuffer(*newObject, fbb, metadataFbb.GetBufferPointer(), metadataFbb.GetSize()); //TODO don't overwrite the old entry, but instead store a new revision - d->transaction.write(key, QByteArray::fromRawData(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize())); + d->transaction.openDatabase().write(key, QByteArray::fromRawData(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize())); Akonadi2::Storage::setMaxRevision(d->transaction, newRevision); return KAsync::start([this, key, entityType, newRevision](KAsync::Future &future) { @@ -296,7 +296,7 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) const QByteArray key = QByteArray(reinterpret_cast(deleteEntity->entityId()->Data()), deleteEntity->entityId()->size()); //TODO instead of deleting the entry, a new revision should be created that marks the entity as deleted - d->transaction.remove(key); + d->transaction.openDatabase().remove(key); Akonadi2::Storage::setMaxRevision(d->transaction, newRevision); Log() << "Pipeline: deleted entity: "<< newRevision; diff --git a/common/pipeline.h b/common/pipeline.h index fee6a5e..a3b3735 100644 --- a/common/pipeline.h +++ b/common/pipeline.h @@ -142,7 +142,7 @@ public: void process(const PipelineState &state, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - transaction.scan(state.key(), [this, &state, &transaction](const QByteArray &key, const QByteArray &value) -> bool { + transaction.openDatabase().scan(state.key(), [this, &state, &transaction](const QByteArray &key, const QByteArray &value) -> bool { auto entity = Akonadi2::GetEntity(value); mFunction(state, *entity, transaction); processingCompleted(state); diff --git a/common/storage.h b/common/storage.h index 8a2e51f..191f535 100644 --- a/common/storage.h +++ b/common/storage.h @@ -130,13 +130,6 @@ public: return (d != nullptr); } - bool write(const QByteArray &key, const QByteArray &value, const std::function &errorHandler = std::function()); - - void remove(const QByteArray &key, - const std::function &errorHandler = std::function()); - int scan(const QByteArray &k, - const std::function &resultHandler, - const std::function &errorHandler = std::function()) const; private: Transaction(Transaction& other); Transaction& operator=(Transaction& other); diff --git a/common/storage_common.cpp b/common/storage_common.cpp index 4de585d..a506cf8 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp @@ -62,7 +62,7 @@ void Storage::setMaxRevision(qint64 revision) void Storage::setMaxRevision(Akonadi2::Storage::Transaction &transaction, qint64 revision) { - transaction.write("__internal_maxRevision", QByteArray::number(revision)); + transaction.openDatabase().write("__internal_maxRevision", QByteArray::number(revision)); } qint64 Storage::maxRevision() @@ -74,7 +74,7 @@ qint64 Storage::maxRevision() qint64 Storage::maxRevision(const Akonadi2::Storage::Transaction &transaction) { qint64 r = 0; - transaction.scan("__internal_maxRevision", [&](const QByteArray &, const QByteArray &revision) -> bool { + transaction.openDatabase().scan("__internal_maxRevision", [&](const QByteArray &, const QByteArray &revision) -> bool { r = revision.toLongLong(); return false; }, [](const Error &error){ diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 7fed830..a048a71 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp @@ -337,40 +337,6 @@ Storage::NamedDatabase Storage::Transaction::openDatabase(const QByteArray &db, return Storage::NamedDatabase(p); } -bool Storage::Transaction::write(const QByteArray &key, const QByteArray &value, const std::function &errorHandler) -{ - auto eHandler = [this, errorHandler](const Storage::Error &error) { - d->error = true; - errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); - }; - openDatabase("default", eHandler).write(key, value, eHandler); - d->implicitCommit = true; - - return !d->error; -} - -void Storage::Transaction::remove(const QByteArray &k, - const std::function &errorHandler) -{ - auto eHandler = [this, errorHandler](const Storage::Error &error) { - d->error = true; - errorHandler ? errorHandler(error) : d->defaultErrorHandler(error); - }; - openDatabase("default", eHandler).remove(k, eHandler); - d->implicitCommit = true; -} - -int Storage::Transaction::scan(const QByteArray &k, - const std::function &resultHandler, - const std::function &errorHandler) const -{ - auto db = openDatabase("default", std::function()); - if (db) { - return db.scan(k, resultHandler, errorHandler); - } - return 0; -} - -- cgit v1.2.3