Akonadi

tagqueryhelper.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
3 SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "tagqueryhelper.h"
9
10#include "commandcontext.h"
11#include "handler.h"
12#include "storage/querybuilder.h"
13
14#include "private/scope_p.h"
15
16using namespace Akonadi;
17using namespace Akonadi::Server;
18
19void TagQueryHelper::remoteIdToQuery(const QStringList &rids, const CommandContext &context, QueryBuilder &qb)
20{
21 qb.addJoin(QueryBuilder::InnerJoin, TagRemoteIdResourceRelation::tableName(), Tag::idFullColumnName(), TagRemoteIdResourceRelation::tagIdFullColumnName());
22 qb.addValueCondition(TagRemoteIdResourceRelation::resourceIdFullColumnName(), Query::Equals, context.resource().id());
23
24 if (rids.size() == 1) {
25 qb.addValueCondition(TagRemoteIdResourceRelation::remoteIdFullColumnName(), Query::Equals, rids.first());
26 } else {
27 qb.addValueCondition(TagRemoteIdResourceRelation::remoteIdFullColumnName(), Query::In, rids);
28 }
29}
30
31void TagQueryHelper::gidToQuery(const QStringList &gids, const CommandContext &context, QueryBuilder &qb)
32{
33 if (context.resource().isValid()) {
35 TagRemoteIdResourceRelation::tableName(),
36 Tag::idFullColumnName(),
37 TagRemoteIdResourceRelation::tagIdFullColumnName());
38 qb.addValueCondition(TagRemoteIdResourceRelation::resourceIdFullColumnName(), Query::Equals, context.resource().id());
39 }
40
41 if (gids.size() == 1) {
42 qb.addValueCondition(Tag::gidFullColumnName(), Query::Equals, gids.first());
43 } else {
44 qb.addValueCondition(Tag::gidFullColumnName(), Query::In, gids);
45 }
46}
47
48void TagQueryHelper::scopeToQuery(const Scope &scope, const CommandContext &context, QueryBuilder &qb)
49{
50 if (scope.scope() == Scope::Invalid) {
51 return;
52 }
53
54 if (scope.scope() == Scope::Uid) {
55 if (!scope.isEmpty()) {
56 qb.addValueCondition(Tag::idFullColumnName(), Query::In, scope.uidSet());
57 }
58 return;
59 }
60
61 if (scope.scope() == Scope::Gid) {
62 TagQueryHelper::gidToQuery(scope.gidSet(), context, qb);
63 return;
64 }
65
66 if (scope.scope() == Scope::Rid) {
67 if (!context.resource().isValid()) {
68 throw HandlerException("Operations based on remote identifiers require a resource or collection context");
69 }
70
71 if (scope.scope() == Scope::Rid) {
72 TagQueryHelper::remoteIdToQuery(scope.ridSet(), context, qb);
73 }
74 }
75
76 throw HandlerException("HRID tag operations are not permitted");
77}
Helper class to construct arbitrary SQL queries.
void addValueCondition(const QString &column, Query::CompareOperator op, const QVariant &value, ConditionType type=WhereCondition)
Add a WHERE or HAVING condition which compares a column with a given value.
void addJoin(JoinType joinType, const QString &table, const Query::Condition &condition)
Join a table to the query.
@ InnerJoin
NOTE: only supported for UPDATE and SELECT queries.
void remoteIdToQuery(const QStringList &rids, const CommandContext &context, QueryBuilder &qb)
Add conditions to qb for the given remote identifier rid.
void scopeToQuery(const Scope &scope, const CommandContext &context, QueryBuilder &qb)
Add conditions to qb for the given item operation scope scope.
Helper integration between Akonadi and Qt.
T & first()
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.