Mercurial > hg > orthanc
annotate OrthancServer/Plugins/Samples/DelayedDeletion/PendingDeletionsDatabase.cpp @ 5573:823aae1ea72a
removed dependency of HouseKeeper upon Orthanc::Logging
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Apr 2024 16:01:26 +0200 |
parents | 48b8dae6dc77 |
children | f7adfb22e20e |
rev | line source |
---|---|
5264
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
1 /** |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5264
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5264
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
5264
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
7 * |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
9 * modify it under the terms of the GNU General Public License as |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
10 * published by the Free Software Foundation, either version 3 of the |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
11 * License, or (at your option) any later version. |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
12 * |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
16 * General Public License for more details. |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
17 * |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
20 **/ |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
21 |
99751c5a7cfe
added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5024
diff
changeset
|
22 |
5024 | 23 #include "PendingDeletionsDatabase.h" |
24 | |
25 #include "../../../../OrthancFramework/Sources/SQLite/Statement.h" | |
26 #include "../../../../OrthancFramework/Sources/SQLite/Transaction.h" | |
27 | |
28 void PendingDeletionsDatabase::Setup() | |
29 { | |
30 // Performance tuning of SQLite with PRAGMAs | |
31 // http://www.sqlite.org/pragma.html | |
32 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;"); | |
33 db_.Execute("PRAGMA JOURNAL_MODE=WAL;"); | |
34 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); | |
35 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); | |
36 | |
37 { | |
38 Orthanc::SQLite::Transaction t(db_); | |
39 t.Begin(); | |
40 | |
41 if (!db_.DoesTableExist("Pending")) | |
42 { | |
43 db_.Execute("CREATE TABLE Pending(uuid TEXT, type INTEGER)"); | |
44 } | |
45 | |
46 t.Commit(); | |
47 } | |
48 } | |
49 | |
50 | |
51 PendingDeletionsDatabase::PendingDeletionsDatabase(const std::string& path) | |
52 { | |
53 db_.Open(path); | |
54 Setup(); | |
55 } | |
56 | |
57 | |
58 void PendingDeletionsDatabase::Enqueue(const std::string& uuid, | |
59 Orthanc::FileContentType type) | |
60 { | |
61 boost::mutex::scoped_lock lock(mutex_); | |
62 | |
63 Orthanc::SQLite::Transaction t(db_); | |
64 t.Begin(); | |
65 | |
66 { | |
67 Orthanc::SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Pending VALUES(?, ?)"); | |
68 s.BindString(0, uuid); | |
69 s.BindInt(1, type); | |
70 s.Run(); | |
71 } | |
72 | |
73 t.Commit(); | |
74 } | |
75 | |
76 | |
77 bool PendingDeletionsDatabase::Dequeue(std::string& uuid, | |
78 Orthanc::FileContentType& type) | |
79 { | |
80 bool ok = false; | |
81 | |
82 boost::mutex::scoped_lock lock(mutex_); | |
83 | |
84 Orthanc::SQLite::Transaction t(db_); | |
85 t.Begin(); | |
86 | |
87 { | |
88 Orthanc::SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT uuid, type FROM Pending LIMIT 1"); | |
89 | |
90 if (s.Step()) | |
91 { | |
92 uuid = s.ColumnString(0); | |
93 type = static_cast<Orthanc::FileContentType>(s.ColumnInt(1)); | |
94 | |
95 Orthanc::SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Pending WHERE uuid=?"); | |
96 s.BindString(0, uuid); | |
97 s.Run(); | |
98 | |
99 ok = true; | |
100 } | |
101 } | |
102 | |
103 t.Commit(); | |
104 | |
105 return ok; | |
106 } | |
107 | |
108 | |
109 unsigned int PendingDeletionsDatabase::GetSize() | |
110 { | |
111 boost::mutex::scoped_lock lock(mutex_); | |
112 | |
113 unsigned int value = 0; | |
114 | |
115 Orthanc::SQLite::Transaction t(db_); | |
116 t.Begin(); | |
117 | |
118 { | |
119 Orthanc::SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT COUNT(*) FROM Pending"); | |
120 | |
121 if (s.Step()) | |
122 { | |
123 int tmp = s.ColumnInt(0); | |
124 if (tmp > 0) | |
125 { | |
126 value = static_cast<unsigned int>(tmp); | |
127 } | |
128 } | |
129 } | |
130 | |
131 t.Commit(); | |
132 | |
133 return value; | |
134 } |