From 4a14a6fade947aa830d3f21598a4a6ba7316b933 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 19 Sep 2016 18:55:21 +0200 Subject: Refactored the query part of the entity reader into DataStoreQuery. DataStoreQuery now encapsulates the low-level query that operates directly on the storage. It no longer has access to the resource buffers, and is instantiated by the type implementation, so we can specialize the query alogorithm per type, but not per resource. This will allow us to implement the threading queries for the mailtype. --- common/domain/event.cpp | 13 +++++++++++++ common/domain/event.h | 2 ++ common/domain/folder.cpp | 11 +++++++++++ common/domain/folder.h | 2 ++ common/domain/mail.cpp | 13 +++++++++++++ common/domain/mail.h | 2 ++ 6 files changed, 43 insertions(+) (limited to 'common/domain') diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 0909bf1..dfbcb61 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp @@ -32,6 +32,8 @@ #include "../query.h" #include "../definitions.h" #include "../typeindex.h" +#include "entitybuffer.h" +#include "entity_generated.h" #include "event_generated.h" @@ -84,3 +86,14 @@ QSharedPointer::BufferBuilder> > T propertyMapper->addMapping(&BufferBuilder::add_attachment); return propertyMapper; } + +DataStoreQuery TypeImplementation::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) +{ + + auto mapper = initializeReadPropertyMapper(); + return DataStoreQuery(query, ApplicationDomain::getTypeName(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { + + const auto localBuffer = Sink::EntityBuffer::readBuffer(entity.local()); + return mapper->getProperty(property, localBuffer); + }); +} diff --git a/common/domain/event.h b/common/domain/event.h index 5315566..4ac572c 100644 --- a/common/domain/event.h +++ b/common/domain/event.h @@ -21,6 +21,7 @@ #include "applicationdomaintype.h" #include "storage.h" +#include "datastorequery.h" class ResultSet; class QByteArray; @@ -50,6 +51,7 @@ public: typedef Sink::ApplicationDomain::Buffer::Event Buffer; typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; static QSet indexedProperties(); + static DataStoreQuery prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); /** * Returns the potential result set based on the indexes. * diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp index ddb0c10..6d487b1 100644 --- a/common/domain/folder.cpp +++ b/common/domain/folder.cpp @@ -32,6 +32,8 @@ #include "../query.h" #include "../definitions.h" #include "../typeindex.h" +#include "entitybuffer.h" +#include "entity_generated.h" #include "folder_generated.h" @@ -88,3 +90,12 @@ QSharedPointer::BufferBuilder> > propertyMapper->addMapping(&BufferBuilder::add_specialpurpose); return propertyMapper; } + +DataStoreQuery TypeImplementation::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) +{ + auto mapper = initializeReadPropertyMapper(); + return DataStoreQuery(query, ApplicationDomain::getTypeName(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { + const auto localBuffer = Sink::EntityBuffer::readBuffer(entity.local()); + return mapper->getProperty(property, localBuffer); + }); +} diff --git a/common/domain/folder.h b/common/domain/folder.h index 6e066e1..77edc8a 100644 --- a/common/domain/folder.h +++ b/common/domain/folder.h @@ -21,6 +21,7 @@ #include "applicationdomaintype.h" #include "storage.h" +#include "datastorequery.h" class ResultSet; class QByteArray; @@ -44,6 +45,7 @@ class TypeImplementation { public: typedef Sink::ApplicationDomain::Buffer::Folder Buffer; typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; + static DataStoreQuery prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); static QSet indexedProperties(); static ResultSet queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, QByteArray &appliedSorting, Sink::Storage::Transaction &transaction); static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index 13e1305..bb5ad58 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp @@ -32,6 +32,8 @@ #include "../query.h" #include "../definitions.h" #include "../typeindex.h" +#include "entitybuffer.h" +#include "entity_generated.h" #include "mail_generated.h" @@ -110,3 +112,14 @@ QSharedPointer::BufferBuilder> > Ty propertyMapper->addMapping(&BufferBuilder::add_sent); return propertyMapper; } + +DataStoreQuery TypeImplementation::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) +{ + auto mapper = initializeReadPropertyMapper(); + return DataStoreQuery(query, ApplicationDomain::getTypeName(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { + + const auto localBuffer = Sink::EntityBuffer::readBuffer(entity.local()); + return mapper->getProperty(property, localBuffer); + }); +} + diff --git a/common/domain/mail.h b/common/domain/mail.h index ff169dd..d6af9c5 100644 --- a/common/domain/mail.h +++ b/common/domain/mail.h @@ -21,6 +21,7 @@ #include "applicationdomaintype.h" #include "storage.h" +#include "datastorequery.h" class ResultSet; class QByteArray; @@ -44,6 +45,7 @@ class TypeImplementation { public: typedef Sink::ApplicationDomain::Buffer::Mail Buffer; typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; + static DataStoreQuery prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); static QSet indexedProperties(); /** * Returns the potential result set based on the indexes. -- cgit v1.2.3