Mercurial > dedupe
changeset 92:f49023c61dac
Support for bulk insertion.
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Mon, 21 Oct 2013 20:03:39 +0200 |
| parents | a5788991ca9f |
| children | 308a718812ba |
| files | FileDBLink.cpp FileDBLink.hpp MemoryDBLink.cpp MemoryDBLink.hpp SqliteDBLink.cpp SqliteDBLink.hpp |
| diffstat | 6 files changed, 37 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/FileDBLink.cpp Mon Oct 21 16:21:54 2013 +0200 +++ b/FileDBLink.cpp Mon Oct 21 20:03:39 2013 +0200 @@ -8,6 +8,11 @@ #include <boost/bind.hpp> +FileDBLink::~FileDBLink() +{ + commit(); +} + void FileDBLink::updateIfModified(const QString& path, bool lazy) { QFileInfo fileinfo(path); @@ -30,10 +35,9 @@ const QDateTime& lastModified, bool lazy) { QByteArray hash; - //if (!lazy || updateAllWithSize(size)) if (!lazy) hash = computeHash(path); - addFile(path, size, lastModified, hash); + addFile(path, size, lastModified, hash, lazy); } void FileDBLink::addFile(const QFileInfo& fileinfo, bool lazy) @@ -91,7 +95,6 @@ const QDateTime& lastModified, bool lazy) { QByteArray hash; - //if (!lazy || updateAllWithSize(size)) if (!lazy) hash = computeHash(path); updateFile(path, size, lastModified, hash); @@ -221,3 +224,8 @@ } return dbinf_ptr_t(); } + +bool FileDBLink::commit() +{ + return true; +}
--- a/FileDBLink.hpp Mon Oct 21 16:21:54 2013 +0200 +++ b/FileDBLink.hpp Mon Oct 21 20:03:39 2013 +0200 @@ -111,12 +111,13 @@ public: enum DBStatus { NONE = 0, MTIME_DIFFERENT, SAME}; - virtual ~FileDBLink() {} + virtual ~FileDBLink(); void updateIfModified(const QString& path, bool lazy = false); virtual void addFile(const QString& path, quint64 size, - const QDateTime& dtime, const QByteArray& hash) = 0; + const QDateTime& dtime, const QByteArray& hash, + bool lazy) = 0; virtual void keepOnlyFromPrefix(const QString& prefix, const QStringList& files) = 0; virtual void deleteFileFromDB(const QString& path) = 0; @@ -131,7 +132,8 @@ void addFile(const QFileInfo& fileinfo, bool lazy = false); virtual void updateFile(const QString& path, quint64 size, - const QDateTime& dtime, const QByteArray& hash) = 0; + const QDateTime& dtime, const QByteArray& hash, + bool lazy = false) = 0; void updateFile(const QString& path, quint64 size, const QDateTime& dtime, bool lazy = false); void updateFile(const QFileInfo& fileinfo, bool lazy = false); @@ -139,6 +141,7 @@ virtual DBStatus existsWithMtime(const QString& path, const QDateTime& mtime) = 0; + virtual bool commit(); virtual const QList<dbinf_ptr_t> values(const QString& prefix = QString() ) const = 0;
--- a/MemoryDBLink.cpp Mon Oct 21 16:21:54 2013 +0200 +++ b/MemoryDBLink.cpp Mon Oct 21 20:03:39 2013 +0200 @@ -3,7 +3,7 @@ #include <QtCore/QStringList> void MemoryDBLink::addFile(const QString& path, quint64 size, - const QDateTime& dtime, const QByteArray& hash) + const QDateTime& dtime, const QByteArray& hash, bool) { addFile(DBInfo(path, size, dtime, hash)); } @@ -85,7 +85,8 @@ } void MemoryDBLink::updateFile(const QString& path, quint64 size, - const QDateTime& dtime, const QByteArray& hash) + const QDateTime& dtime, const QByteArray& hash, + bool) { updateFile(DBInfo(path, size, dtime, hash)); }
--- a/MemoryDBLink.hpp Mon Oct 21 16:21:54 2013 +0200 +++ b/MemoryDBLink.hpp Mon Oct 21 20:03:39 2013 +0200 @@ -15,9 +15,11 @@ QStringList toStringList(); virtual void addFile(const QString& path, quint64 size, - const QDateTime& dtime, const QByteArray& hash); + const QDateTime& dtime, const QByteArray& hash, + bool lazy = false); virtual void updateFile(const QString& path, quint64 size, - const QDateTime& dtime, const QByteArray& hash); + const QDateTime& dtime, const QByteArray& hash, + bool lazy = false); DBStatus existsWithMtime(const QString& path, const QDateTime& mtime); const QList<dbinf_ptr_t > values(const QString& prefix = QString() ) const;
--- a/SqliteDBLink.cpp Mon Oct 21 16:21:54 2013 +0200 +++ b/SqliteDBLink.cpp Mon Oct 21 20:03:39 2013 +0200 @@ -85,9 +85,10 @@ } void SqliteDBLink::addFile(const QString& path, quint64 size, - const QDateTime& dtime, const QByteArray& hash) + const QDateTime& dtime, const QByteArray& hash, + bool lazy) { - addFile(DBInfo(path, size, dtime, hash)); + addFile(DBInfo(path, size, dtime, hash), lazy); } bool SqliteDBLink::tryAddFile(const DBInfo& dbinfo) @@ -106,12 +107,12 @@ void SqliteDBLink::updateFile(const QString& path, quint64 size, const QDateTime& dtime, - const QByteArray& hash) + const QByteArray& hash, bool lazy) { - updateFile(DBInfo(path, size, dtime, hash)); + updateFile(DBInfo(path, size, dtime, hash), lazy); } -void SqliteDBLink::updateFile(const DBInfo& dbinfo) +void SqliteDBLink::updateFile(const DBInfo& dbinfo, bool lazy) { QSqlQuery query(db); query.prepare("UPDATE files " @@ -126,7 +127,7 @@ } } -void SqliteDBLink::addFile(const DBInfo& dbinfo) +void SqliteDBLink::addFile(const DBInfo& dbinfo, bool lazy) { if (!tryAddFile(dbinfo)) { abort(); //Should throw exception
--- a/SqliteDBLink.hpp Mon Oct 21 16:21:54 2013 +0200 +++ b/SqliteDBLink.hpp Mon Oct 21 20:03:39 2013 +0200 @@ -10,9 +10,11 @@ ~SqliteDBLink(); virtual void addFile(const QString& path, quint64 size, - const QDateTime& dtime, const QByteArray& hash); + const QDateTime& dtime, const QByteArray& hash, + bool lazy = false); virtual void updateFile(const QString& path, quint64 size, - const QDateTime& dtime, const QByteArray& hash); + const QDateTime& dtime, const QByteArray& hash, + bool lazy = false); bool exists(const QString& path); DBStatus existsWithMtime(const QString& path, const QDateTime& mtime); @@ -26,9 +28,9 @@ virtual void deleteFileFromDB(const QString& path); private: - void addFile(const DBInfo& info); + void addFile(const DBInfo& info, bool lazy); bool tryAddFile(const DBInfo& info); - void updateFile(const DBInfo& dbinfo); + void updateFile(const DBInfo& dbinfo, bool lazy); QSqlDatabase db; static const QString connectionName;
