annotate MySQL/Plugins/MySQLStorageArea.cpp @ 67:714c5d2bee76

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