Mercurial > hg > orthanc-databases
comparison MySQL/Plugins/MySQLStorageArea.cpp @ 226:a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Apr 2021 19:23:36 +0200 |
parents | ee5858d438dc |
children | 35598014f140 |
comparison
equal
deleted
inserted
replaced
225:94c9908e6aca | 226:a4918d57435c |
---|---|
31 #include <boost/math/special_functions/round.hpp> | 31 #include <boost/math/special_functions/round.hpp> |
32 | 32 |
33 | 33 |
34 namespace OrthancDatabases | 34 namespace OrthancDatabases |
35 { | 35 { |
36 IDatabase* MySQLStorageArea::OpenInternal() | 36 void MySQLStorageArea::ConfigureDatabase(MySQLDatabase& db, |
37 const MySQLParameters& parameters, | |
38 bool clearAll) | |
37 { | 39 { |
38 std::unique_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_)); | |
39 | |
40 db->Open(); | |
41 | |
42 { | 40 { |
43 MySQLDatabase::TransientAdvisoryLock lock(*db, MYSQL_LOCK_DATABASE_SETUP); | 41 MySQLDatabase::TransientAdvisoryLock lock(db, MYSQL_LOCK_DATABASE_SETUP); |
44 MySQLTransaction t(*db, TransactionType_ReadWrite); | 42 MySQLTransaction t(db, TransactionType_ReadWrite); |
45 | 43 |
46 int64_t size; | 44 int64_t size; |
47 if (db->LookupGlobalIntegerVariable(size, "max_allowed_packet")) | 45 if (db.LookupGlobalIntegerVariable(size, "max_allowed_packet")) |
48 { | 46 { |
49 int mb = boost::math::iround(static_cast<double>(size) / | 47 int mb = boost::math::iround(static_cast<double>(size) / |
50 static_cast<double>(1024 * 1024)); | 48 static_cast<double>(1024 * 1024)); |
51 LOG(WARNING) << "Your MySQL server cannot " | 49 LOG(WARNING) << "Your MySQL server cannot " |
52 << "store DICOM files larger than " << mb << "MB"; | 50 << "store DICOM files larger than " << mb << "MB"; |
57 { | 55 { |
58 LOG(WARNING) << "Unable to auto-detect the maximum size of DICOM " | 56 LOG(WARNING) << "Unable to auto-detect the maximum size of DICOM " |
59 << "files that can be stored in this MySQL server"; | 57 << "files that can be stored in this MySQL server"; |
60 } | 58 } |
61 | 59 |
62 if (clearAll_) | 60 if (clearAll) |
63 { | 61 { |
64 db->Execute("DROP TABLE IF EXISTS StorageArea", false); | 62 db.Execute("DROP TABLE IF EXISTS StorageArea", false); |
65 } | 63 } |
66 | 64 |
67 db->Execute("CREATE TABLE IF NOT EXISTS StorageArea(" | 65 db.Execute("CREATE TABLE IF NOT EXISTS StorageArea(" |
68 "uuid VARCHAR(64) NOT NULL PRIMARY KEY," | 66 "uuid VARCHAR(64) NOT NULL PRIMARY KEY," |
69 "content LONGBLOB NOT NULL," | 67 "content LONGBLOB NOT NULL," |
70 "type INTEGER NOT NULL)", false); | 68 "type INTEGER NOT NULL)", false); |
71 | 69 |
72 t.Commit(); | 70 t.Commit(); |
73 } | 71 } |
74 | 72 |
75 /** | 73 /** |
78 * 5.7, it is impossible to acquire more than one lock at a time, | 76 * 5.7, it is impossible to acquire more than one lock at a time, |
79 * as calling "SELECT GET_LOCK()" releases all the | 77 * as calling "SELECT GET_LOCK()" releases all the |
80 * previously-acquired locks. | 78 * previously-acquired locks. |
81 * https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html | 79 * https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html |
82 **/ | 80 **/ |
83 if (parameters_.HasLock()) | 81 if (parameters.HasLock()) |
84 { | 82 { |
85 db->AdvisoryLock(MYSQL_LOCK_STORAGE); | 83 db.AdvisoryLock(MYSQL_LOCK_STORAGE); |
86 } | 84 } |
87 | |
88 return db.release(); | |
89 } | 85 } |
90 | 86 |
91 | 87 |
92 MySQLStorageArea::MySQLStorageArea(const MySQLParameters& parameters) : | 88 MySQLStorageArea::MySQLStorageArea(const MySQLParameters& parameters, |
93 StorageBackend(new Factory(*this)), | 89 bool clearAll) |
94 parameters_(parameters), | |
95 clearAll_(false) | |
96 { | 90 { |
91 std::unique_ptr<MySQLDatabase> database(MySQLDatabase::OpenDatabaseConnection(parameters)); | |
92 | |
93 if (database.get() == NULL) | |
94 { | |
95 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
96 } | |
97 | |
98 ConfigureDatabase(*database, parameters, clearAll); | |
99 SetDatabase(database.release()); | |
97 } | 100 } |
98 } | 101 } |