Akonadi

parthelper.h
1 /***************************************************************************
2  * SPDX-FileCopyrightText: 2009 Andras Mantia <[email protected]> *
3  * *
4  * SPDX-License-Identifier: LGPL-2.0-or-later *
5  ***************************************************************************/
6 
7 #pragma once
8 
9 #include "../exception.h"
10 #include "entities.h"
11 
12 class QString;
13 class QVariant;
14 
15 namespace Akonadi
16 {
17 namespace Server
18 {
19 AKONADI_EXCEPTION_MAKE_INSTANCE(PartHelperException);
20 
21 /**
22  * Helper methods that store data in a file instead of the database.
23  *
24  * @author Andras Mantia <[email protected]>
25  *
26  * @todo Use exceptions for error handling in all these methods. Requires that all callers
27  * can handle that first though.
28  */
29 namespace PartHelper
30 {
31 /**
32  * Update payload of an existing part @p part to @p data and size @p dataSize.
33  * Automatically decides whether or not the data should be stored in the database
34  * or the file system.
35  * @throw PartHelperException if file operations failed
36  */
37 void update(Part *part, const QByteArray &data, qint64 dataSize);
38 
39 /**
40  * Adds a new part to the database and if necessary to the filesystem.
41  * @p part must not be in the database yet (ie. valid() == false) and must have
42  * a data size set.
43  */
44 bool insert(Part *part, qint64 *insertId = nullptr);
45 
46 /** Deletes @p part from the database and also removes existing filesystem data if needed. */
47 bool remove(Part *part);
48 /** Deletes all parts which match the given constraint, including all corresponding filesystem data. */
49 bool remove(const QString &column, const QVariant &value);
50 
51 /** Returns the payload data. */
52 QByteArray translateData(const QByteArray &data, Part::Storage storageType);
53 /** Convenience overload of the above. */
54 QByteArray translateData(const Part &part);
55 
56 /** Truncate the payload of @p part and update filesystem/database accordingly.
57  * This is more efficient than using update since it does not require the data to be loaded.
58  */
59 bool truncate(Part &part);
60 
61 /** Verifies and if necessary fixes the external reference of this part. */
62 bool verify(Part &part);
63 
64 } // namespace PartHelper
65 
66 } // namespace Server
67 } // namespace Akonadi
68 
bool insert(Part *part, qint64 *insertId=nullptr)
Adds a new part to the database and if necessary to the filesystem.
Definition: parthelper.cpp:58
bool truncate(Part &part)
Truncate the payload of part and update filesystem/database accordingly.
Definition: parthelper.cpp:152
QByteArray translateData(const QByteArray &data, Part::Storage storageType)
Returns the payload data.
Definition: parthelper.cpp:122
bool remove(Part *part)
Deletes part from the database and also removes existing filesystem data if needed.
Definition: parthelper.cpp:90
void update(Part *part, const QByteArray &data, qint64 dataSize)
Update payload of an existing part part to data and size dataSize.
Definition: parthelper.cpp:22
bool verify(Part &part)
Verifies and if necessary fixes the external reference of this part.
Definition: parthelper.cpp:164
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:48 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.