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. --- .../mailtransportresource.cpp | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'examples/mailtransportresource/mailtransportresource.cpp') diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 3ce9476..9a22c41 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #define ENTITY_TYPE_MAIL "mail" @@ -52,7 +53,7 @@ using namespace Sink; class MailtransportWriteback : public Sink::SourceWriteBack { public: - MailtransportWriteback(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier) : Sink::SourceWriteBack(resourceType, resourceInstanceIdentifier) + MailtransportWriteback(const Sink::ResourceContext &resourceContext) : Sink::SourceWriteBack(resourceContext) { } @@ -74,9 +75,9 @@ public: class MailtransportSynchronizer : public Sink::Synchronizer { public: - MailtransportSynchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier) - : Sink::Synchronizer(resourceType, resourceInstanceIdentifier), - mResourceInstanceIdentifier(resourceInstanceIdentifier) + MailtransportSynchronizer(const Sink::ResourceContext &resourceContext) + : Sink::Synchronizer(resourceContext), + mResourceInstanceIdentifier(resourceContext.instanceId()) { } @@ -112,10 +113,9 @@ public: { SinkLog() << " Synchronizing"; return KAsync::start([this](KAsync::Future future) { - Sink::Query query; QList toSend; SinkLog() << " Looking for mail"; - store().reader().query(query, [&](const ApplicationDomain::Mail &mail) -> bool { + store().readAll([&](const ApplicationDomain::Mail &mail) -> bool { SinkTrace() << "Found mail: " << mail.identifier(); if (!mail.getSent()) { toSend << mail; @@ -143,10 +143,10 @@ public: MailtransportResource::Settings mSettings; }; -MailtransportResource::MailtransportResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline) - : Sink::GenericResource(PLUGIN_NAME, instanceIdentifier, pipeline) +MailtransportResource::MailtransportResource(const Sink::ResourceContext &resourceContext, const QSharedPointer &pipeline) + : Sink::GenericResource(resourceContext, pipeline) { - auto config = ResourceConfig::getConfiguration(instanceIdentifier); + auto config = ResourceConfig::getConfiguration(resourceContext.instanceId()); mSettings = {config.value("server").toString(), config.value("username").toString(), config.value("cacert").toString(), @@ -154,11 +154,11 @@ MailtransportResource::MailtransportResource(const QByteArray &instanceIdentifie config.value("testmode").toBool() }; - auto synchronizer = QSharedPointer::create(PLUGIN_NAME, instanceIdentifier); + auto synchronizer = QSharedPointer::create(resourceContext); synchronizer->mSettings = mSettings; setupSynchronizer(synchronizer); - auto changereplay = QSharedPointer::create(PLUGIN_NAME, instanceIdentifier); + auto changereplay = QSharedPointer::create(resourceContext); changereplay->mSettings = mSettings; setupChangereplay(changereplay); @@ -168,14 +168,14 @@ MailtransportResource::MailtransportResource(const QByteArray &instanceIdentifie void MailtransportResource::removeFromDisk(const QByteArray &instanceIdentifier) { GenericResource::removeFromDisk(instanceIdentifier); - Sink::Storage(Sink::storageLocation(), instanceIdentifier + ".synchronization", Sink::Storage::ReadWrite).removeFromDisk(); + Sink::Storage::DataStore(Sink::storageLocation(), instanceIdentifier + ".synchronization", Sink::Storage::DataStore::ReadWrite).removeFromDisk(); } KAsync::Job MailtransportResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) { if (domainType == ENTITY_TYPE_MAIL) { if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { - auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/" + entityId; + auto path = resourceStorageLocation(mResourceContext.instanceId()) + "/test/" + entityId; if (QFileInfo::exists(path)) { return KAsync::null(); } @@ -191,14 +191,14 @@ MailtransportResourceFactory::MailtransportResourceFactory(QObject *parent) } -Sink::Resource *MailtransportResourceFactory::createResource(const QByteArray &instanceIdentifier) +Sink::Resource *MailtransportResourceFactory::createResource(const Sink::ResourceContext &context) { - return new MailtransportResource(instanceIdentifier); + return new MailtransportResource(context); } void MailtransportResourceFactory::registerFacades(Sink::FacadeFactory &factory) { - factory.registerFacade>>(PLUGIN_NAME); + factory.registerFacade>(PLUGIN_NAME); } void MailtransportResourceFactory::registerAdaptorFactories(Sink::AdaptorFactoryRegistry ®istry) -- cgit v1.2.3