Mercurial > hg > orthanc-databases
annotate Framework/PostgreSQL/PostgreSQLDatabase.h @ 348:47db0b70f705 OrthancPostgreSQL-3.3
closing OrthancPostgreSQL-3.3
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Aug 2021 16:09:37 +0200 |
parents | 4cd7e45b671e |
children | 6fe74f9a516e |
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 | |
140
4cd7e45b671e
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
5 * Copyright (C) 2017-2020 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 #pragma once | |
23 | |
24 #if ORTHANC_ENABLE_POSTGRESQL != 1 | |
25 # error PostgreSQL support must be enabled to use this file | |
26 #endif | |
27 | |
28 #include "PostgreSQLParameters.h" | |
29 #include "../Common/IDatabase.h" | |
30 | |
31 namespace OrthancDatabases | |
32 { | |
33 class PostgreSQLDatabase : public IDatabase | |
34 { | |
35 private: | |
36 friend class PostgreSQLStatement; | |
37 friend class PostgreSQLLargeObject; | |
38 | |
39 PostgreSQLParameters parameters_; | |
40 void* pg_; /* Object of type "PGconn*" */ | |
41 | |
42 void ThrowException(bool log); | |
43 | |
44 void Close(); | |
45 | |
134
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
46 bool RunAdvisoryLockStatement(const std::string& statement); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
47 |
0 | 48 public: |
49 PostgreSQLDatabase(const PostgreSQLParameters& parameters) : | |
50 parameters_(parameters), | |
51 pg_(NULL) | |
52 { | |
53 } | |
54 | |
46
6a574d810b98
Compatibility with MySQL 8.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
55 ~PostgreSQLDatabase(); |
0 | 56 |
57 void Open(); | |
58 | |
134
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
59 bool AcquireAdvisoryLock(int32_t lock); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
60 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
61 bool ReleaseAdvisoryLock(int32_t lock); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
62 |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
63 void AdvisoryLock(int32_t lock); |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
64 |
0 | 65 void Execute(const std::string& sql); |
66 | |
67 bool DoesTableExist(const char* name); | |
68 | |
69 void ClearAll(); // Only for unit tests! | |
70 | |
71 virtual Dialect GetDialect() const | |
72 { | |
73 return Dialect_PostgreSQL; | |
74 } | |
75 | |
76 virtual IPrecompiledStatement* Compile(const Query& query); | |
77 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
12
diff
changeset
|
78 virtual ITransaction* CreateTransaction(bool isImplicit); |
134
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
79 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
80 class TransientAdvisoryLock |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
81 { |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
82 private: |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
83 PostgreSQLDatabase& database_; |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
84 int32_t lock_; |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
85 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
86 public: |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
87 TransientAdvisoryLock(PostgreSQLDatabase& database, |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
88 int32_t lock); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
89 |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
90 ~TransientAdvisoryLock(); |
cc3dc759c989
Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
91 }; |
0 | 92 }; |
93 } |