From 237b9ae4113e7a9f489632296941becb71afdb45 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 16 Oct 2016 14:55:20 +0200 Subject: Refactor how the storage is used. This is the initial refactoring to improve how we deal with the storage. It does a couple of things: * Rename Sink::Storage to Sink::Storage::DataStore to free up the Sink::Storage namespace * Introduce a Sink::ResourceContext to have a single object that can be passed around containing everything that is necessary to operate on a resource. This is a lot better than the multiple separate parameters that we used to pass around all over the place, while still allowing for dependency injection for tests. * Tie storage access together using the new EntityStore that directly works with ApplicationDomainTypes. This gives us a central place where main storage, indexes and buffer adaptors are tied together, which will also give us a place to implement external indexes, such as a fulltextindex using xapian. * Use ApplicationDomainTypes as the default way to pass around entities. Instead of using various ways to pass around entities (buffers, buffer adaptors, ApplicationDomainTypes), only use a single way. The old approach was confusing, and was only done as: * optimization; really shouldn't be necessary and otherwise I'm sure we can find better ways to optimize ApplicationDomainType itself. * a way to account for entities that have multiple buffers, a concept that I no longer deem relevant. While this commit does the bulk of the work to get there, the following commits will refactor more stuff to get things back to normal. --- common/messagequeue.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'common/messagequeue.cpp') diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp index e050bcd..0fcbf99 100644 --- a/common/messagequeue.cpp +++ b/common/messagequeue.cpp @@ -5,7 +5,7 @@ SINK_DEBUG_AREA("messagequeue") -MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) : mStorage(storageRoot, name, Sink::Storage::ReadWrite) +MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) : mStorage(storageRoot, name, Sink::Storage::DataStore::ReadWrite) { } @@ -27,13 +27,13 @@ void MessageQueue::startTransaction() return; } processRemovals(); - mWriteTransaction = mStorage.createTransaction(Sink::Storage::ReadWrite); + mWriteTransaction = mStorage.createTransaction(Sink::Storage::DataStore::ReadWrite); } void MessageQueue::commit() { mWriteTransaction.commit(); - mWriteTransaction = Sink::Storage::Transaction(); + mWriteTransaction = Sink::Storage::DataStore::Transaction(); processRemovals(); emit messageReady(); } @@ -45,10 +45,10 @@ void MessageQueue::enqueue(const QByteArray &value) implicitTransaction = true; startTransaction(); } - const qint64 revision = Sink::Storage::maxRevision(mWriteTransaction) + 1; + const qint64 revision = Sink::Storage::DataStore::maxRevision(mWriteTransaction) + 1; const QByteArray key = QString("%1").arg(revision).toUtf8(); mWriteTransaction.openDatabase().write(key, value); - Sink::Storage::setMaxRevision(mWriteTransaction, revision); + Sink::Storage::DataStore::setMaxRevision(mWriteTransaction, revision); if (implicitTransaction) { commit(); } @@ -59,7 +59,7 @@ void MessageQueue::processRemovals() if (mWriteTransaction) { return; } - auto transaction = mStorage.createTransaction(Sink::Storage::ReadWrite); + auto transaction = mStorage.createTransaction(Sink::Storage::DataStore::ReadWrite); for (const auto &key : mPendingRemoval) { transaction.openDatabase().remove(key); } @@ -82,7 +82,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(Sink::Storage::ReadOnly) + mStorage.createTransaction(Sink::Storage::DataStore::ReadOnly) .openDatabase() .scan("", [this, resultHandler, resultCount, &count, maxBatchSize, &waitCondition](const QByteArray &key, const QByteArray &value) -> bool { @@ -101,7 +101,7 @@ KAsync::Job MessageQueue::dequeueBatch(int maxBatchSize, const std::functi } return false; }, - [](const Sink::Storage::Error &error) { + [](const Sink::Storage::DataStore::Error &error) { SinkError() << "Error while retrieving value" << error.message; // errorHandler(Error(error.store, error.code, error.message)); }); @@ -126,7 +126,7 @@ KAsync::Job MessageQueue::dequeueBatch(int maxBatchSize, const std::functi bool MessageQueue::isEmpty() { int count = 0; - auto t = mStorage.createTransaction(Sink::Storage::ReadOnly); + auto t = mStorage.createTransaction(Sink::Storage::DataStore::ReadOnly); auto db = t.openDatabase(); if (db) { db.scan("", @@ -137,7 +137,7 @@ bool MessageQueue::isEmpty() } return true; }, - [](const Sink::Storage::Error &error) { SinkError() << "Error while checking if empty" << error.message; }); + [](const Sink::Storage::DataStore::Error &error) { SinkError() << "Error while checking if empty" << error.message; }); } return count == 0; } -- cgit v1.2.3