Mercurial > hg > orthanc-databases
comparison MySQL/Plugins/MySQLIndex.cpp @ 241:a063bbf10a3e
simplification of class DatabaseManager::Transaction
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 13 Apr 2021 12:07:30 +0200 |
parents | f033cc039264 |
children | 33fa478c119a |
comparison
equal
deleted
inserted
replaced
240:c82c2cf84ae8 | 241:a063bbf10a3e |
---|---|
110 * https://groups.google.com/d/msg/orthanc-users/OCFFkm1qm0k/Mbroy8VWAQAJ | 110 * https://groups.google.com/d/msg/orthanc-users/OCFFkm1qm0k/Mbroy8VWAQAJ |
111 **/ | 111 **/ |
112 { | 112 { |
113 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); | 113 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
114 | 114 |
115 t.ExecuteMultiLines("ALTER DATABASE " + parameters_.GetDatabase() + | 115 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER DATABASE " + parameters_.GetDatabase() + |
116 " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); | 116 " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); |
117 | 117 |
118 // This is the first table to be created | 118 // This is the first table to be created |
119 if (!t.DoesTableExist("GlobalProperties")) | 119 if (!t.GetDatabaseTransaction().DoesTableExist("GlobalProperties")) |
120 { | 120 { |
121 std::string query; | 121 std::string query; |
122 | 122 |
123 Orthanc::EmbeddedResources::GetFileResource | 123 Orthanc::EmbeddedResources::GetFileResource |
124 (query, Orthanc::EmbeddedResources::MYSQL_PREPARE_INDEX); | 124 (query, Orthanc::EmbeddedResources::MYSQL_PREPARE_INDEX); |
125 | 125 |
126 // Need to escape arobases: Don't use "t.ExecuteMultiLines()" here | 126 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here |
127 db.ExecuteMultiLines(query, true); | 127 db.ExecuteMultiLines(query, true); |
128 } | 128 } |
129 | 129 |
130 t.Commit(); | 130 t.Commit(); |
131 } | 131 } |
142 | 142 |
143 { | 143 { |
144 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); | 144 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
145 | 145 |
146 // This is the last table to be created | 146 // This is the last table to be created |
147 if (!t.DoesTableExist("PatientRecyclingOrder")) | 147 if (!t.GetDatabaseTransaction().DoesTableExist("PatientRecyclingOrder")) |
148 { | 148 { |
149 LOG(ERROR) << "Corrupted MySQL database"; | 149 LOG(ERROR) << "Corrupted MySQL database"; |
150 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 150 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
151 } | 151 } |
152 | 152 |
153 // This is the last item to be created | 153 // This is the last item to be created |
154 if (!t.DoesTriggerExist("PatientAdded")) | 154 if (!t.GetDatabaseTransaction().DoesTriggerExist("PatientAdded")) |
155 { | 155 { |
156 ThrowCannotCreateTrigger(); | 156 ThrowCannotCreateTrigger(); |
157 } | 157 } |
158 | 158 |
159 if (!LookupGlobalIntegerProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion)) | 159 if (!LookupGlobalIntegerProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion)) |
192 | 192 |
193 // The serialization of jobs as a global property can lead to | 193 // The serialization of jobs as a global property can lead to |
194 // very long values => switch to the LONGTEXT type that can | 194 // very long values => switch to the LONGTEXT type that can |
195 // store up to 4GB: | 195 // store up to 4GB: |
196 // https://stackoverflow.com/a/13932834/881731 | 196 // https://stackoverflow.com/a/13932834/881731 |
197 t.ExecuteMultiLines("ALTER TABLE GlobalProperties MODIFY value LONGTEXT"); | 197 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE GlobalProperties MODIFY value LONGTEXT"); |
198 | 198 |
199 revision = 2; | 199 revision = 2; |
200 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); | 200 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
201 | 201 |
202 t.Commit(); | 202 t.Commit(); |
210 std::string query; | 210 std::string query; |
211 | 211 |
212 Orthanc::EmbeddedResources::GetFileResource | 212 Orthanc::EmbeddedResources::GetFileResource |
213 (query, Orthanc::EmbeddedResources::MYSQL_GET_LAST_CHANGE_INDEX); | 213 (query, Orthanc::EmbeddedResources::MYSQL_GET_LAST_CHANGE_INDEX); |
214 | 214 |
215 // Need to escape arobases: Don't use "t.ExecuteMultiLines()" here | 215 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here |
216 db.ExecuteMultiLines(query, true); | 216 db.ExecuteMultiLines(query, true); |
217 | 217 |
218 if (!t.DoesTriggerExist("ChangeAdded")) | 218 if (!t.GetDatabaseTransaction().DoesTriggerExist("ChangeAdded")) |
219 { | 219 { |
220 ThrowCannotCreateTrigger(); | 220 ThrowCannotCreateTrigger(); |
221 } | 221 } |
222 | 222 |
223 revision = 3; | 223 revision = 3; |
233 // Reconfiguration of "Metadata" from TEXT type (up to 64KB) | 233 // Reconfiguration of "Metadata" from TEXT type (up to 64KB) |
234 // to the LONGTEXT type (up to 4GB). This might be important | 234 // to the LONGTEXT type (up to 4GB). This might be important |
235 // for applications such as the Osimis Web viewer that stores | 235 // for applications such as the Osimis Web viewer that stores |
236 // large amount of metadata. | 236 // large amount of metadata. |
237 // http://book.orthanc-server.com/faq/features.html#central-registry-of-metadata-and-attachments | 237 // http://book.orthanc-server.com/faq/features.html#central-registry-of-metadata-and-attachments |
238 t.ExecuteMultiLines("ALTER TABLE Metadata MODIFY value LONGTEXT"); | 238 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE Metadata MODIFY value LONGTEXT"); |
239 | 239 |
240 revision = 4; | 240 revision = 4; |
241 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); | 241 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
242 | 242 |
243 t.Commit(); | 243 t.Commit(); |
251 std::string query; | 251 std::string query; |
252 | 252 |
253 Orthanc::EmbeddedResources::GetFileResource | 253 Orthanc::EmbeddedResources::GetFileResource |
254 (query, Orthanc::EmbeddedResources::MYSQL_CREATE_INSTANCE); | 254 (query, Orthanc::EmbeddedResources::MYSQL_CREATE_INSTANCE); |
255 | 255 |
256 // Need to escape arobases: Don't use "t.ExecuteMultiLines()" here | 256 // Need to escape arobases: Don't use "t.GetDatabaseTransaction().ExecuteMultiLines()" here |
257 db.ExecuteMultiLines(query, true); | 257 db.ExecuteMultiLines(query, true); |
258 | 258 |
259 revision = 5; | 259 revision = 5; |
260 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); | 260 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
261 | 261 |
271 | 271 |
272 { | 272 { |
273 // New in release 4.0 to deal with multiple writers | 273 // New in release 4.0 to deal with multiple writers |
274 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); | 274 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
275 | 275 |
276 if (!t.DoesTableExist("ServerProperties")) | 276 if (!t.GetDatabaseTransaction().DoesTableExist("ServerProperties")) |
277 { | 277 { |
278 t.ExecuteMultiLines("CREATE TABLE ServerProperties(server VARCHAR(64) NOT NULL, " | 278 t.GetDatabaseTransaction().ExecuteMultiLines("CREATE TABLE ServerProperties(server VARCHAR(64) NOT NULL, " |
279 "property INTEGER, value TEXT, PRIMARY KEY(server, property))"); | 279 "property INTEGER, value TEXT, PRIMARY KEY(server, property))"); |
280 } | 280 } |
281 | 281 |
282 t.Commit(); | 282 t.Commit(); |
283 } | 283 } |
284 } | 284 } |