Akonadi

tagqueryhelper.cpp
1 /*
2  Copyright (c) 2009 Volker Krause <[email protected]>
3  Copyright (c) 2015 Daniel Vrátil <[email protected]>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "tagqueryhelper.h"
22 
23 #include "commandcontext.h"
24 #include "storage/querybuilder.h"
25 #include "handler.h"
26 #include "storage/queryhelper.h"
27 
28 #include <private/scope_p.h>
29 #include <private/imapset_p.h>
30 
31 using namespace Akonadi;
32 using namespace Akonadi::Server;
33 
34 void TagQueryHelper::remoteIdToQuery(const QStringList &rids, const CommandContext &context, QueryBuilder &qb)
35 {
37  Tag::idFullColumnName(), TagRemoteIdResourceRelation::tagIdFullColumnName());
38  qb.addValueCondition(TagRemoteIdResourceRelation::resourceIdFullColumnName(), Query::Equals, context.resource().id());
39 
40  if (rids.size() == 1) {
41  qb.addValueCondition(TagRemoteIdResourceRelation::remoteIdFullColumnName(), Query::Equals, rids.first());
42  } else {
43  qb.addValueCondition(TagRemoteIdResourceRelation::remoteIdFullColumnName(), Query::In, rids);
44  }
45 }
46 
47 void TagQueryHelper::gidToQuery(const QStringList &gids, const CommandContext &context, QueryBuilder &qb)
48 {
49  if (context.resource().isValid()) {
51  Tag::idFullColumnName(), TagRemoteIdResourceRelation::tagIdFullColumnName());
52  qb.addValueCondition(TagRemoteIdResourceRelation::resourceIdFullColumnName(), Query::Equals, context.resource().id());
53  }
54 
55  if (gids.size() == 1) {
56  qb.addValueCondition(Tag::gidFullColumnName(), Query::Equals, gids.first());
57  } else {
58  qb.addValueCondition(Tag::gidFullColumnName(), Query::In, gids);
59  }
60 }
61 
62 void TagQueryHelper::scopeToQuery(const Scope &scope, const CommandContext &context, QueryBuilder &qb)
63 {
64  if (scope.scope() == Scope::Uid) {
65  QueryHelper::setToQuery(scope.uidSet(), Tag::idFullColumnName(), qb);
66  return;
67  }
68 
69  if (scope.scope() == Scope::Gid) {
70  TagQueryHelper::gidToQuery(scope.gidSet(), context, qb);
71  return;
72  }
73 
74  if (scope.scope() == Scope::Rid) {
75  if (!context.resource().isValid()) {
76  throw HandlerException("Operations based on remote identifiers require a resource or collection context");
77  }
78 
79  if (scope.scope() == Scope::Rid) {
80  TagQueryHelper::remoteIdToQuery(scope.ridSet(), context, qb);
81  }
82  }
83 
84  throw HandlerException("HRID tag operations are not permitted");
85 }
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.
NOTE: only supported for UPDATE and SELECT queries.
Definition: querybuilder.h:62
void addJoin(JoinType joinType, const QString &table, const Query::Condition &condition)
Join a table to the query.
int size() const const
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.
T & first()
void setToQuery(const ImapSet &set, const QString &column, QueryBuilder &qb)
Add conditions to qb for the given uid set set applied to column.
Definition: queryhelper.cpp:29
Helper integration between Akonadi and Qt.
static QString tableName()
Returns the name of the SQL table.
Definition: entities.cpp:9623
Helper class to construct arbitrary SQL queries.
Definition: querybuilder.h:45
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 30 2020 22:46:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.