Mercurial > hg > orthanc-databases
annotate SQLite/Plugins/IndexPlugin.cpp @ 234:d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 08 Apr 2021 10:50:01 +0200 |
parents | c8e06b41feec |
children | 16aac0287485 |
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 | |
193
3236894320d6
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 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 "SQLiteIndex.h" | |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
23 #include "../../Framework/Plugins/PluginInitialization.h" |
0 | 24 |
152 | 25 #include <Logging.h> |
0 | 26 |
27 | |
28 extern "C" | |
29 { | |
30 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
31 { | |
28
c0cb5d2cd696
checks depending on Orthanc version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
32 if (!OrthancDatabases::InitializePlugin(context, "SQLite", true)) |
0 | 33 { |
34 return -1; | |
35 } | |
36 | |
37 #if 0 | |
62
eedd082355f9
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
38 OrthancPlugins::OrthancConfiguration configuration; |
0 | 39 |
40 if (!configuration.IsSection("SQLite")) | |
41 { | |
42 LOG(WARNING) << "No available configuration for the SQLite index plugin"; | |
43 return 0; | |
44 } | |
45 | |
46 OrthancPlugins::OrthancConfiguration sqlite; | |
47 configuration.GetSection(sqlite, "SQLite"); | |
48 | |
49 bool enable; | |
50 if (!sqlite.LookupBooleanValue(enable, "EnableIndex") || | |
51 !enable) | |
52 { | |
53 LOG(WARNING) << "The SQLite index is currently disabled, set \"EnableIndex\" " | |
54 << "to \"true\" in the \"SQLite\" section of the configuration file of Orthanc"; | |
55 return 0; | |
56 } | |
57 #endif | |
58 | |
59 try | |
60 { | |
61 /* Register the SQLite index into Orthanc */ | |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
62 OrthancDatabases::IndexBackend::Register( |
234
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
63 new OrthancDatabases::SQLiteIndex(context, "index.db"), // TODO parameter |
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
64 1 /* only 1 connection is possible with SQLite */, |
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
65 0 /* no collision is possible, as SQLite has a global lock */); |
0 | 66 } |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
67 catch (Orthanc::OrthancException& e) |
0 | 68 { |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
69 LOG(ERROR) << e.What(); |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
70 return -1; |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
71 } |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
72 catch (...) |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
73 { |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
74 LOG(ERROR) << "Native exception while initializing the plugin"; |
0 | 75 return -1; |
76 } | |
77 | |
78 return 0; | |
79 } | |
80 | |
81 | |
82 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
83 { | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
84 LOG(WARNING) << "SQLite index is finalizing"; |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
85 OrthancDatabases::IndexBackend::Finalize(); |
0 | 86 } |
87 | |
88 | |
89 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
90 { | |
91 return "sqlite-index"; | |
92 } | |
93 | |
94 | |
95 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
96 { | |
97 return ORTHANC_PLUGIN_VERSION; | |
98 } | |
99 } |