comparison OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp @ 4556:2a0f8031fb93 db-changes

removed abstraction IDatabaseWrapper::ITransaction::Begin(), must be done by IDatabaseWrapper::StartTransaction()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Mar 2021 17:31:30 +0100
parents 5b929e6b3c36
children 648defffc8cc
comparison
equal deleted inserted replaced
4555:456ed3fcff81 4556:2a0f8031fb93
58 SignalFileDeleted(IDatabaseListener& listener) : 58 SignalFileDeleted(IDatabaseListener& listener) :
59 listener_(listener) 59 listener_(listener)
60 { 60 {
61 } 61 }
62 62
63 virtual const char* GetName() const 63 virtual const char* GetName() const ORTHANC_OVERRIDE
64 { 64 {
65 return "SignalFileDeleted"; 65 return "SignalFileDeleted";
66 } 66 }
67 67
68 virtual unsigned int GetCardinality() const 68 virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE
69 { 69 {
70 return 7; 70 return 7;
71 } 71 }
72 72
73 virtual void Compute(SQLite::FunctionContext& context) 73 virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE
74 { 74 {
75 std::string uncompressedMD5, compressedMD5; 75 std::string uncompressedMD5, compressedMD5;
76 76
77 if (!context.IsNullValue(5)) 77 if (!context.IsNullValue(5))
78 { 78 {
105 SignalResourceDeleted(IDatabaseListener& listener) : 105 SignalResourceDeleted(IDatabaseListener& listener) :
106 listener_(listener) 106 listener_(listener)
107 { 107 {
108 } 108 }
109 109
110 virtual const char* GetName() const 110 virtual const char* GetName() const ORTHANC_OVERRIDE
111 { 111 {
112 return "SignalResourceDeleted"; 112 return "SignalResourceDeleted";
113 } 113 }
114 114
115 virtual unsigned int GetCardinality() const 115 virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE
116 { 116 {
117 return 2; 117 return 2;
118 } 118 }
119 119
120 virtual void Compute(SQLite::FunctionContext& context) 120 virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE
121 { 121 {
122 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1)); 122 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1));
123 ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0)); 123 ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0));
124 listener_.SignalChange(change); 124 listener_.SignalChange(change);
125 } 125 }
141 void Reset() 141 void Reset()
142 { 142 {
143 hasRemainingAncestor_ = false; 143 hasRemainingAncestor_ = false;
144 } 144 }
145 145
146 virtual const char* GetName() const 146 virtual const char* GetName() const ORTHANC_OVERRIDE
147 { 147 {
148 return "SignalRemainingAncestor"; 148 return "SignalRemainingAncestor";
149 } 149 }
150 150
151 virtual unsigned int GetCardinality() const 151 virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE
152 { 152 {
153 return 2; 153 return 2;
154 } 154 }
155 155
156 virtual void Compute(SQLite::FunctionContext& context) 156 virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE
157 { 157 {
158 CLOG(TRACE, SQLITE) << "There exists a remaining ancestor with public ID \"" 158 CLOG(TRACE, SQLITE) << "There exists a remaining ancestor with public ID \""
159 << context.GetStringValue(0) << "\" of type " 159 << context.GetStringValue(0) << "\" of type "
160 << context.GetIntValue(1); 160 << context.GetIntValue(1);
161 161
615 // Debug mode 615 // Debug mode
616 initialDiskSize_ = static_cast<int64_t>(that_.GetTotalCompressedSize()); 616 initialDiskSize_ = static_cast<int64_t>(that_.GetTotalCompressedSize());
617 #endif 617 #endif
618 } 618 }
619 619
620 virtual void Begin() 620 void Begin()
621 { 621 {
622 transaction_->Begin(); 622 transaction_->Begin();
623 } 623 }
624 624
625 virtual void Rollback() 625 virtual void Rollback() ORTHANC_OVERRIDE
626 { 626 {
627 transaction_->Rollback(); 627 transaction_->Rollback();
628 } 628 }
629 629
630 virtual void Commit(int64_t fileSizeDelta /* only used in debug */) 630 virtual void Commit(int64_t fileSizeDelta /* only used in debug */) ORTHANC_OVERRIDE
631 { 631 {
632 transaction_->Commit(); 632 transaction_->Commit();
633 633
634 assert(initialDiskSize_ + fileSizeDelta >= 0 && 634 assert(initialDiskSize_ + fileSizeDelta >= 0 &&
635 initialDiskSize_ + fileSizeDelta == static_cast<int64_t>(that_.GetTotalCompressedSize())); 635 initialDiskSize_ + fileSizeDelta == static_cast<int64_t>(that_.GetTotalCompressedSize()));
637 }; 637 };
638 638
639 639
640 IDatabaseWrapper::ITransaction* SQLiteDatabaseWrapper::StartTransaction() 640 IDatabaseWrapper::ITransaction* SQLiteDatabaseWrapper::StartTransaction()
641 { 641 {
642 return new Transaction(*this); 642 std::unique_ptr<Transaction> transaction(new Transaction(*this));
643 transaction->Begin();
644 return transaction.release();
643 } 645 }
644 646
645 647
646 void SQLiteDatabaseWrapper::GetAllMetadata(std::map<MetadataType, std::string>& target, 648 void SQLiteDatabaseWrapper::GetAllMetadata(std::map<MetadataType, std::string>& target,
647 int64_t id) 649 int64_t id)
1158 { 1160 {
1159 private: 1161 private:
1160 std::list<std::string> values_; 1162 std::list<std::string> values_;
1161 1163
1162 public: 1164 public:
1163 virtual std::string GenerateParameter(const std::string& value) 1165 virtual std::string GenerateParameter(const std::string& value) ORTHANC_OVERRIDE
1164 { 1166 {
1165 values_.push_back(value); 1167 values_.push_back(value);
1166 return "?"; 1168 return "?";
1167 } 1169 }
1168 1170
1169 virtual std::string FormatResourceType(ResourceType level) 1171 virtual std::string FormatResourceType(ResourceType level) ORTHANC_OVERRIDE
1170 { 1172 {
1171 return boost::lexical_cast<std::string>(level); 1173 return boost::lexical_cast<std::string>(level);
1172 } 1174 }
1173 1175
1174 virtual std::string FormatWildcardEscape() 1176 virtual std::string FormatWildcardEscape() ORTHANC_OVERRIDE
1175 { 1177 {
1176 return "ESCAPE '\\'"; 1178 return "ESCAPE '\\'";
1177 } 1179 }
1178 1180
1179 void Bind(SQLite::Statement& statement) const 1181 void Bind(SQLite::Statement& statement) const