annotate Framework/Plugins/IndexConnectionsPool.cpp @ 404:3cd39c8cade9 db-protobuf

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Apr 2023 20:52:09 +0200
parents 91124cc8a8c7
children de6de66d70b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
374
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
389
3d6886f3e5b3 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 374
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
3d6886f3e5b3 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 374
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
374
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU Affero General Public License
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * Affero General Public License for more details.
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU Affero General Public License
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "IndexConnectionsPool.h"
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 namespace OrthancDatabases
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 class IndexConnectionsPool::ManagerReference : public Orthanc::IDynamicObject
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 private:
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 DatabaseManager* manager_;
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 public:
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 ManagerReference(DatabaseManager& manager) :
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 manager_(&manager)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 DatabaseManager& GetManager()
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 assert(manager_ != NULL);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 return *manager_;
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 };
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 IndexConnectionsPool::IndexConnectionsPool(IndexBackend* backend,
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 size_t countConnections) :
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 backend_(backend),
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 countConnections_(countConnections)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 if (countConnections == 0)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 "There must be a non-zero number of connections to the database");
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 else if (backend == NULL)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 else
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 context_ = backend_->GetContext();
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 IndexConnectionsPool::~IndexConnectionsPool()
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 for (std::list<DatabaseManager*>::iterator
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 it = connections_.begin(); it != connections_.end(); ++it)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 assert(*it != NULL);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 delete *it;
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
403
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
78 void IndexConnectionsPool::OpenConnections(bool hasIdentifierTags,
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
79 const std::list<IdentifierTag>& identifierTags)
374
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 boost::unique_lock<boost::shared_mutex> lock(connectionsMutex_);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 if (connections_.size() == 0)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 assert(backend_.get() != NULL);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 std::unique_ptr<DatabaseManager> manager(new DatabaseManager(backend_->CreateDatabaseFactory()));
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 manager->GetDatabase(); // Make sure to open the database connection
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
403
91124cc8a8c7 database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 389
diff changeset
91 backend_->ConfigureDatabase(*manager, hasIdentifierTags, identifierTags);
374
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 connections_.push_back(manager.release());
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 for (size_t i = 1; i < countConnections_; i++)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 connections_.push_back(new DatabaseManager(backend_->CreateDatabaseFactory()));
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 connections_.back()->GetDatabase(); // Make sure to open the database connection
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 for (std::list<DatabaseManager*>::iterator
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 it = connections_.begin(); it != connections_.end(); ++it)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 assert(*it != NULL);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 availableConnections_.Enqueue(new ManagerReference(**it));
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 else
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 void IndexConnectionsPool::CloseConnections()
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 boost::unique_lock<boost::shared_mutex> lock(connectionsMutex_);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 if (connections_.size() != countConnections_)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 else if (availableConnections_.GetSize() != countConnections_)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Some connections are still in use, bug in the Orthanc core");
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 else
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 for (std::list<DatabaseManager*>::iterator
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 it = connections_.begin(); it != connections_.end(); ++it)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 assert(*it != NULL);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 (*it)->Close();
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 IndexConnectionsPool::Accessor::Accessor(IndexConnectionsPool& pool) :
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 lock_(pool.connectionsMutex_),
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 pool_(pool),
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 manager_(NULL)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 for (;;)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 std::unique_ptr<Orthanc::IDynamicObject> manager(pool.availableConnections_.Dequeue(100));
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 if (manager.get() != NULL)
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 manager_ = &dynamic_cast<ManagerReference&>(*manager).GetManager();
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 return;
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 IndexConnectionsPool::Accessor::~Accessor()
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 assert(manager_ != NULL);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 pool_.availableConnections_.Enqueue(new ManagerReference(*manager_));
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 IndexBackend& IndexConnectionsPool::Accessor::GetBackend() const
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 return *pool_.backend_;
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 DatabaseManager& IndexConnectionsPool::Accessor::GetManager() const
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 assert(manager_ != NULL);
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 return *manager_;
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
4a3985088723 moved class IndexConnectionsPool out of DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }