comparison OrthancServer/SQLiteDatabaseWrapper.cpp @ 3019:8336204d95dc db-changes

refactoring computation of disk size for recycling
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Dec 2018 18:07:40 +0100
parents e3b5c07146a3
children d207f6ac1f86
comparison
equal deleted inserted replaced
3018:e3b5c07146a3 3019:8336204d95dc
34 #include "PrecompiledHeadersServer.h" 34 #include "PrecompiledHeadersServer.h"
35 #include "SQLiteDatabaseWrapper.h" 35 #include "SQLiteDatabaseWrapper.h"
36 36
37 #include "../Core/DicomFormat/DicomArray.h" 37 #include "../Core/DicomFormat/DicomArray.h"
38 #include "../Core/Logging.h" 38 #include "../Core/Logging.h"
39 #include "../Core/SQLite/Transaction.h"
39 #include "EmbeddedResources.h" 40 #include "EmbeddedResources.h"
40 #include "ServerToolbox.h" 41 #include "ServerToolbox.h"
41 42
42 #include <stdio.h> 43 #include <stdio.h>
43 #include <boost/lexical_cast.hpp> 44 #include <boost/lexical_cast.hpp>
371 } 372 }
372 373
373 // New in Orthanc 1.5.1 374 // New in Orthanc 1.5.1
374 if (version_ == 6) 375 if (version_ == 6)
375 { 376 {
376 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabaseTracksSizeOfAttachments) || 377 if (!LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast) ||
377 tmp != "1") 378 tmp != "1")
378 { 379 {
379 LOG(INFO) << "Installing the SQLite triggers to track the size of the attachments"; 380 LOG(INFO) << "Installing the SQLite triggers to track the size of the attachments";
380 std::string query; 381 std::string query;
381 EmbeddedResources::GetFileResource(query, EmbeddedResources::INSTALL_TRACK_ATTACHMENTS_SIZE); 382 EmbeddedResources::GetFileResource(query, EmbeddedResources::INSTALL_TRACK_ATTACHMENTS_SIZE);
540 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1"); 541 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1");
541 GetChangesInternal(target, done, s, 1); 542 GetChangesInternal(target, done, s, 1);
542 } 543 }
543 544
544 545
546 class SQLiteDatabaseWrapper::Transaction : public IDatabaseWrapper::ITransaction
547 {
548 private:
549 SQLiteDatabaseWrapper& that_;
550 std::auto_ptr<SQLite::Transaction> transaction_;
551 int64_t initialDiskSize_;
552
553 public:
554 Transaction(SQLiteDatabaseWrapper& that) :
555 that_(that),
556 transaction_(new SQLite::Transaction(that_.db_))
557 {
558 #if defined(NDEBUG)
559 // Release mode
560 initialDiskSize_ = 0;
561 #else
562 // Debug mode
563 initialDiskSize_ = static_cast<int64_t>(that_.GetTotalCompressedSize());
564 #endif
565 }
566
567 virtual void Begin()
568 {
569 transaction_->Begin();
570 }
571
572 virtual void Rollback()
573 {
574 transaction_->Rollback();
575 }
576
577 virtual void Commit(int64_t fileSizeDelta /* only used in debug */)
578 {
579 transaction_->Commit();
580
581 assert(initialDiskSize_ + fileSizeDelta >= 0 &&
582 initialDiskSize_ + fileSizeDelta == static_cast<int64_t>(that_.GetTotalCompressedSize()));
583 }
584 };
585
586
587 IDatabaseWrapper::ITransaction* SQLiteDatabaseWrapper::StartTransaction()
588 {
589 return new Transaction(*this);
590 }
591
592
545 void SQLiteDatabaseWrapper::GetAllMetadata(std::map<MetadataType, std::string>& target, 593 void SQLiteDatabaseWrapper::GetAllMetadata(std::map<MetadataType, std::string>& target,
546 int64_t id) 594 int64_t id)
547 { 595 {
548 target.clear(); 596 target.clear();
549 597