From 778b01181604dc2eae2013f2dc37db6d647b526a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 8 May 2017 14:27:25 +0200 Subject: Gather required databases from index definitions. --- common/domain/typeimplementations.cpp | 78 +++++++++++++---- common/domain/typeimplementations.h | 5 ++ common/domain/typeimplementations_p.h | 154 ++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 18 deletions(-) create mode 100644 common/domain/typeimplementations_p.h (limited to 'common/domain') diff --git a/common/domain/typeimplementations.cpp b/common/domain/typeimplementations.cpp index a87e73d..4e61bad 100644 --- a/common/domain/typeimplementations.cpp +++ b/common/domain/typeimplementations.cpp @@ -28,6 +28,7 @@ #include "entity_generated.h" #include "mail/threadindexer.h" #include "domainadaptor.h" +#include "typeimplementations_p.h" using namespace Sink; using namespace Sink::ApplicationDomain; @@ -35,22 +36,43 @@ using namespace Sink::ApplicationDomain; #define SINK_REGISTER_SERIALIZER(MAPPER, ENTITYTYPE, PROPERTY, LOWERCASEPROPERTY) \ MAPPER.addMapping(&Sink::ApplicationDomain::Buffer::ENTITYTYPE::LOWERCASEPROPERTY, &Sink::ApplicationDomain::Buffer::ENTITYTYPE##Builder::add_##LOWERCASEPROPERTY); +typedef IndexConfig, + ValueIndex, + ValueIndex, + ValueIndex, + SortedIndex, + SecondaryIndex, + SecondaryIndex, + CustomSecondaryIndex + > MailIndexConfig; + +typedef IndexConfig, + ValueIndex + > FolderIndexConfig; + +typedef IndexConfig + > ContactIndexConfig; + +typedef IndexConfig + > AddressbookIndexConfig; + +typedef IndexConfig + > EventIndexConfig; + void TypeImplementation::configure(TypeIndex &index) { - // index.addProperty(); - /* index.addProperty(Mail::SenderName::name); */ - /* index->addProperty(Mail::Subject::name); */ - /* index->addFulltextProperty(Mail::Subject::name); */ - index.addProperty(); - index.addProperty(); - index.addPropertyWithSorting(); - index.addProperty(); - index.addProperty(); + MailIndexConfig::configure(index); +} - index.addSecondaryPropertyIndexer(); - index.addSecondaryProperty(); - index.addSecondaryProperty(); +QMap TypeImplementation::typeDatabases() +{ + return merge(QMap{{QByteArray{Mail::name} + ".main", 0}}, MailIndexConfig::databases()); } void TypeImplementation::configure(IndexPropertyMapper &indexPropertyMapper) @@ -85,10 +107,15 @@ void TypeImplementation::configure(PropertyMapper &propertyMapper) SINK_REGISTER_SERIALIZER(propertyMapper, Mail, ParentMessageId, parentMessageId); } + void TypeImplementation::configure(TypeIndex &index) { - index.addProperty(Folder::Parent::name); - index.addProperty(Folder::Name::name); + FolderIndexConfig::configure(index); +} + +QMap TypeImplementation::typeDatabases() +{ + return merge(QMap{{QByteArray{Folder::name} + ".main", 0}}, FolderIndexConfig::databases()); } void TypeImplementation::configure(PropertyMapper &propertyMapper) @@ -108,7 +135,12 @@ void TypeImplementation::configure(IndexPropertyMapper &) void TypeImplementation::configure(TypeIndex &index) { - index.addProperty(Contact::Uid::name); + ContactIndexConfig::configure(index); +} + +QMap TypeImplementation::typeDatabases() +{ + return merge(QMap{{QByteArray{Contact::name} + ".main", 0}}, ContactIndexConfig::databases()); } void TypeImplementation::configure(PropertyMapper &propertyMapper) @@ -130,8 +162,12 @@ void TypeImplementation::configure(IndexPropertyMapper &) void TypeImplementation::configure(TypeIndex &index) { - index.addProperty(Addressbook::Parent::name); - index.addProperty(Addressbook::Name::name); + AddressbookIndexConfig::configure(index); +} + +QMap TypeImplementation::typeDatabases() +{ + return merge(QMap{{QByteArray{Addressbook::name} + ".main", 0}}, AddressbookIndexConfig::databases()); } void TypeImplementation::configure(PropertyMapper &propertyMapper) @@ -148,7 +184,12 @@ void TypeImplementation::configure(IndexPropertyMapper &) void TypeImplementation::configure(TypeIndex &index) { - index.addProperty(Event::Uid::name); + EventIndexConfig::configure(index); +} + +QMap TypeImplementation::typeDatabases() +{ + return merge(QMap{{QByteArray{Event::name} + ".main", 0}}, EventIndexConfig::databases()); } void TypeImplementation::configure(PropertyMapper &propertyMapper) @@ -163,3 +204,4 @@ void TypeImplementation::configure(IndexPropertyMapper &) { } + diff --git a/common/domain/typeimplementations.h b/common/domain/typeimplementations.h index 7e4608c..d36dfc1 100644 --- a/common/domain/typeimplementations.h +++ b/common/domain/typeimplementations.h @@ -47,6 +47,7 @@ public: static void configure(TypeIndex &index); static void configure(PropertyMapper &propertyMapper); static void configure(IndexPropertyMapper &indexPropertyMapper); + static QMap typeDatabases(); }; template<> @@ -57,6 +58,7 @@ public: static void configure(TypeIndex &); static void configure(PropertyMapper &); static void configure(IndexPropertyMapper &indexPropertyMapper); + static QMap typeDatabases(); }; template<> @@ -67,6 +69,7 @@ public: static void configure(TypeIndex &); static void configure(PropertyMapper &); static void configure(IndexPropertyMapper &indexPropertyMapper); + static QMap typeDatabases(); }; template<> @@ -77,6 +80,7 @@ public: static void configure(TypeIndex &); static void configure(PropertyMapper &); static void configure(IndexPropertyMapper &indexPropertyMapper); + static QMap typeDatabases(); }; template<> @@ -87,6 +91,7 @@ public: static void configure(TypeIndex &); static void configure(PropertyMapper &); static void configure(IndexPropertyMapper &indexPropertyMapper); + static QMap typeDatabases(); }; } diff --git a/common/domain/typeimplementations_p.h b/common/domain/typeimplementations_p.h new file mode 100644 index 0000000..b7a78ac --- /dev/null +++ b/common/domain/typeimplementations_p.h @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2015 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "typeindex.h" +#include + +template +void mergeImpl(T &map, First f) +{ + for (auto it = f.constBegin(); it != f.constEnd(); it++) { + map.insert(it.key(), it.value()); + } +} + +template +void mergeImpl(T &map, First f, Tail ...maps) +{ + for (auto it = f.constBegin(); it != f.constEnd(); it++) { + map.insert(it.key(), it.value()); + } + mergeImpl(map, maps...); +} + +template +First merge(First f, Tail ...maps) +{ + First map; + mergeImpl(f, maps...); + return map; +} + +template +class ValueIndex +{ +public: + static void configure(TypeIndex &index) + { + index.addProperty(); + } + + template + static QMap databases() + { + return {{QByteArray{EntityType::name} +".index." + Property::name, 1}}; + } +}; + + +template +class SortedIndex +{ +public: + static void configure(TypeIndex &index) + { + index.addPropertyWithSorting(); + } + + template + static QMap databases() + { + return {{QByteArray{EntityType::name} +".index." + Property::name + ".sort." + SortProperty::name, 1}}; + } +}; + +template +class SecondaryIndex +{ +public: + static void configure(TypeIndex &index) + { + index.addSecondaryProperty(); + } + + template + static QMap databases() + { + return {{QByteArray{EntityType::name} +".index." + Property::name + SecondaryProperty::name, 1}}; + } +}; + +template +class CustomSecondaryIndex +{ +public: + static void configure(TypeIndex &index) + { + index.addSecondaryPropertyIndexer(); + } + + template + static QMap databases() + { + return Indexer::databases(); + } +}; + +template +class IndexConfig +{ + template + static void applyIndex(TypeIndex &index) + { + T::configure(index); + } + + ///Apply recursively for parameter pack + template + static void applyIndex(TypeIndex &index) + { + applyIndex(index); + applyIndex(index); + } + + template + static QMap getDbs() + { + return T::template databases(); + } + + template + static QMap getDbs() + { + return merge(getDbs(), getDbs()); + } + +public: + static void configure(TypeIndex &index) + { + applyIndex(index); + } + + static QMap databases() + { + return getDbs(); + } + +}; + -- cgit v1.2.3