/* * Copyright (C) 2014 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 "event.h" #include #include #include #include "../resultset.h" #include "../index.h" #include "../storage.h" #include "../log.h" #include "../propertymapper.h" #include "../query.h" #include "../definitions.h" #include "event_generated.h" using namespace Akonadi2::ApplicationDomain; ResultSet TypeImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet &appliedFilters, Akonadi2::Storage::Transaction &transaction) { QVector keys; if (query.propertyFilter.contains("uid")) { Index uidIndex("event.index.uid", transaction); uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { keys << value; }, [](const Index::Error &error) { Warning() << "Error in uid index: " << error.message; }); appliedFilters << "uid"; } return ResultSet(keys); } void TypeImplementation::index(const Event &type, Akonadi2::Storage::Transaction &transaction) { const auto uid = type.getProperty("uid"); if (uid.isValid()) { Index("event.index.uid", transaction).add(uid.toByteArray(), type.identifier()); } } QSharedPointer::Buffer> > TypeImplementation::initializeReadPropertyMapper() { auto propertyMapper = QSharedPointer >::create(); propertyMapper->addMapping("summary", &Buffer::summary); propertyMapper->addMapping("uid", &Buffer::uid); return propertyMapper; } QSharedPointer::BufferBuilder> > TypeImplementation::initializeWritePropertyMapper() { auto propertyMapper = QSharedPointer >::create(); propertyMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { auto offset = variantToProperty(value, fbb); return [offset](BufferBuilder &builder) { builder.add_summary(offset); }; }); propertyMapper->addMapping("uid", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { auto offset = variantToProperty(value, fbb); return [offset](BufferBuilder &builder) { builder.add_uid(offset); }; }); return propertyMapper; }