summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-20 17:46:10 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-21 09:18:50 +0200
commit0c1f6da51631c0a573a44e2f93eb4012d52dfe5c (patch)
treecf3cd3bec9fabd44a7107f47e7b0b057880ecb61
parent9a03eb1a54c6289773bc1b8eb96181ed01553927 (diff)
downloadsink-0c1f6da51631c0a573a44e2f93eb4012d52dfe5c.tar.gz
sink-0c1f6da51631c0a573a44e2f93eb4012d52dfe5c.zip
Get access to properties in indexes.
-rw-r--r--common/domain/event.cpp5
-rw-r--r--common/domain/event.h2
-rw-r--r--common/domain/folder.cpp5
-rw-r--r--common/domain/folder.h2
-rw-r--r--common/domain/mail.cpp10
-rw-r--r--common/domain/mail.h2
-rw-r--r--common/domainadaptor.h52
-rw-r--r--common/domaintypeadaptorfactoryinterface.h3
-rw-r--r--common/mail/threadindexer.cpp6
-rw-r--r--common/storage/entitystore.cpp31
-rw-r--r--common/typeindex.cpp8
-rw-r--r--common/typeindex.h14
12 files changed, 114 insertions, 26 deletions
diff --git a/common/domain/event.cpp b/common/domain/event.cpp
index a8098b7..10c92bb 100644
--- a/common/domain/event.cpp
+++ b/common/domain/event.cpp
@@ -50,3 +50,8 @@ void TypeImplementation<Event>::configure(WritePropertyMapper<BufferBuilder> &pr
50 propertyMapper.addMapping<Event::Uid>(&BufferBuilder::add_uid); 50 propertyMapper.addMapping<Event::Uid>(&BufferBuilder::add_uid);
51 propertyMapper.addMapping<Event::Attachment>(&BufferBuilder::add_attachment); 51 propertyMapper.addMapping<Event::Attachment>(&BufferBuilder::add_attachment);
52} 52}
53
54void TypeImplementation<Event>::configure(IndexPropertyMapper &)
55{
56
57}
diff --git a/common/domain/event.h b/common/domain/event.h
index d85b9b3..b683f5f 100644
--- a/common/domain/event.h
+++ b/common/domain/event.h
@@ -26,6 +26,7 @@ template<typename T>
26class ReadPropertyMapper; 26class ReadPropertyMapper;
27template<typename T> 27template<typename T>
28class WritePropertyMapper; 28class WritePropertyMapper;
29class IndexPropertyMapper;
29 30
30class TypeIndex; 31class TypeIndex;
31 32
@@ -49,6 +50,7 @@ public:
49 static void configure(TypeIndex &); 50 static void configure(TypeIndex &);
50 static void configure(ReadPropertyMapper<Buffer> &); 51 static void configure(ReadPropertyMapper<Buffer> &);
51 static void configure(WritePropertyMapper<BufferBuilder> &); 52 static void configure(WritePropertyMapper<BufferBuilder> &);
53 static void configure(IndexPropertyMapper &indexPropertyMapper);
52}; 54};
53 55
54} 56}
diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp
index e6701ac..4bc2efb 100644
--- a/common/domain/folder.cpp
+++ b/common/domain/folder.cpp
@@ -51,3 +51,8 @@ void TypeImplementation<Folder>::configure(WritePropertyMapper<BufferBuilder> &p
51 propertyMapper.addMapping<Folder::Icon>(&BufferBuilder::add_icon); 51 propertyMapper.addMapping<Folder::Icon>(&BufferBuilder::add_icon);
52 propertyMapper.addMapping<Folder::SpecialPurpose>(&BufferBuilder::add_specialpurpose); 52 propertyMapper.addMapping<Folder::SpecialPurpose>(&BufferBuilder::add_specialpurpose);
53} 53}
54
55void TypeImplementation<Folder>::configure(IndexPropertyMapper &)
56{
57
58}
diff --git a/common/domain/folder.h b/common/domain/folder.h
index 3c83794..f232ab5 100644
--- a/common/domain/folder.h
+++ b/common/domain/folder.h
@@ -24,6 +24,7 @@ template<typename T>
24class ReadPropertyMapper; 24class ReadPropertyMapper;
25template<typename T> 25template<typename T>
26class WritePropertyMapper; 26class WritePropertyMapper;
27class IndexPropertyMapper;
27 28
28class TypeIndex; 29class TypeIndex;
29 30
@@ -43,6 +44,7 @@ public:
43 static void configure(TypeIndex &); 44 static void configure(TypeIndex &);
44 static void configure(ReadPropertyMapper<Buffer> &); 45 static void configure(ReadPropertyMapper<Buffer> &);
45 static void configure(WritePropertyMapper<BufferBuilder> &); 46 static void configure(WritePropertyMapper<BufferBuilder> &);
47 static void configure(IndexPropertyMapper &indexPropertyMapper);
46}; 48};
47 49
48} 50}
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp
index 8abe259..c1b0b34 100644
--- a/common/domain/mail.cpp
+++ b/common/domain/mail.cpp
@@ -27,6 +27,7 @@
27#include "entitybuffer.h" 27#include "entitybuffer.h"
28#include "entity_generated.h" 28#include "entity_generated.h"
29#include "mail/threadindexer.h" 29#include "mail/threadindexer.h"
30#include "domainadaptor.h"
30 31
31#include "mail_generated.h" 32#include "mail_generated.h"
32 33
@@ -53,6 +54,15 @@ void TypeImplementation<Mail>::configure(TypeIndex &index)
53 index.addSecondaryProperty<Mail::ThreadId, Mail::MessageId>(); 54 index.addSecondaryProperty<Mail::ThreadId, Mail::MessageId>();
54} 55}
55 56
57void TypeImplementation<Mail>::configure(IndexPropertyMapper &indexPropertyMapper)
58{
59 indexPropertyMapper.addIndexLookupProperty<Mail::ThreadId>([](TypeIndex &index, const ApplicationDomain::BufferAdaptor &entity) {
60 auto messageId = entity.getProperty(Mail::MessageId::name);
61 auto thread = index.secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId);
62 Q_ASSERT(!thread.isEmpty());
63 return thread.first();
64 });
65}
56 66
57void TypeImplementation<Mail>::configure(ReadPropertyMapper<Buffer> &propertyMapper) 67void TypeImplementation<Mail>::configure(ReadPropertyMapper<Buffer> &propertyMapper)
58{ 68{
diff --git a/common/domain/mail.h b/common/domain/mail.h
index c12976a..e052448 100644
--- a/common/domain/mail.h
+++ b/common/domain/mail.h
@@ -26,6 +26,7 @@ template<typename T>
26class ReadPropertyMapper; 26class ReadPropertyMapper;
27template<typename T> 27template<typename T>
28class WritePropertyMapper; 28class WritePropertyMapper;
29class IndexPropertyMapper;
29 30
30class TypeIndex; 31class TypeIndex;
31 32
@@ -44,6 +45,7 @@ public:
44 static void configure(TypeIndex &index); 45 static void configure(TypeIndex &index);
45 static void configure(ReadPropertyMapper<Buffer> &propertyMapper); 46 static void configure(ReadPropertyMapper<Buffer> &propertyMapper);
46 static void configure(WritePropertyMapper<BufferBuilder> &propertyMapper); 47 static void configure(WritePropertyMapper<BufferBuilder> &propertyMapper);
48 static void configure(IndexPropertyMapper &indexPropertyMapper);
47}; 49};
48 50
49} 51}
diff --git a/common/domainadaptor.h b/common/domainadaptor.h
index 0eb90b3..0f5bdc7 100644
--- a/common/domainadaptor.h
+++ b/common/domainadaptor.h
@@ -83,6 +83,42 @@ static void createBufferPartBuffer(const Sink::ApplicationDomain::ApplicationDom
83 } 83 }
84} 84}
85 85
86class IndexPropertyMapper
87{
88public:
89 typedef std::function<QVariant(TypeIndex &index, const Sink::ApplicationDomain::BufferAdaptor &adaptor)> Accessor;
90 virtual ~IndexPropertyMapper(){};
91
92 virtual QVariant getProperty(const QByteArray &key, TypeIndex &index, const Sink::ApplicationDomain::BufferAdaptor &adaptor) const
93 {
94 auto accessor = mReadAccessors.value(key);
95 Q_ASSERT(accessor);
96 if (!accessor) {
97 return QVariant();
98 }
99 return accessor(index, adaptor);
100 }
101
102 bool hasMapping(const QByteArray &key) const
103 {
104 return mReadAccessors.contains(key);
105 }
106
107 QList<QByteArray> availableProperties() const
108 {
109 return mReadAccessors.keys();
110 }
111
112 template<typename Property>
113 void addIndexLookupProperty(const Accessor &accessor)
114 {
115 mReadAccessors.insert(Property::name, accessor);
116 }
117
118private:
119 QHash<QByteArray, Accessor> mReadAccessors;
120};
121
86/** 122/**
87 * A generic adaptor implementation that uses a property mapper to read/write values. 123 * A generic adaptor implementation that uses a property mapper to read/write values.
88 */ 124 */
@@ -107,6 +143,8 @@ public:
107 return mResourceMapper->getProperty(key, mResourceBuffer); 143 return mResourceMapper->getProperty(key, mResourceBuffer);
108 } else if (mLocalBuffer && mLocalMapper->hasMapping(key)) { 144 } else if (mLocalBuffer && mLocalMapper->hasMapping(key)) {
109 return mLocalMapper->getProperty(key, mLocalBuffer); 145 return mLocalMapper->getProperty(key, mLocalBuffer);
146 } else if (mIndex && mIndexMapper->hasMapping(key)) {
147 return mIndexMapper->getProperty(key, *mIndex, *this);
110 } 148 }
111 SinkWarning() << "No mapping available for key " << key << mLocalBuffer << mResourceBuffer; 149 SinkWarning() << "No mapping available for key " << key << mLocalBuffer << mResourceBuffer;
112 return QVariant(); 150 return QVariant();
@@ -117,13 +155,15 @@ public:
117 */ 155 */
118 virtual QList<QByteArray> availableProperties() const Q_DECL_OVERRIDE 156 virtual QList<QByteArray> availableProperties() const Q_DECL_OVERRIDE
119 { 157 {
120 return mResourceMapper->availableProperties() + mLocalMapper->availableProperties(); 158 return mResourceMapper->availableProperties() + mLocalMapper->availableProperties() + mIndexMapper->availableProperties();
121 } 159 }
122 160
123 LocalBuffer const *mLocalBuffer; 161 LocalBuffer const *mLocalBuffer;
124 ResourceBuffer const *mResourceBuffer; 162 ResourceBuffer const *mResourceBuffer;
125 QSharedPointer<ReadPropertyMapper<LocalBuffer>> mLocalMapper; 163 QSharedPointer<ReadPropertyMapper<LocalBuffer>> mLocalMapper;
126 QSharedPointer<ReadPropertyMapper<ResourceBuffer>> mResourceMapper; 164 QSharedPointer<ReadPropertyMapper<ResourceBuffer>> mResourceMapper;
165 QSharedPointer<IndexPropertyMapper> mIndexMapper;
166 TypeIndex *mIndex;
127}; 167};
128 168
129/** 169/**
@@ -142,11 +182,14 @@ public:
142 : mLocalMapper(QSharedPointer<ReadPropertyMapper<LocalBuffer>>::create()), 182 : mLocalMapper(QSharedPointer<ReadPropertyMapper<LocalBuffer>>::create()),
143 mResourceMapper(QSharedPointer<ReadPropertyMapper<ResourceBuffer>>::create()), 183 mResourceMapper(QSharedPointer<ReadPropertyMapper<ResourceBuffer>>::create()),
144 mLocalWriteMapper(QSharedPointer<WritePropertyMapper<LocalBuilder>>::create()), 184 mLocalWriteMapper(QSharedPointer<WritePropertyMapper<LocalBuilder>>::create()),
145 mResourceWriteMapper(QSharedPointer<WritePropertyMapper<ResourceBuilder>>::create()) 185 mResourceWriteMapper(QSharedPointer<WritePropertyMapper<ResourceBuilder>>::create()),
186 mIndexMapper(QSharedPointer<IndexPropertyMapper>::create())
146 { 187 {
147 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mLocalMapper); 188 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mLocalMapper);
148 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mLocalWriteMapper); 189 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mLocalWriteMapper);
190 Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mIndexMapper);
149 } 191 }
192
150 virtual ~DomainTypeAdaptorFactory(){}; 193 virtual ~DomainTypeAdaptorFactory(){};
151 194
152 /** 195 /**
@@ -154,13 +197,15 @@ public:
154 * 197 *
155 * This returns by default a DatastoreBufferAdaptor initialized with the corresponding property mappers. 198 * This returns by default a DatastoreBufferAdaptor initialized with the corresponding property mappers.
156 */ 199 */
157 virtual QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> createAdaptor(const Sink::Entity &entity) Q_DECL_OVERRIDE 200 virtual QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> createAdaptor(const Sink::Entity &entity, TypeIndex *index = nullptr) Q_DECL_OVERRIDE
158 { 201 {
159 auto adaptor = QSharedPointer<DatastoreBufferAdaptor<LocalBuffer, ResourceBuffer>>::create(); 202 auto adaptor = QSharedPointer<DatastoreBufferAdaptor<LocalBuffer, ResourceBuffer>>::create();
160 adaptor->mLocalBuffer = Sink::EntityBuffer::readBuffer<LocalBuffer>(entity.local()); 203 adaptor->mLocalBuffer = Sink::EntityBuffer::readBuffer<LocalBuffer>(entity.local());
161 adaptor->mLocalMapper = mLocalMapper; 204 adaptor->mLocalMapper = mLocalMapper;
162 adaptor->mResourceBuffer = Sink::EntityBuffer::readBuffer<ResourceBuffer>(entity.resource()); 205 adaptor->mResourceBuffer = Sink::EntityBuffer::readBuffer<ResourceBuffer>(entity.resource());
163 adaptor->mResourceMapper = mResourceMapper; 206 adaptor->mResourceMapper = mResourceMapper;
207 adaptor->mIndexMapper = mIndexMapper;
208 adaptor->mIndex = index;
164 return adaptor; 209 return adaptor;
165 } 210 }
166 211
@@ -198,4 +243,5 @@ protected:
198 QSharedPointer<ReadPropertyMapper<ResourceBuffer>> mResourceMapper; 243 QSharedPointer<ReadPropertyMapper<ResourceBuffer>> mResourceMapper;
199 QSharedPointer<WritePropertyMapper<LocalBuilder>> mLocalWriteMapper; 244 QSharedPointer<WritePropertyMapper<LocalBuilder>> mLocalWriteMapper;
200 QSharedPointer<WritePropertyMapper<ResourceBuilder>> mResourceWriteMapper; 245 QSharedPointer<WritePropertyMapper<ResourceBuilder>> mResourceWriteMapper;
246 QSharedPointer<IndexPropertyMapper> mIndexMapper;
201}; 247};
diff --git a/common/domaintypeadaptorfactoryinterface.h b/common/domaintypeadaptorfactoryinterface.h
index 8829c87..4becbe5 100644
--- a/common/domaintypeadaptorfactoryinterface.h
+++ b/common/domaintypeadaptorfactoryinterface.h
@@ -20,6 +20,7 @@
20 20
21#include <QSharedPointer> 21#include <QSharedPointer>
22 22
23class TypeIndex;
23namespace Sink { 24namespace Sink {
24namespace ApplicationDomain { 25namespace ApplicationDomain {
25class BufferAdaptor; 26class BufferAdaptor;
@@ -37,7 +38,7 @@ class DomainTypeAdaptorFactoryInterface
37public: 38public:
38 typedef QSharedPointer<DomainTypeAdaptorFactoryInterface> Ptr; 39 typedef QSharedPointer<DomainTypeAdaptorFactoryInterface> Ptr;
39 virtual ~DomainTypeAdaptorFactoryInterface(){}; 40 virtual ~DomainTypeAdaptorFactoryInterface(){};
40 virtual QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> createAdaptor(const Sink::Entity &entity) = 0; 41 virtual QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> createAdaptor(const Sink::Entity &entity, TypeIndex *index = nullptr) = 0;
41 42
42 /* 43 /*
43 * Creates a buffer from @param domainType 44 * Creates a buffer from @param domainType
diff --git a/common/mail/threadindexer.cpp b/common/mail/threadindexer.cpp
index 4a18625..17ee31e 100644
--- a/common/mail/threadindexer.cpp
+++ b/common/mail/threadindexer.cpp
@@ -91,16 +91,16 @@ void ThreadIndexer::updateThreadingIndex(const QByteArray &identifier, const App
91 QVector<QByteArray> thread; 91 QVector<QByteArray> thread;
92 92
93 //a child already registered our thread. 93 //a child already registered our thread.
94 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId, transaction); 94 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(messageId);
95 95
96 //If parent is already available, add to thread of parent 96 //If parent is already available, add to thread of parent
97 if (thread.isEmpty() && parentMessageId.isValid()) { 97 if (thread.isEmpty() && parentMessageId.isValid()) {
98 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId, transaction); 98 thread = index().secondaryLookup<Mail::MessageId, Mail::ThreadId>(parentMessageId);
99 SinkTrace() << "Found parent"; 99 SinkTrace() << "Found parent";
100 } 100 }
101 if (thread.isEmpty()) { 101 if (thread.isEmpty()) {
102 //Try to lookup the thread by subject: 102 //Try to lookup the thread by subject:
103 thread = index().secondaryLookup<Mail::Subject, Mail::ThreadId>(normalizedSubject, transaction); 103 thread = index().secondaryLookup<Mail::Subject, Mail::ThreadId>(normalizedSubject);
104 if (thread.isEmpty()) { 104 if (thread.isEmpty()) {
105 SinkTrace() << "Created a new thread "; 105 SinkTrace() << "Created a new thread ";
106 thread << QUuid::createUuid().toByteArray(); 106 thread << QUuid::createUuid().toByteArray();
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp
index f7f235e..dce2fc6 100644
--- a/common/storage/entitystore.cpp
+++ b/common/storage/entitystore.cpp
@@ -69,9 +69,8 @@ public:
69 /* return *index; */ 69 /* return *index; */
70 /* } */ 70 /* } */
71 71
72 TypeIndex &typeIndex(const QByteArray &type) 72 TypeIndex &cachedIndex(const QByteArray &type)
73 { 73 {
74 /* return applyType<typeIndex>(type); */
75 if (indexByType.contains(type)) { 74 if (indexByType.contains(type)) {
76 return *indexByType.value(type); 75 return *indexByType.value(type);
77 } 76 }
@@ -92,7 +91,19 @@ public:
92 } 91 }
93 indexByType.insert(type, index); 92 indexByType.insert(type, index);
94 return *index; 93 return *index;
94 TypeIndex &typeIndex(const QByteArray &type)
95 {
96 auto &index = cachedIndex(type);
97 index.mTransaction = &transaction;
98 return index;
99 }
100
101 ApplicationDomain::ApplicationDomainType createApplicationDomainType(const QByteArray &type, const QByteArray &uid, qint64 revision, const EntityBuffer &buffer)
102 {
103 auto adaptor = resourceContext.adaptorFactory(type).createAdaptor(buffer.entity(), &typeIndex(type));
104 return ApplicationDomain::ApplicationDomainType{resourceContext.instanceId(), uid, revision, adaptor};
95 } 105 }
106
96}; 107};
97 108
98EntityStore::EntityStore(const ResourceContext &context) 109EntityStore::EntityStore(const ResourceContext &context)
@@ -373,17 +384,16 @@ void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, cons
373void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) 384void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback)
374{ 385{
375 readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { 386 readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) {
376 auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity()); 387 //TODO cache max revision for the duration of the transaction.
377 callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor}); 388 callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer));
378 }); 389 });
379} 390}
380 391
381void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &, Sink::Operation)> callback) 392void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &, Sink::Operation)> callback)
382{ 393{
383 readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { 394 readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) {
384 auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity());
385 //TODO cache max revision for the duration of the transaction. 395 //TODO cache max revision for the duration of the transaction.
386 callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor}, buffer.operation()); 396 callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer), buffer.operation());
387 }); 397 });
388} 398}
389 399
@@ -410,8 +420,7 @@ void EntityStore::readEntity(const QByteArray &type, const QByteArray &key, cons
410void EntityStore::readEntity(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) 420void EntityStore::readEntity(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback)
411{ 421{
412 readEntity(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { 422 readEntity(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) {
413 auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity()); 423 callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer));
414 callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor});
415 }); 424 });
416} 425}
417 426
@@ -432,8 +441,7 @@ void EntityStore::readAll(const QByteArray &type, const std::function<void(const
432 [=](const QByteArray &key, const QByteArray &value) -> bool { 441 [=](const QByteArray &key, const QByteArray &value) -> bool {
433 auto uid = DataStore::uidFromKey(key); 442 auto uid = DataStore::uidFromKey(key);
434 auto buffer = Sink::EntityBuffer{value.data(), value.size()}; 443 auto buffer = Sink::EntityBuffer{value.data(), value.size()};
435 auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity()); 444 callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer));
436 callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor});
437 return true; 445 return true;
438 }, 446 },
439 [&](const DataStore::Error &error) { SinkWarning() << "Error during query: " << error.message; }); 447 [&](const DataStore::Error &error) { SinkWarning() << "Error during query: " << error.message; });
@@ -480,8 +488,7 @@ void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qi
480void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) 488void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback)
481{ 489{
482 readPrevious(type, uid, revision, [&](const QByteArray &uid, const EntityBuffer &buffer) { 490 readPrevious(type, uid, revision, [&](const QByteArray &uid, const EntityBuffer &buffer) {
483 auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity()); 491 callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer));
484 callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor});
485 }); 492 });
486} 493}
487 494
diff --git a/common/typeindex.cpp b/common/typeindex.cpp
index 8f5de4f..036b662 100644
--- a/common/typeindex.cpp
+++ b/common/typeindex.cpp
@@ -238,10 +238,10 @@ void TypeIndex::index<QString, QByteArray>(const QByteArray &leftName, const QBy
238} 238}
239 239
240template <> 240template <>
241QVector<QByteArray> TypeIndex::secondaryLookup<QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) 241QVector<QByteArray> TypeIndex::secondaryLookup<QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value)
242{ 242{
243 QVector<QByteArray> keys; 243 QVector<QByteArray> keys;
244 Index index(indexName(leftName + rightName), transaction); 244 Index index(indexName(leftName + rightName), *mTransaction);
245 const auto lookupKey = getByteArray(value); 245 const auto lookupKey = getByteArray(value);
246 index.lookup( 246 index.lookup(
247 lookupKey, [&](const QByteArray &value) { keys << value; }, [=](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << value; }); 247 lookupKey, [&](const QByteArray &value) { keys << value; }, [=](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << value; });
@@ -250,10 +250,10 @@ QVector<QByteArray> TypeIndex::secondaryLookup<QByteArray>(const QByteArray &lef
250} 250}
251 251
252template <> 252template <>
253QVector<QByteArray> TypeIndex::secondaryLookup<QString>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) 253QVector<QByteArray> TypeIndex::secondaryLookup<QString>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value)
254{ 254{
255 QVector<QByteArray> keys; 255 QVector<QByteArray> keys;
256 Index index(indexName(leftName + rightName), transaction); 256 Index index(indexName(leftName + rightName), *mTransaction);
257 const auto lookupKey = getByteArray(value); 257 const auto lookupKey = getByteArray(value);
258 index.lookup( 258 index.lookup(
259 lookupKey, [&](const QByteArray &value) { keys << value; }, [=](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << value; }); 259 lookupKey, [&](const QByteArray &value) { keys << value; }, [=](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << value; });
diff --git a/common/typeindex.h b/common/typeindex.h
index 041e04a..3cffb1e 100644
--- a/common/typeindex.h
+++ b/common/typeindex.h
@@ -25,6 +25,12 @@
25#include "indexer.h" 25#include "indexer.h"
26#include <QByteArray> 26#include <QByteArray>
27 27
28namespace Sink {
29namespace Storage {
30 class EntityStore;
31}
32}
33
28class TypeIndex 34class TypeIndex
29{ 35{
30public: 36public:
@@ -66,13 +72,13 @@ public:
66 QVector<QByteArray> lookup(const QByteArray &property, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction); 72 QVector<QByteArray> lookup(const QByteArray &property, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction);
67 73
68 template <typename Left, typename Right> 74 template <typename Left, typename Right>
69 QVector<QByteArray> secondaryLookup(const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) 75 QVector<QByteArray> secondaryLookup(const QVariant &value)
70 { 76 {
71 return secondaryLookup<typename Left::Type>(Left::name, Right::name, value, transaction); 77 return secondaryLookup<typename Left::Type>(Left::name, Right::name, value);
72 } 78 }
73 79
74 template <typename Type> 80 template <typename Type>
75 QVector<QByteArray> secondaryLookup(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction); 81 QVector<QByteArray> secondaryLookup(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value);
76 82
77 template <typename Left, typename Right> 83 template <typename Left, typename Right>
78 void index(const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction) 84 void index(const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction)
@@ -85,6 +91,7 @@ public:
85 91
86 92
87private: 93private:
94 friend class Sink::Storage::EntityStore;
88 QByteArray indexName(const QByteArray &property, const QByteArray &sortProperty = QByteArray()) const; 95 QByteArray indexName(const QByteArray &property, const QByteArray &sortProperty = QByteArray()) const;
89 QByteArray mType; 96 QByteArray mType;
90 SINK_DEBUG_COMPONENT(mType) 97 SINK_DEBUG_COMPONENT(mType)
@@ -93,6 +100,7 @@ private:
93 //<Property, ResultProperty> 100 //<Property, ResultProperty>
94 QMap<QByteArray, QByteArray> mSecondaryProperties; 101 QMap<QByteArray, QByteArray> mSecondaryProperties;
95 QList<Sink::Indexer::Ptr> mCustomIndexer; 102 QList<Sink::Indexer::Ptr> mCustomIndexer;
103 Sink::Storage::DataStore::Transaction *mTransaction;
96 QHash<QByteArray, std::function<void(const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction)>> mIndexer; 104 QHash<QByteArray, std::function<void(const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction)>> mIndexer;
97 QHash<QByteArray, std::function<void(const QByteArray &identifier, const QVariant &value, const QVariant &sortValue, Sink::Storage::DataStore::Transaction &transaction)>> mSortIndexer; 105 QHash<QByteArray, std::function<void(const QByteArray &identifier, const QVariant &value, const QVariant &sortValue, Sink::Storage::DataStore::Transaction &transaction)>> mSortIndexer;
98}; 106};