diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dummyresource/facade.cpp | 61 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 28 |
2 files changed, 20 insertions, 69 deletions
diff --git a/examples/dummyresource/facade.cpp b/examples/dummyresource/facade.cpp index 9722335..611217f 100644 --- a/examples/dummyresource/facade.cpp +++ b/examples/dummyresource/facade.cpp | |||
@@ -24,6 +24,8 @@ | |||
24 | 24 | ||
25 | #include "common/resourceaccess.h" | 25 | #include "common/resourceaccess.h" |
26 | #include "common/commands.h" | 26 | #include "common/commands.h" |
27 | #include "common/resultset.h" | ||
28 | #include "common/domain/event.h" | ||
27 | #include "dummycalendar_generated.h" | 29 | #include "dummycalendar_generated.h" |
28 | #include "event_generated.h" | 30 | #include "event_generated.h" |
29 | #include "entity_generated.h" | 31 | #include "entity_generated.h" |
@@ -126,60 +128,16 @@ void DummyResourceFacade::readValue(const QSharedPointer<Akonadi2::Storage> &sto | |||
126 | }); | 128 | }); |
127 | } | 129 | } |
128 | 130 | ||
129 | /* | ||
130 | * An iterator to a result set. | ||
131 | * | ||
132 | * We'll eventually want to lazy load results in next(). | ||
133 | */ | ||
134 | class ResultSet { | ||
135 | public: | ||
136 | ResultSet(const QVector<QByteArray> &resultSet) | ||
137 | : mResultSet(resultSet), | ||
138 | mIt(nullptr) | ||
139 | { | ||
140 | |||
141 | } | ||
142 | |||
143 | bool next() | ||
144 | { | ||
145 | if (!mIt) { | ||
146 | mIt = mResultSet.constBegin(); | ||
147 | } else { | ||
148 | mIt++; | ||
149 | } | ||
150 | return mIt != mResultSet.constEnd(); | ||
151 | } | ||
152 | |||
153 | QByteArray id() | ||
154 | { | ||
155 | return *mIt; | ||
156 | } | ||
157 | |||
158 | private: | ||
159 | QVector<QByteArray> mResultSet; | ||
160 | QVector<QByteArray>::ConstIterator mIt; | ||
161 | }; | ||
162 | |||
163 | static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage) | 131 | static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage) |
164 | { | 132 | { |
165 | //Now that the sync is complete we can execute the query | 133 | auto resultSet = Akonadi2::ApplicationDomain::EventImplementation::queryIndexes(query, "org.kde.dummy"); |
166 | const auto preparedQuery = prepareQuery(query); | ||
167 | |||
168 | //Index lookups | ||
169 | //TODO query standard indexes | ||
170 | QVector<QByteArray> keys; | ||
171 | if (query.propertyFilter.contains("uid")) { | ||
172 | static Index uidIndex(Akonadi2::Store::storageLocation(), "org.kde.dummy.index.uid", Akonadi2::Storage::ReadOnly); | ||
173 | uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { | ||
174 | keys << value; | ||
175 | }, | ||
176 | [](const Index::Error &error) { | ||
177 | Warning() << "Error in index: " << error.message; | ||
178 | }); | ||
179 | } | ||
180 | 134 | ||
181 | //Scan for where we don't have an index | 135 | //Scan for where we don't have an index |
182 | if (keys.isEmpty()) { | 136 | //TODO: we may want a way for queryIndexes to indicate that the resultSet is not final, and that a scan over the remaining set is required |
137 | //TODO: the prepared query should be generalized in EventImplementation on top of domain adaptors | ||
138 | if (resultSet.isEmpty()) { | ||
139 | QVector<QByteArray> keys; | ||
140 | const auto preparedQuery = prepareQuery(query); | ||
183 | scan(storage, QByteArray(), [preparedQuery, &keys](const QByteArray &key, const Akonadi2::Entity &entity, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local, Akonadi2::Metadata const *metadataBuffer) { | 141 | scan(storage, QByteArray(), [preparedQuery, &keys](const QByteArray &key, const Akonadi2::Entity &entity, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local, Akonadi2::Metadata const *metadataBuffer) { |
184 | //TODO use adapter for query and scan? | 142 | //TODO use adapter for query and scan? |
185 | if (preparedQuery && preparedQuery(std::string(key.constData(), key.size()), buffer, local)) { | 143 | if (preparedQuery && preparedQuery(std::string(key.constData(), key.size()), buffer, local)) { |
@@ -187,9 +145,10 @@ static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer | |||
187 | } | 145 | } |
188 | return true; | 146 | return true; |
189 | }); | 147 | }); |
148 | return ResultSet(keys); | ||
190 | } | 149 | } |
191 | 150 | ||
192 | return ResultSet(keys); | 151 | return resultSet; |
193 | } | 152 | } |
194 | 153 | ||
195 | KAsync::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) | 154 | KAsync::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) |
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index e16a693..71a4ac5 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "clientapi.h" | 30 | #include "clientapi.h" |
31 | #include "index.h" | 31 | #include "index.h" |
32 | #include "log.h" | 32 | #include "log.h" |
33 | #include "domain/event.h" | ||
33 | #include <QUuid> | 34 | #include <QUuid> |
34 | #include <assert.h> | 35 | #include <assert.h> |
35 | 36 | ||
@@ -106,35 +107,26 @@ static QMap<QString, QString> s_dataSource = populate(); | |||
106 | 107 | ||
107 | //FIXME We need to pass the resource-instance name to generic resource, not the plugin name | 108 | //FIXME We need to pass the resource-instance name to generic resource, not the plugin name |
108 | DummyResource::DummyResource() | 109 | DummyResource::DummyResource() |
109 | : Akonadi2::GenericResource(PLUGIN_NAME) | 110 | : Akonadi2::GenericResource(PLUGIN_NAME ".instance1") |
110 | { | 111 | { |
111 | } | 112 | } |
112 | 113 | ||
113 | void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) | 114 | void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) |
114 | { | 115 | { |
115 | auto eventFactory = QSharedPointer<DummyEventAdaptorFactory>::create(); | 116 | //TODO In case of a non 1:1 mapping between resource and domain types special handling is required. |
116 | //FIXME we should setup for each resource entity type, not for each domain type | ||
117 | //i.e. If a resource stores tags as part of each message it needs to update the tag index | 117 | //i.e. If a resource stores tags as part of each message it needs to update the tag index |
118 | //TODO setup preprocessors for each resource entity type and pipeline type allowing full customization | ||
119 | //Eventually the order should be self configuring, for now it's hardcoded. | ||
120 | auto eventIndexer = new SimpleProcessor("summaryprocessor", [eventFactory](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { | ||
121 | auto adaptor = eventFactory->createAdaptor(entity); | ||
122 | // Log() << "Summary preprocessor: " << adaptor->getProperty("summary").toString(); | ||
123 | }); | ||
124 | 118 | ||
125 | auto uidIndexer = new SimpleProcessor("uidIndexer", [eventFactory](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { | 119 | auto eventFactory = QSharedPointer<DummyEventAdaptorFactory>::create(); |
126 | static Index uidIndex(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage", "org.kde.dummy.index.uid", Akonadi2::Storage::ReadWrite); | 120 | const auto resourceIdentifier = mResourceInstanceIdentifier; |
127 | 121 | auto eventIndexer = new SimpleProcessor("eventIndexer", [eventFactory, resourceIdentifier](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity) { | |
128 | //TODO: Benchmark if this is performance wise acceptable, or if we have to access the buffer directly | ||
129 | auto adaptor = eventFactory->createAdaptor(entity); | 122 | auto adaptor = eventFactory->createAdaptor(entity); |
130 | const auto uid = adaptor->getProperty("uid"); | 123 | //FIXME set revision? |
131 | if (uid.isValid()) { | 124 | Akonadi2::ApplicationDomain::Event event(resourceIdentifier, state.key(), -1, adaptor); |
132 | uidIndex.add(uid.toByteArray(), state.key()); | 125 | Akonadi2::ApplicationDomain::EventImplementation::index(event); |
133 | } | ||
134 | }); | 126 | }); |
135 | 127 | ||
136 | //event is the entitytype and not the domain type | 128 | //event is the entitytype and not the domain type |
137 | pipeline->setPreprocessors("event", Akonadi2::Pipeline::NewPipeline, QVector<Akonadi2::Preprocessor*>() << eventIndexer << uidIndexer); | 129 | pipeline->setPreprocessors("event", Akonadi2::Pipeline::NewPipeline, QVector<Akonadi2::Preprocessor*>() << eventIndexer); |
138 | GenericResource::configurePipeline(pipeline); | 130 | GenericResource::configurePipeline(pipeline); |
139 | } | 131 | } |
140 | 132 | ||