File indexing completed on 2025-01-05 04:47:00
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org> * 0003 * * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later * 0005 ***************************************************************************/ 0006 0007 #pragma once 0008 0009 #include "../exception.h" 0010 #include "entities.h" 0011 0012 class QString; 0013 class QVariant; 0014 0015 namespace Akonadi 0016 { 0017 namespace Server 0018 { 0019 AKONADI_EXCEPTION_MAKE_INSTANCE(PartHelperException); 0020 0021 /** 0022 * Helper methods that store data in a file instead of the database. 0023 * 0024 * @author Andras Mantia <amantia@kde.org> 0025 * 0026 * @todo Use exceptions for error handling in all these methods. Requires that all callers 0027 * can handle that first though. 0028 */ 0029 namespace PartHelper 0030 { 0031 /** 0032 * Update payload of an existing part @p part to @p data and size @p dataSize. 0033 * Automatically decides whether or not the data should be stored in the database 0034 * or the file system. 0035 * @throw PartHelperException if file operations failed 0036 */ 0037 void update(Part *part, const QByteArray &data, qint64 dataSize); 0038 0039 /** 0040 * Adds a new part to the database and if necessary to the filesystem. 0041 * @p part must not be in the database yet (ie. valid() == false) and must have 0042 * a data size set. 0043 */ 0044 bool insert(Part *part, qint64 *insertId = nullptr); 0045 0046 /** Deletes @p part from the database and also removes existing filesystem data if needed. */ 0047 bool remove(Part *part); 0048 /** Deletes all parts which match the given constraint, including all corresponding filesystem data. */ 0049 bool remove(const QString &column, const QVariant &value); 0050 0051 /** Returns the payload data. */ 0052 QByteArray translateData(const QByteArray &data, Part::Storage storageType); 0053 /** Convenience overload of the above. */ 0054 QByteArray translateData(const Part &part); 0055 0056 /** Truncate the payload of @p part and update filesystem/database accordingly. 0057 * This is more efficient than using update since it does not require the data to be loaded. 0058 */ 0059 bool truncate(Part &part); 0060 0061 /** Verifies and if necessary fixes the external reference of this part. */ 0062 bool verify(Part &part); 0063 0064 } // namespace PartHelper 0065 0066 } // namespace Server 0067 } // namespace Akonadi