annotate PostgreSQL/Plugins/StoragePlugin.cpp @ 365:7671fa7f099e OrthancOdbc-1.1

todo
author Alain Mazy <am@osimis.io>
date Tue, 05 Jul 2022 08:44:26 +0200
parents 567761f0c1ea
children 16aac0287485
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
193
3236894320d6 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
2
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
16
9e419261f1c9 mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
22 #include "PostgreSQLStorageArea.h"
24
17f849b2af34 sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
23 #include "../../Framework/Plugins/PluginInitialization.h"
12
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
24
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
25 #include <Logging.h>
267
ece4663dedde Fix issue #193
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
26 #include <Toolbox.h>
12
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
27
2
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 extern "C"
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
28
c0cb5d2cd696 checks depending on Orthanc version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
32 if (!OrthancDatabases::InitializePlugin(context, "PostgreSQL", false))
2
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 return -1;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
267
ece4663dedde Fix issue #193
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
37 Orthanc::Toolbox::InitializeOpenSsl();
ece4663dedde Fix issue #193
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
38
62
eedd082355f9 fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 28
diff changeset
39 OrthancPlugins::OrthancConfiguration configuration;
2
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 if (!configuration.IsSection("PostgreSQL"))
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 LOG(WARNING) << "No available configuration for the PostgreSQL storage area plugin";
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 return 0;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 OrthancPlugins::OrthancConfiguration postgresql;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 configuration.GetSection(postgresql, "PostgreSQL");
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 bool enable;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 if (!postgresql.LookupBooleanValue(enable, "EnableStorage") ||
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 !enable)
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 LOG(WARNING) << "The PostgreSQL storage area is currently disabled, set \"EnableStorage\" "
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 << "to \"true\" in the \"PostgreSQL\" section of the configuration file of Orthanc";
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 return 0;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 try
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
12
41543239072d transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
61 OrthancDatabases::PostgreSQLParameters parameters(postgresql);
269
567761f0c1ea fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 267
diff changeset
62 OrthancDatabases::StorageBackend::Register(
567761f0c1ea fix issue #151: support of retries in the storage area plugins to deal with multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 267
diff changeset
63 context, new OrthancDatabases::PostgreSQLStorageArea(parameters, false /* don't clear database */));
2
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 catch (Orthanc::OrthancException& e)
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 LOG(ERROR) << e.What();
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 return -1;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 catch (...)
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 LOG(ERROR) << "Native exception while initializing the plugin";
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 return -1;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 return 0;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 LOG(WARNING) << "PostgreSQL storage area is finalizing";
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 OrthancDatabases::StorageBackend::Finalize();
267
ece4663dedde Fix issue #193
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
84 Orthanc::Toolbox::FinalizeOpenSsl();
2
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 return "postgresql-storage";
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 return ORTHANC_PLUGIN_VERSION;
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
17bce6a07b2b storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }