2013-10-03 17:27:29 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SYNCJOURNALDB_H
|
|
|
|
#define SYNCJOURNALDB_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2013-10-04 23:02:23 +04:00
|
|
|
#include <qmutex.h>
|
2013-10-16 13:59:54 +04:00
|
|
|
#include <QDateTime>
|
2013-10-03 17:27:29 +04:00
|
|
|
#include <QSqlDatabase>
|
2013-11-11 14:11:45 +04:00
|
|
|
#include <QHash>
|
2013-11-13 14:16:00 +04:00
|
|
|
#include <QSqlQuery>
|
2013-10-03 17:27:29 +04:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
class SyncJournalFileRecord;
|
2013-11-20 16:44:01 +04:00
|
|
|
class SyncJournalBlacklistRecord;
|
2013-10-03 17:27:29 +04:00
|
|
|
|
|
|
|
class SyncJournalDb : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit SyncJournalDb(const QString& path, QObject *parent = 0);
|
2013-11-18 12:59:59 +04:00
|
|
|
virtual ~SyncJournalDb();
|
2013-10-03 17:27:29 +04:00
|
|
|
SyncJournalFileRecord getFileRecord( const QString& filename );
|
2013-10-03 19:48:04 +04:00
|
|
|
bool setFileRecord( const SyncJournalFileRecord& record );
|
2013-10-28 13:47:10 +04:00
|
|
|
bool deleteFileRecord( const QString& filename, bool recursively = false );
|
2013-10-04 16:44:57 +04:00
|
|
|
int getFileRecordCount();
|
|
|
|
bool exists();
|
2013-12-03 17:47:32 +04:00
|
|
|
|
2013-11-20 16:44:01 +04:00
|
|
|
void updateBlacklistEntry( const SyncJournalBlacklistRecord& item );
|
|
|
|
void wipeBlacklistEntry(const QString& file);
|
2013-12-03 17:03:45 +04:00
|
|
|
int wipeBlacklist();
|
2013-12-03 17:47:32 +04:00
|
|
|
int blackListEntryCount();
|
2013-10-03 20:52:02 +04:00
|
|
|
|
2013-10-16 13:59:54 +04:00
|
|
|
struct DownloadInfo {
|
|
|
|
DownloadInfo() : _errorCount(0), _valid(false) {}
|
|
|
|
QString _tmpfile;
|
|
|
|
QByteArray _etag;
|
|
|
|
int _errorCount;
|
|
|
|
bool _valid;
|
|
|
|
};
|
|
|
|
struct UploadInfo {
|
|
|
|
UploadInfo() : _chunk(0), _transferid(0), _errorCount(0), _valid(false) {}
|
|
|
|
int _chunk;
|
|
|
|
int _transferid;
|
|
|
|
quint64 _size; //currently unused
|
|
|
|
QDateTime _modtime;
|
|
|
|
int _errorCount;
|
|
|
|
bool _valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
DownloadInfo getDownloadInfo(const QString &file);
|
|
|
|
void setDownloadInfo(const QString &file, const DownloadInfo &i);
|
|
|
|
UploadInfo getUploadInfo(const QString &file);
|
|
|
|
void setUploadInfo(const QString &file, const UploadInfo &i);
|
2013-11-20 16:44:01 +04:00
|
|
|
SyncJournalBlacklistRecord blacklistEntry( const QString& );
|
|
|
|
|
2013-11-11 14:11:45 +04:00
|
|
|
bool postSyncCleanup( const QHash<QString, QString>& items );
|
2013-10-16 13:59:54 +04:00
|
|
|
|
2013-11-18 12:59:59 +04:00
|
|
|
/* Because sqlite transactions is really slow, we encapsulate everything in big transactions
|
|
|
|
* Commit will actually commit the transaction and create a new one.
|
|
|
|
*/
|
2013-11-21 14:13:58 +04:00
|
|
|
void commit(const QString &context, bool startTrans = true);
|
2013-11-18 12:59:59 +04:00
|
|
|
|
2013-11-18 12:58:02 +04:00
|
|
|
void close();
|
2013-11-21 14:13:58 +04:00
|
|
|
|
|
|
|
|
2013-10-03 17:27:29 +04:00
|
|
|
signals:
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
private:
|
2013-10-04 23:02:23 +04:00
|
|
|
qint64 getPHash(const QString& ) const;
|
2013-10-25 15:30:45 +04:00
|
|
|
bool updateDatabaseStructure();
|
2013-11-21 14:13:58 +04:00
|
|
|
bool sqlFail(const QString& log, const QSqlQuery &query );
|
2013-11-25 18:11:37 +04:00
|
|
|
void commitInternal(const QString &context, bool startTrans = true);
|
|
|
|
void startTransaction();
|
|
|
|
void commitTransaction();
|
|
|
|
QStringList tableColumns( const QString& table );
|
2013-10-25 15:30:45 +04:00
|
|
|
|
2013-10-04 23:02:23 +04:00
|
|
|
bool checkConnect();
|
2013-10-03 17:27:29 +04:00
|
|
|
QSqlDatabase _db;
|
|
|
|
QString _dbFile;
|
2013-10-04 23:02:23 +04:00
|
|
|
QMutex _mutex; // Public functions are protected with the mutex.
|
2013-11-21 14:13:58 +04:00
|
|
|
int _transaction;
|
2013-11-13 14:16:00 +04:00
|
|
|
QScopedPointer<QSqlQuery> _getFileRecordQuery;
|
|
|
|
QScopedPointer<QSqlQuery> _setFileRecordQuery;
|
|
|
|
QScopedPointer<QSqlQuery> _getDownloadInfoQuery;
|
|
|
|
QScopedPointer<QSqlQuery> _setDownloadInfoQuery;
|
|
|
|
QScopedPointer<QSqlQuery> _deleteDownloadInfoQuery;
|
|
|
|
QScopedPointer<QSqlQuery> _getUploadInfoQuery;
|
|
|
|
QScopedPointer<QSqlQuery> _setUploadInfoQuery;
|
|
|
|
QScopedPointer<QSqlQuery> _deleteUploadInfoQuery;
|
2013-11-18 16:02:09 +04:00
|
|
|
QScopedPointer<QSqlQuery> _deleteFileRecordPhash;
|
|
|
|
QScopedPointer<QSqlQuery> _deleteFileRecordRecursively;
|
2013-11-20 16:44:01 +04:00
|
|
|
QScopedPointer<QSqlQuery> _blacklistQuery;
|
2013-10-03 17:27:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Mirall
|
|
|
|
#endif // SYNCJOURNALDB_H
|