17
|
1 /**
|
|
2 * Orthanc - A Lightweight, RESTful DICOM Store
|
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
|
|
4 * Department, University Hospital of Liege, Belgium
|
67
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
|
17
|
6 *
|
|
7 * This program is free software: you can redistribute it and/or
|
|
8 * modify it under the terms of the GNU Affero General Public License
|
|
9 * as published by the Free Software Foundation, either version 3 of
|
|
10 * the License, or (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful, but
|
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 * Affero General Public License for more details.
|
|
16 *
|
|
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/>.
|
|
19 **/
|
|
20
|
|
21
|
|
22 #include "MySQLStorageArea.h"
|
|
23
|
|
24 #include "../../Framework/MySQL/MySQLDatabase.h"
|
|
25 #include "../../Framework/MySQL/MySQLTransaction.h"
|
|
26
|
|
27 #include <Core/Logging.h>
|
|
28
|
|
29 #include <boost/math/special_functions/round.hpp>
|
|
30
|
|
31
|
|
32 namespace OrthancDatabases
|
|
33 {
|
|
34 IDatabase* MySQLStorageArea::OpenInternal()
|
|
35 {
|
|
36 std::auto_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_));
|
|
37
|
|
38 db->Open();
|
|
39
|
|
40 if (parameters_.HasLock())
|
|
41 {
|
|
42 db->AdvisoryLock(43 /* some arbitrary constant */);
|
|
43 }
|
|
44
|
|
45 {
|
|
46 MySQLTransaction t(*db);
|
|
47
|
|
48 int64_t size;
|
|
49 if (db->LookupGlobalIntegerVariable(size, "max_allowed_packet"))
|
|
50 {
|
|
51 int mb = boost::math::iround(static_cast<double>(size) /
|
|
52 static_cast<double>(1024 * 1024));
|
|
53 LOG(WARNING) << "Your MySQL server cannot "
|
|
54 << "store DICOM files larger than " << mb << "MB";
|
|
55 LOG(WARNING) << " => Consider increasing \"max_allowed_packet\" "
|
|
56 << "in \"my.cnf\" if this limit is insufficient for your use";
|
|
57 }
|
|
58 else
|
|
59 {
|
|
60 LOG(WARNING) << "Unable to auto-detect the maximum size of DICOM "
|
|
61 << "files that can be stored in this MySQL server";
|
|
62 }
|
|
63
|
|
64 if (clearAll_)
|
|
65 {
|
|
66 db->Execute("DROP TABLE IF EXISTS StorageArea", false);
|
|
67 }
|
|
68
|
|
69 db->Execute("CREATE TABLE IF NOT EXISTS StorageArea("
|
|
70 "uuid VARCHAR(64) NOT NULL PRIMARY KEY,"
|
|
71 "content LONGBLOB NOT NULL,"
|
|
72 "type INTEGER NOT NULL)", false);
|
|
73
|
|
74 t.Commit();
|
|
75 }
|
|
76
|
|
77 return db.release();
|
|
78 }
|
|
79
|
|
80
|
|
81 MySQLStorageArea::MySQLStorageArea(const MySQLParameters& parameters) :
|
|
82 StorageBackend(new Factory(*this)),
|
|
83 parameters_(parameters),
|
|
84 clearAll_(false)
|
|
85 {
|
|
86 }
|
|
87 }
|