From 3601ee575f833bf204540f4fac41d87a0d977a79 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 25 May 2015 23:14:57 +0200 Subject: Centralized type specific code. --- common/domain/event.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ common/domain/event.h | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 common/domain/event.cpp create mode 100644 common/domain/event.h (limited to 'common/domain') diff --git a/common/domain/event.cpp b/common/domain/event.cpp new file mode 100644 index 0000000..86100b7 --- /dev/null +++ b/common/domain/event.cpp @@ -0,0 +1,53 @@ +/* + * 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 "../resultset.h" +#include "../index.h" +#include "../storage.h" +#include "../log.h" + +using namespace Akonadi2::ApplicationDomain; + +ResultSet EventImplementation::queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier) +{ + QVector keys; + if (query.propertyFilter.contains("uid")) { + Index uidIndex(Akonadi2::Store::storageLocation(), resourceInstanceIdentifier + "index.uid", Akonadi2::Storage::ReadOnly); + uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { + keys << value; + }, + [](const Index::Error &error) { + Warning() << "Error in index: " << error.message; + }); + } + return ResultSet(keys); +} + +void EventImplementation::index(const Event &type) +{ + Index uidIndex(Akonadi2::Store::storageLocation(), type.resourceInstanceIdentifier() + "index.uid", Akonadi2::Storage::ReadWrite); + const auto uid = type.getProperty("uid"); + if (uid.isValid()) { + uidIndex.add(uid.toByteArray(), type.identifier()); + } +} diff --git a/common/domain/event.h b/common/domain/event.h new file mode 100644 index 0000000..4cb0d34 --- /dev/null +++ b/common/domain/event.h @@ -0,0 +1,46 @@ +/* + * 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. + */ +#pragma once + +#include "../clientapi.h" + +class ResultSet; +class QByteArray; + +namespace Akonadi2 { + class Query; + +namespace ApplicationDomain { + +/** + * Implements all type-specific code such as updating and querying indexes. + */ +namespace EventImplementation { + typedef Event DomainType; + /** + * Returns the potential result set based on the indexes. + * + * An empty result set indicates that a full scan is required. + */ + ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier); + void index(const Event &type); +}; + +} +} -- cgit v1.2.3