From 60b4be31c40e7c4681f5ce462af84dd92872ec5f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 25 Nov 2015 15:42:21 +0100 Subject: Separate the default index updater from other generic indexers --- examples/dummyresource/resourcefactory.cpp | 53 ++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'examples') diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 2a5a3e8..e524c3f 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -52,7 +52,6 @@ * * range indexes like what date range an event affects. * * group indexes like tree hierarchies as nested sets */ -template class IndexUpdater : public Akonadi2::Preprocessor { public: IndexUpdater(const QByteArray &index, const QByteArray &type) @@ -64,21 +63,17 @@ public: void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - Akonadi2::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); add(newEntity.getProperty("remoteId"), uid, transaction); } void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); - Akonadi2::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); remove(oldEntity.getProperty("remoteId"), uid, transaction); add(newEntity.getProperty("remoteId"), uid, transaction); } void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE { - Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); remove(oldEntity.getProperty("remoteId"), uid, transaction); } @@ -92,6 +87,7 @@ private: void remove(const QVariant &value, const QByteArray &uid, Akonadi2::Storage::Transaction &transaction) { + //TODO hide notfound error Index(mIndexIdentifier, transaction).remove(value.toByteArray(), uid); } @@ -99,26 +95,49 @@ private: QByteArray mBufferType; }; +template +class DefaultIndexUpdater : public Akonadi2::Preprocessor { +public: + void newEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + { + Akonadi2::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); + } + + void modifiedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, const Akonadi2::ApplicationDomain::BufferAdaptor &newEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + { + Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); + Akonadi2::ApplicationDomain::TypeImplementation::index(uid, newEntity, transaction); + } + + void deletedEntity(const QByteArray &uid, qint64 revision, const Akonadi2::ApplicationDomain::BufferAdaptor &oldEntity, Akonadi2::Storage::Transaction &transaction) Q_DECL_OVERRIDE + { + Akonadi2::ApplicationDomain::TypeImplementation::removeIndex(uid, oldEntity, transaction); + } +}; + DummyResource::DummyResource(const QByteArray &instanceIdentifier, const QSharedPointer &pipeline) : Akonadi2::GenericResource(instanceIdentifier, pipeline) { { - auto eventFactory = QSharedPointer::create(); - auto eventIndexer = new IndexUpdater("event.index.rid", ENTITY_TYPE_EVENT); - mPipeline->setPreprocessors(ENTITY_TYPE_EVENT, QVector() << eventIndexer); - mPipeline->setAdaptorFactory(ENTITY_TYPE_EVENT, eventFactory); + QVector eventPreprocessors; + eventPreprocessors << new DefaultIndexUpdater; + eventPreprocessors << new IndexUpdater("event.index.rid", ENTITY_TYPE_EVENT); + mPipeline->setPreprocessors(ENTITY_TYPE_EVENT, eventPreprocessors); + mPipeline->setAdaptorFactory(ENTITY_TYPE_EVENT, QSharedPointer::create()); } { - auto mailFactory = QSharedPointer::create(); - auto mailIndexer = new IndexUpdater("mail.index.rid", ENTITY_TYPE_MAIL); - mPipeline->setPreprocessors(ENTITY_TYPE_MAIL, QVector() << mailIndexer); - mPipeline->setAdaptorFactory(ENTITY_TYPE_MAIL, mailFactory); + QVector mailPreprocessors; + mailPreprocessors << new DefaultIndexUpdater; + mailPreprocessors << new IndexUpdater("mail.index.rid", ENTITY_TYPE_MAIL); + mPipeline->setPreprocessors(ENTITY_TYPE_MAIL, mailPreprocessors); + mPipeline->setAdaptorFactory(ENTITY_TYPE_MAIL, QSharedPointer::create()); } { - auto folderFactory = QSharedPointer::create(); - auto folderIndexer = new IndexUpdater("folder.index.rid", ENTITY_TYPE_FOLDER); - mPipeline->setPreprocessors(ENTITY_TYPE_FOLDER, QVector() << folderIndexer); - mPipeline->setAdaptorFactory(ENTITY_TYPE_FOLDER, folderFactory); + QVector folderPreprocessors; + folderPreprocessors << new DefaultIndexUpdater; + folderPreprocessors << new IndexUpdater("folder.index.rid", ENTITY_TYPE_FOLDER); + mPipeline->setPreprocessors(ENTITY_TYPE_FOLDER, folderPreprocessors); + mPipeline->setAdaptorFactory(ENTITY_TYPE_FOLDER, QSharedPointer::create()); } } -- cgit v1.2.3