diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-19 18:55:21 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-09-19 18:55:21 +0200 |
commit | 4a14a6fade947aa830d3f21598a4a6ba7316b933 (patch) | |
tree | c6b340bf1c6284e5501d371f65b58e3a69391a26 /common/domain | |
parent | 1deac558af4b1c9f04352ede7f8e172f11a70a6b (diff) | |
download | sink-4a14a6fade947aa830d3f21598a4a6ba7316b933.tar.gz sink-4a14a6fade947aa830d3f21598a4a6ba7316b933.zip |
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.
Diffstat (limited to 'common/domain')
-rw-r--r-- | common/domain/event.cpp | 13 | ||||
-rw-r--r-- | common/domain/event.h | 2 | ||||
-rw-r--r-- | common/domain/folder.cpp | 11 | ||||
-rw-r--r-- | common/domain/folder.h | 2 | ||||
-rw-r--r-- | common/domain/mail.cpp | 13 | ||||
-rw-r--r-- | common/domain/mail.h | 2 |
6 files changed, 43 insertions, 0 deletions
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 @@ | |||
32 | #include "../query.h" | 32 | #include "../query.h" |
33 | #include "../definitions.h" | 33 | #include "../definitions.h" |
34 | #include "../typeindex.h" | 34 | #include "../typeindex.h" |
35 | #include "entitybuffer.h" | ||
36 | #include "entity_generated.h" | ||
35 | 37 | ||
36 | #include "event_generated.h" | 38 | #include "event_generated.h" |
37 | 39 | ||
@@ -84,3 +86,14 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Event>::BufferBuilder> > T | |||
84 | propertyMapper->addMapping<Event::Attachment>(&BufferBuilder::add_attachment); | 86 | propertyMapper->addMapping<Event::Attachment>(&BufferBuilder::add_attachment); |
85 | return propertyMapper; | 87 | return propertyMapper; |
86 | } | 88 | } |
89 | |||
90 | DataStoreQuery TypeImplementation<Event>::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) | ||
91 | { | ||
92 | |||
93 | auto mapper = initializeReadPropertyMapper(); | ||
94 | return DataStoreQuery(query, ApplicationDomain::getTypeName<Event>(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { | ||
95 | |||
96 | const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); | ||
97 | return mapper->getProperty(property, localBuffer); | ||
98 | }); | ||
99 | } | ||
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 @@ | |||
21 | #include "applicationdomaintype.h" | 21 | #include "applicationdomaintype.h" |
22 | 22 | ||
23 | #include "storage.h" | 23 | #include "storage.h" |
24 | #include "datastorequery.h" | ||
24 | 25 | ||
25 | class ResultSet; | 26 | class ResultSet; |
26 | class QByteArray; | 27 | class QByteArray; |
@@ -50,6 +51,7 @@ public: | |||
50 | typedef Sink::ApplicationDomain::Buffer::Event Buffer; | 51 | typedef Sink::ApplicationDomain::Buffer::Event Buffer; |
51 | typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; | 52 | typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; |
52 | static QSet<QByteArray> indexedProperties(); | 53 | static QSet<QByteArray> indexedProperties(); |
54 | static DataStoreQuery prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); | ||
53 | /** | 55 | /** |
54 | * Returns the potential result set based on the indexes. | 56 | * Returns the potential result set based on the indexes. |
55 | * | 57 | * |
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 @@ | |||
32 | #include "../query.h" | 32 | #include "../query.h" |
33 | #include "../definitions.h" | 33 | #include "../definitions.h" |
34 | #include "../typeindex.h" | 34 | #include "../typeindex.h" |
35 | #include "entitybuffer.h" | ||
36 | #include "entity_generated.h" | ||
35 | 37 | ||
36 | #include "folder_generated.h" | 38 | #include "folder_generated.h" |
37 | 39 | ||
@@ -88,3 +90,12 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Folder>::BufferBuilder> > | |||
88 | propertyMapper->addMapping<Folder::SpecialPurpose>(&BufferBuilder::add_specialpurpose); | 90 | propertyMapper->addMapping<Folder::SpecialPurpose>(&BufferBuilder::add_specialpurpose); |
89 | return propertyMapper; | 91 | return propertyMapper; |
90 | } | 92 | } |
93 | |||
94 | DataStoreQuery TypeImplementation<Folder>::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) | ||
95 | { | ||
96 | auto mapper = initializeReadPropertyMapper(); | ||
97 | return DataStoreQuery(query, ApplicationDomain::getTypeName<Folder>(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { | ||
98 | const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); | ||
99 | return mapper->getProperty(property, localBuffer); | ||
100 | }); | ||
101 | } | ||
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 @@ | |||
21 | #include "applicationdomaintype.h" | 21 | #include "applicationdomaintype.h" |
22 | 22 | ||
23 | #include "storage.h" | 23 | #include "storage.h" |
24 | #include "datastorequery.h" | ||
24 | 25 | ||
25 | class ResultSet; | 26 | class ResultSet; |
26 | class QByteArray; | 27 | class QByteArray; |
@@ -44,6 +45,7 @@ class TypeImplementation<Sink::ApplicationDomain::Folder> { | |||
44 | public: | 45 | public: |
45 | typedef Sink::ApplicationDomain::Buffer::Folder Buffer; | 46 | typedef Sink::ApplicationDomain::Buffer::Folder Buffer; |
46 | typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; | 47 | typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; |
48 | static DataStoreQuery prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); | ||
47 | static QSet<QByteArray> indexedProperties(); | 49 | static QSet<QByteArray> indexedProperties(); |
48 | static ResultSet queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting, Sink::Storage::Transaction &transaction); | 50 | static ResultSet queryIndexes(const Sink::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting, Sink::Storage::Transaction &transaction); |
49 | static void index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction); | 51 | 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 @@ | |||
32 | #include "../query.h" | 32 | #include "../query.h" |
33 | #include "../definitions.h" | 33 | #include "../definitions.h" |
34 | #include "../typeindex.h" | 34 | #include "../typeindex.h" |
35 | #include "entitybuffer.h" | ||
36 | #include "entity_generated.h" | ||
35 | 37 | ||
36 | #include "mail_generated.h" | 38 | #include "mail_generated.h" |
37 | 39 | ||
@@ -110,3 +112,14 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Mail>::BufferBuilder> > Ty | |||
110 | propertyMapper->addMapping<Mail::Sent>(&BufferBuilder::add_sent); | 112 | propertyMapper->addMapping<Mail::Sent>(&BufferBuilder::add_sent); |
111 | return propertyMapper; | 113 | return propertyMapper; |
112 | } | 114 | } |
115 | |||
116 | DataStoreQuery TypeImplementation<Mail>::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) | ||
117 | { | ||
118 | auto mapper = initializeReadPropertyMapper(); | ||
119 | return DataStoreQuery(query, ApplicationDomain::getTypeName<Mail>(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { | ||
120 | |||
121 | const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); | ||
122 | return mapper->getProperty(property, localBuffer); | ||
123 | }); | ||
124 | } | ||
125 | |||
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 @@ | |||
21 | #include "applicationdomaintype.h" | 21 | #include "applicationdomaintype.h" |
22 | 22 | ||
23 | #include "storage.h" | 23 | #include "storage.h" |
24 | #include "datastorequery.h" | ||
24 | 25 | ||
25 | class ResultSet; | 26 | class ResultSet; |
26 | class QByteArray; | 27 | class QByteArray; |
@@ -44,6 +45,7 @@ class TypeImplementation<Sink::ApplicationDomain::Mail> { | |||
44 | public: | 45 | public: |
45 | typedef Sink::ApplicationDomain::Buffer::Mail Buffer; | 46 | typedef Sink::ApplicationDomain::Buffer::Mail Buffer; |
46 | typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; | 47 | typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; |
48 | static DataStoreQuery prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction); | ||
47 | static QSet<QByteArray> indexedProperties(); | 49 | static QSet<QByteArray> indexedProperties(); |
48 | /** | 50 | /** |
49 | * Returns the potential result set based on the indexes. | 51 | * Returns the potential result set based on the indexes. |