Mercurial > hg > orthanc-databases
comparison MySQL/Plugins/StoragePlugin.cpp @ 17:54ea251aed70
unit test
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Jul 2018 10:33:02 +0200 |
parents | 9e419261f1c9 |
children | 17f849b2af34 |
comparison
equal
deleted
inserted
replaced
16:9e419261f1c9 | 17:54ea251aed70 |
---|---|
17 * You should have received a copy of the GNU Affero General Public License | 17 * You should have received a copy of the GNU Affero General Public License |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "../../Framework/Plugins/StorageBackend.h" | 22 #include "MySQLStorageArea.h" |
23 #include "../../Framework/MySQL/MySQLDatabase.h" | |
23 | 24 |
24 #include <Core/Logging.h> | 25 #include <Core/Logging.h> |
25 | |
26 | |
27 #include "../../Framework/Common/Integer64Value.h" | |
28 #include "../../Framework/MySQL/MySQLDatabase.h" | |
29 #include "../../Framework/MySQL/MySQLResult.h" | |
30 #include "../../Framework/MySQL/MySQLStatement.h" | |
31 #include "../../Framework/MySQL/MySQLTransaction.h" | |
32 | |
33 #include <boost/math/special_functions/round.hpp> | |
34 | |
35 namespace OrthancDatabases | |
36 { | |
37 class MySQLStorageArea : public StorageBackend | |
38 { | |
39 private: | |
40 class Factory : public IDatabaseFactory | |
41 { | |
42 private: | |
43 MySQLStorageArea& that_; | |
44 | |
45 public: | |
46 Factory(MySQLStorageArea& that) : | |
47 that_(that) | |
48 { | |
49 } | |
50 | |
51 virtual Dialect GetDialect() const | |
52 { | |
53 return Dialect_MySQL; | |
54 } | |
55 | |
56 virtual IDatabase* Open() | |
57 { | |
58 return that_.OpenInternal(); | |
59 } | |
60 }; | |
61 | |
62 OrthancPluginContext* context_; | |
63 MySQLParameters parameters_; | |
64 bool clearAll_; | |
65 | |
66 IDatabase* OpenInternal() | |
67 { | |
68 std::auto_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_)); | |
69 | |
70 db->Open(); | |
71 | |
72 if (parameters_.HasLock()) | |
73 { | |
74 db->AdvisoryLock(43 /* some arbitrary constant */); | |
75 } | |
76 | |
77 { | |
78 MySQLTransaction t(*db); | |
79 | |
80 int64_t size; | |
81 if (db->LookupGlobalIntegerVariable(size, "max_allowed_packet")) | |
82 { | |
83 int mb = boost::math::iround(static_cast<double>(size) / | |
84 static_cast<double>(1024 * 1024)); | |
85 LOG(WARNING) << "Your MySQL server cannot " | |
86 << "store DICOM files larger than " << mb << "MB"; | |
87 LOG(WARNING) << " => Consider increasing \"max_allowed_packet\" " | |
88 << "in \"my.cnf\" if this limit is insufficient for your use"; | |
89 } | |
90 else | |
91 { | |
92 LOG(WARNING) << "Unable to auto-detect the maximum size of DICOM " | |
93 << "files that can be stored in this MySQL server"; | |
94 } | |
95 | |
96 if (clearAll_) | |
97 { | |
98 db->Execute("DROP TABLE IF EXISTS StorageArea", false); | |
99 } | |
100 | |
101 db->Execute("CREATE TABLE IF NOT EXISTS StorageArea(" | |
102 "uuid VARCHAR(64) NOT NULL PRIMARY KEY," | |
103 "content LONGBLOB NOT NULL," | |
104 "type INTEGER NOT NULL)", false); | |
105 | |
106 t.Commit(); | |
107 } | |
108 | |
109 return db.release(); | |
110 } | |
111 | |
112 public: | |
113 MySQLStorageArea(const MySQLParameters& parameters) : | |
114 StorageBackend(new Factory(*this)), | |
115 parameters_(parameters), | |
116 clearAll_(false) | |
117 { | |
118 } | |
119 | |
120 void SetClearAll(bool clear) | |
121 { | |
122 clearAll_ = clear; | |
123 } | |
124 }; | |
125 } | |
126 | |
127 | |
128 | 26 |
129 | 27 |
130 static bool DisplayPerformanceWarning() | 28 static bool DisplayPerformanceWarning() |
131 { | 29 { |
132 (void) DisplayPerformanceWarning; // Disable warning about unused function | 30 (void) DisplayPerformanceWarning; // Disable warning about unused function |