Mercurial > hg > orthanc-databases
annotate Framework/PostgreSQL/PostgreSQLParameters.h @ 485:9722e408d817 OrthancPostgreSQL-6.0
closing OrthancPostgreSQL-6.0
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 22 Mar 2024 13:34:19 +0100 |
parents | 11c6bcc9d1f2 |
children | 8e6a95629a22 |
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 | |
459
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Affero General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Affero General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Affero General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #pragma once | |
24 | |
25 #if ORTHANC_ENABLE_POSTGRESQL != 1 | |
26 # error PostgreSQL support must be enabled to use this file | |
27 #endif | |
28 | |
152 | 29 #include "../../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
0 | 30 |
31 namespace OrthancDatabases | |
32 { | |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
33 enum IsolationMode |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
34 { |
470 | 35 IsolationMode_Serializable = 0, |
36 IsolationMode_ReadCommited = 1 | |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
37 }; |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
38 |
0 | 39 class PostgreSQLParameters |
40 { | |
41 private: | |
42 std::string host_; | |
43 uint16_t port_; | |
44 std::string username_; | |
45 std::string password_; | |
46 std::string database_; | |
47 std::string uri_; | |
80
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
48 bool ssl_; |
0 | 49 bool lock_; |
141
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
50 unsigned int maxConnectionRetries_; |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
51 unsigned int connectionRetryInterval_; |
429
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
52 bool isVerboseEnabled_; |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
53 IsolationMode isolationMode_; |
0 | 54 void Reset(); |
55 | |
56 public: | |
57 PostgreSQLParameters(); | |
58 | |
186 | 59 explicit PostgreSQLParameters(const OrthancPlugins::OrthancConfiguration& configuration); |
0 | 60 |
61 void SetConnectionUri(const std::string& uri); | |
62 | |
63 std::string GetConnectionUri() const; | |
64 | |
65 void SetHost(const std::string& host); | |
66 | |
67 const std::string& GetHost() const | |
68 { | |
69 return host_; | |
70 } | |
71 | |
72 void SetPortNumber(unsigned int port); | |
73 | |
74 uint16_t GetPortNumber() const | |
75 { | |
76 return port_; | |
77 } | |
78 | |
79 void SetUsername(const std::string& username); | |
80 | |
81 const std::string& GetUsername() const | |
82 { | |
83 return username_; | |
84 } | |
85 | |
86 void SetPassword(const std::string& password); | |
87 | |
88 const std::string& GetPassword() const | |
89 { | |
90 return password_; | |
91 } | |
92 | |
93 void SetDatabase(const std::string& database); | |
94 | |
95 void ResetDatabase() | |
96 { | |
97 SetDatabase(""); | |
98 } | |
99 | |
100 const std::string& GetDatabase() const | |
101 { | |
102 return database_; | |
103 } | |
104 | |
80
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
105 void SetSsl(bool ssl) |
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
106 { |
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
107 ssl_ = ssl; |
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
108 } |
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
109 |
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
110 bool IsSsl() const |
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
111 { |
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
112 return ssl_; |
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
113 } |
16df1a6ea452
Fix issue 105 (Unable to connect to PostgreSQL database using SSL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
114 |
0 | 115 void SetLock(bool lock) |
116 { | |
117 lock_ = lock; | |
118 } | |
119 | |
120 bool HasLock() const | |
121 { | |
122 return lock_; | |
123 } | |
124 | |
141
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
125 unsigned int GetMaxConnectionRetries() const |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
126 { |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
127 return maxConnectionRetries_; |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
128 } |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
129 |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
130 unsigned int GetConnectionRetryInterval() const |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
131 { |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
132 return connectionRetryInterval_; |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
133 } |
0b3e9ee53c46
Added 'MaximumConnectionRetries' & 'ConnectionRetryInterval' to configure the retries when connecting to the DB at startup
Alain Mazy <alain@mazy.be>
parents:
140
diff
changeset
|
134 |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
135 void SetIsolationMode(IsolationMode isolationMode) |
370
d2b5d9c92214
PG: test feature: configurable transaction isolation level
Alain Mazy <am@osimis.io>
parents:
359
diff
changeset
|
136 { |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
137 isolationMode_ = isolationMode; |
370
d2b5d9c92214
PG: test feature: configurable transaction isolation level
Alain Mazy <am@osimis.io>
parents:
359
diff
changeset
|
138 } |
d2b5d9c92214
PG: test feature: configurable transaction isolation level
Alain Mazy <am@osimis.io>
parents:
359
diff
changeset
|
139 |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
140 const char* GetReadWriteTransactionStatement() const |
370
d2b5d9c92214
PG: test feature: configurable transaction isolation level
Alain Mazy <am@osimis.io>
parents:
359
diff
changeset
|
141 { |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
142 switch (isolationMode_) |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
143 { |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
144 case IsolationMode_ReadCommited: |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
145 return "SET TRANSACTION ISOLATION LEVEL READ COMMITTED READ WRITE"; |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
146 case IsolationMode_Serializable: |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
147 return "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE"; |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
148 default: |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
149 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
150 } |
370
d2b5d9c92214
PG: test feature: configurable transaction isolation level
Alain Mazy <am@osimis.io>
parents:
359
diff
changeset
|
151 } |
d2b5d9c92214
PG: test feature: configurable transaction isolation level
Alain Mazy <am@osimis.io>
parents:
359
diff
changeset
|
152 |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
153 const char* GetReadOnlyTransactionStatement() const |
370
d2b5d9c92214
PG: test feature: configurable transaction isolation level
Alain Mazy <am@osimis.io>
parents:
359
diff
changeset
|
154 { |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
155 switch (isolationMode_) |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
156 { |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
157 case IsolationMode_ReadCommited: |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
158 return "SET TRANSACTION ISOLATION LEVEL READ COMMITTED READ ONLY"; |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
159 case IsolationMode_Serializable: |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
160 return "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY"; |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
161 default: |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
162 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
429
diff
changeset
|
163 } |
370
d2b5d9c92214
PG: test feature: configurable transaction isolation level
Alain Mazy <am@osimis.io>
parents:
359
diff
changeset
|
164 } |
d2b5d9c92214
PG: test feature: configurable transaction isolation level
Alain Mazy <am@osimis.io>
parents:
359
diff
changeset
|
165 |
429
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
166 void SetVerboseEnabled(bool enabled) |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
167 { |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
168 isVerboseEnabled_ = enabled; |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
169 } |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
170 |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
171 bool IsVerboseEnabled() const |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
172 { |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
173 return isVerboseEnabled_; |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
174 } |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
175 |
dbf811b1bb43
new configuration 'EnableVerboseLogs' to log SQL statements being executed
Alain Mazy <am@osimis.io>
parents:
417
diff
changeset
|
176 |
0 | 177 void Format(std::string& target) const; |
178 }; | |
179 } |