Mercurial > hg > orthanc-databases
annotate MySQL/Plugins/IndexPlugin.cpp @ 536:4ecf50a4521c find-refactoring tip
sync ISqlLookupFormatter from Orthanc + fix bug 224: LIMIT shall not be used with MSSQL
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Fri, 06 Sep 2024 16:56:37 +0200 |
parents | 54d518dcd74a |
children |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
507
54d518dcd74a
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
492
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
54d518dcd74a
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
492
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
459
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU Affero General Public License | |
11 * as published by the Free Software Foundation, either version 3 of | |
12 * the License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * Affero General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU Affero General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "MySQLIndex.h" | |
25 #include "../../Framework/MySQL/MySQLDatabase.h" | |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
26 #include "../../Framework/Plugins/PluginInitialization.h" |
0 | 27 |
152 | 28 #include <HttpClient.h> |
29 #include <Logging.h> | |
30 #include <Toolbox.h> | |
0 | 31 |
381
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
32 #include <google/protobuf/any.h> |
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
33 |
492
af6998ed73dd
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
459
diff
changeset
|
34 #define ORTHANC_PLUGIN_NAME "mysql-index" |
0 | 35 |
36 extern "C" | |
37 { | |
38 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
39 { | |
381
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
40 GOOGLE_PROTOBUF_VERIFY_VERSION; |
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
41 |
492
af6998ed73dd
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
459
diff
changeset
|
42 if (!OrthancDatabases::InitializePlugin(context, ORTHANC_PLUGIN_NAME, "MySQL", true)) |
0 | 43 { |
44 return -1; | |
45 } | |
46 | |
42 | 47 Orthanc::Toolbox::InitializeOpenSsl(); |
40
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
48 Orthanc::HttpClient::GlobalInitialize(); |
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
49 |
62
eedd082355f9
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
42
diff
changeset
|
50 OrthancPlugins::OrthancConfiguration configuration; |
0 | 51 |
52 if (!configuration.IsSection("MySQL")) | |
53 { | |
54 LOG(WARNING) << "No available configuration for the MySQL index plugin"; | |
55 return 0; | |
56 } | |
57 | |
58 OrthancPlugins::OrthancConfiguration mysql; | |
59 configuration.GetSection(mysql, "MySQL"); | |
60 | |
61 bool enable; | |
62 if (!mysql.LookupBooleanValue(enable, "EnableIndex") || | |
63 !enable) | |
64 { | |
65 LOG(WARNING) << "The MySQL index is currently disabled, set \"EnableIndex\" " | |
66 << "to \"true\" in the \"MySQL\" section of the configuration file of Orthanc"; | |
67 return 0; | |
68 } | |
69 | |
70 try | |
71 { | |
253
3bc442765b88
new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
72 const size_t countConnections = mysql.GetUnsignedIntegerValue("IndexConnectionsCount", 1); |
3bc442765b88
new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
73 |
163
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
74 OrthancDatabases::MySQLParameters parameters(mysql, configuration); |
234
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
75 OrthancDatabases::IndexBackend::Register( |
253
3bc442765b88
new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
76 new OrthancDatabases::MySQLIndex(context, parameters), countConnections, |
3bc442765b88
new configuration option: "IndexConnectionsCount"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
77 parameters.GetMaxConnectionRetries()); |
0 | 78 } |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
79 catch (Orthanc::OrthancException& e) |
0 | 80 { |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
81 LOG(ERROR) << e.What(); |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
82 return -1; |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
83 } |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
84 catch (...) |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
85 { |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
86 LOG(ERROR) << "Native exception while initializing the plugin"; |
0 | 87 return -1; |
88 } | |
89 | |
90 return 0; | |
91 } | |
92 | |
93 | |
94 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
95 { | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
96 LOG(WARNING) << "MySQL index is finalizing"; |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
97 OrthancDatabases::IndexBackend::Finalize(); |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
98 |
0 | 99 OrthancDatabases::MySQLDatabase::GlobalFinalization(); |
40
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
100 Orthanc::HttpClient::GlobalFinalize(); |
42 | 101 Orthanc::Toolbox::FinalizeOpenSsl(); |
381
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
102 google::protobuf::ShutdownProtobufLibrary(); |
0 | 103 } |
104 | |
105 | |
106 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
107 { | |
492
af6998ed73dd
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
459
diff
changeset
|
108 return ORTHANC_PLUGIN_NAME; |
0 | 109 } |
110 | |
111 | |
112 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
113 { | |
114 return ORTHANC_PLUGIN_VERSION; | |
115 } | |
116 } |