Mercurial > hg > orthanc
comparison OrthancServer/DatabaseWrapper.h @ 1247:32fcc5dc7562
abstraction
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Dec 2014 13:54:27 +0100 |
parents | 54bf0f0245f4 |
children | ee43f0d611a8 |
comparison
equal
deleted
inserted
replaced
1246:54bf0f0245f4 | 1247:32fcc5dc7562 |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #pragma once | 33 #pragma once |
34 | 34 |
35 #include "IDatabaseWrapper.h" | |
36 | |
35 #include "../Core/SQLite/Connection.h" | 37 #include "../Core/SQLite/Connection.h" |
36 #include "../Core/SQLite/Transaction.h" | 38 #include "../Core/SQLite/Transaction.h" |
37 #include "../Core/DicomFormat/DicomInstanceHasher.h" | |
38 #include "../Core/FileStorage/FileInfo.h" | |
39 #include "IServerIndexListener.h" | |
40 | |
41 #include <list> | |
42 #include <boost/date_time/posix_time/posix_time.hpp> | |
43 | |
44 #include "ExportedResource.h" | |
45 | 39 |
46 namespace Orthanc | 40 namespace Orthanc |
47 { | 41 { |
48 namespace Internals | 42 namespace Internals |
49 { | 43 { |
53 /** | 47 /** |
54 * This class manages an instance of the Orthanc SQLite database. It | 48 * This class manages an instance of the Orthanc SQLite database. It |
55 * translates low-level requests into SQL statements. Mutual | 49 * translates low-level requests into SQL statements. Mutual |
56 * exclusion MUST be implemented at a higher level. | 50 * exclusion MUST be implemented at a higher level. |
57 **/ | 51 **/ |
58 class DatabaseWrapper | 52 class DatabaseWrapper : public IDatabaseWrapper |
59 { | 53 { |
60 private: | 54 private: |
61 IServerIndexListener& listener_; | 55 IServerIndexListener* listener_; |
62 SQLite::Connection db_; | 56 SQLite::Connection db_; |
63 Internals::SignalRemainingAncestor* signalRemainingAncestor_; | 57 Internals::SignalRemainingAncestor* signalRemainingAncestor_; |
64 | 58 |
65 void Open(); | 59 void Open(); |
66 | 60 |
73 bool& done, | 67 bool& done, |
74 SQLite::Statement& s, | 68 SQLite::Statement& s, |
75 unsigned int maxResults); | 69 unsigned int maxResults); |
76 | 70 |
77 public: | 71 public: |
78 void SetGlobalProperty(GlobalProperty property, | 72 DatabaseWrapper(const std::string& path); |
79 const std::string& value); | 73 |
80 | 74 DatabaseWrapper(); |
81 bool LookupGlobalProperty(std::string& target, | 75 |
82 GlobalProperty property); | 76 virtual void SetListener(IServerIndexListener& listener); |
83 | 77 |
84 int64_t CreateResource(const std::string& publicId, | 78 virtual void SetGlobalProperty(GlobalProperty property, |
85 ResourceType type); | 79 const std::string& value); |
86 | 80 |
87 bool LookupResource(const std::string& publicId, | 81 virtual bool LookupGlobalProperty(std::string& target, |
88 int64_t& id, | 82 GlobalProperty property); |
89 ResourceType& type); | 83 |
90 | 84 virtual int64_t CreateResource(const std::string& publicId, |
91 bool LookupParent(int64_t& parentId, | 85 ResourceType type); |
92 int64_t resourceId); | 86 |
93 | 87 virtual bool LookupResource(const std::string& publicId, |
94 std::string GetPublicId(int64_t resourceId); | 88 int64_t& id, |
95 | 89 ResourceType& type); |
96 ResourceType GetResourceType(int64_t resourceId); | 90 |
97 | 91 virtual bool LookupParent(int64_t& parentId, |
98 void AttachChild(int64_t parent, | 92 int64_t resourceId); |
99 int64_t child); | 93 |
100 | 94 virtual std::string GetPublicId(int64_t resourceId); |
101 void DeleteResource(int64_t id); | 95 |
102 | 96 virtual ResourceType GetResourceType(int64_t resourceId); |
103 void SetMetadata(int64_t id, | 97 |
104 MetadataType type, | 98 virtual void AttachChild(int64_t parent, |
105 const std::string& value); | 99 int64_t child); |
106 | 100 |
107 void DeleteMetadata(int64_t id, | 101 virtual void DeleteResource(int64_t id); |
108 MetadataType type); | 102 |
109 | 103 virtual void SetMetadata(int64_t id, |
110 bool LookupMetadata(std::string& target, | 104 MetadataType type, |
111 int64_t id, | 105 const std::string& value); |
112 MetadataType type); | 106 |
113 | 107 virtual void DeleteMetadata(int64_t id, |
114 void ListAvailableMetadata(std::list<MetadataType>& target, | 108 MetadataType type); |
115 int64_t id); | 109 |
116 | 110 virtual bool LookupMetadata(std::string& target, |
117 void AddAttachment(int64_t id, | 111 int64_t id, |
118 const FileInfo& attachment); | 112 MetadataType type); |
119 | 113 |
120 void DeleteAttachment(int64_t id, | 114 virtual void ListAvailableMetadata(std::list<MetadataType>& target, |
121 FileContentType attachment); | 115 int64_t id); |
122 | 116 |
123 void ListAvailableAttachments(std::list<FileContentType>& result, | 117 virtual void AddAttachment(int64_t id, |
118 const FileInfo& attachment); | |
119 | |
120 virtual void DeleteAttachment(int64_t id, | |
121 FileContentType attachment); | |
122 | |
123 virtual void ListAvailableAttachments(std::list<FileContentType>& result, | |
124 int64_t id); | |
125 | |
126 virtual bool LookupAttachment(FileInfo& attachment, | |
127 int64_t id, | |
128 FileContentType contentType); | |
129 | |
130 virtual void SetMainDicomTags(int64_t id, | |
131 const DicomMap& tags); | |
132 | |
133 virtual void GetMainDicomTags(DicomMap& map, | |
124 int64_t id); | 134 int64_t id); |
125 | 135 |
126 bool LookupAttachment(FileInfo& attachment, | 136 virtual void GetChildrenPublicId(std::list<std::string>& result, |
127 int64_t id, | 137 int64_t id); |
128 FileContentType contentType); | 138 |
129 | 139 virtual void GetChildrenInternalId(std::list<int64_t>& result, |
130 void SetMainDicomTags(int64_t id, | 140 int64_t id); |
131 const DicomMap& tags); | 141 |
132 | 142 virtual void LogChange(int64_t internalId, |
133 void GetMainDicomTags(DicomMap& map, | 143 const ServerIndexChange& change); |
134 int64_t id); | 144 |
135 | 145 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, |
136 void GetChildrenPublicId(std::list<std::string>& result, | 146 bool& done /*out*/, |
137 int64_t id); | 147 int64_t since, |
138 | 148 unsigned int maxResults); |
139 void GetChildrenInternalId(std::list<int64_t>& result, | 149 |
140 int64_t id); | 150 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/); |
141 | 151 |
142 void LogChange(int64_t internalId, | 152 virtual void LogExportedResource(const ExportedResource& resource); |
143 const ServerIndexChange& change); | |
144 | |
145 void GetChanges(std::list<ServerIndexChange>& target /*out*/, | |
146 bool& done /*out*/, | |
147 int64_t since, | |
148 unsigned int maxResults); | |
149 | |
150 void GetLastChange(std::list<ServerIndexChange>& target /*out*/); | |
151 | |
152 void LogExportedResource(const ExportedResource& resource); | |
153 | 153 |
154 void GetExportedResources(std::list<ExportedResource>& target /*out*/, | 154 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, |
155 bool& done /*out*/, | 155 bool& done /*out*/, |
156 int64_t since, | 156 int64_t since, |
157 unsigned int maxResults); | 157 unsigned int maxResults); |
158 | 158 |
159 void GetLastExportedResource(std::list<ExportedResource>& target /*out*/); | 159 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/); |
160 | 160 |
161 uint64_t GetTotalCompressedSize(); | 161 virtual uint64_t GetTotalCompressedSize(); |
162 | 162 |
163 uint64_t GetTotalUncompressedSize(); | 163 virtual uint64_t GetTotalUncompressedSize(); |
164 | 164 |
165 uint64_t GetResourceCount(ResourceType resourceType); | 165 virtual uint64_t GetResourceCount(ResourceType resourceType); |
166 | 166 |
167 void GetAllPublicIds(std::list<std::string>& target, | 167 virtual void GetAllPublicIds(std::list<std::string>& target, |
168 ResourceType resourceType); | 168 ResourceType resourceType); |
169 | 169 |
170 bool SelectPatientToRecycle(int64_t& internalId); | 170 virtual bool SelectPatientToRecycle(int64_t& internalId); |
171 | 171 |
172 bool SelectPatientToRecycle(int64_t& internalId, | 172 virtual bool SelectPatientToRecycle(int64_t& internalId, |
173 int64_t patientIdToAvoid); | 173 int64_t patientIdToAvoid); |
174 | 174 |
175 bool IsProtectedPatient(int64_t internalId); | 175 virtual bool IsProtectedPatient(int64_t internalId); |
176 | 176 |
177 void SetProtectedPatient(int64_t internalId, | 177 virtual void SetProtectedPatient(int64_t internalId, |
178 bool isProtected); | 178 bool isProtected); |
179 | 179 |
180 DatabaseWrapper(const std::string& path, | 180 virtual SQLite::ITransaction* StartTransaction() |
181 IServerIndexListener& listener); | |
182 | |
183 DatabaseWrapper(IServerIndexListener& listener); | |
184 | |
185 SQLite::ITransaction* StartTransaction() | |
186 { | 181 { |
187 return new SQLite::Transaction(db_); | 182 return new SQLite::Transaction(db_); |
188 } | 183 } |
184 | |
185 virtual void FlushToDisk() | |
186 { | |
187 db_.FlushToDisk(); | |
188 } | |
189 | |
190 virtual void ClearTable(const std::string& tableName); | |
191 | |
192 virtual bool IsExistingResource(int64_t internalId); | |
193 | |
194 virtual void LookupIdentifier(std::list<int64_t>& result, | |
195 const DicomTag& tag, | |
196 const std::string& value); | |
197 | |
198 virtual void LookupIdentifier(std::list<int64_t>& result, | |
199 const std::string& value); | |
200 | |
201 virtual void GetAllMetadata(std::map<MetadataType, std::string>& result, | |
202 int64_t id); | |
203 | |
204 | |
205 | |
206 | |
207 /** | |
208 * The methods declared below are for unit testing only! | |
209 **/ | |
189 | 210 |
190 const char* GetErrorMessage() const | 211 const char* GetErrorMessage() const |
191 { | 212 { |
192 return db_.GetErrorMessage(); | 213 return db_.GetErrorMessage(); |
193 } | 214 } |
194 | 215 |
195 void FlushToDisk() | |
196 { | |
197 db_.FlushToDisk(); | |
198 } | |
199 | |
200 void ClearTable(const std::string& tableName); | |
201 | |
202 bool IsExistingResource(int64_t internalId); | |
203 | |
204 void LookupIdentifier(std::list<int64_t>& result, | |
205 const DicomTag& tag, | |
206 const std::string& value); | |
207 | |
208 void LookupIdentifier(std::list<int64_t>& result, | |
209 const std::string& value); | |
210 | |
211 void GetAllMetadata(std::map<MetadataType, std::string>& result, | |
212 int64_t id); | |
213 | |
214 | |
215 | |
216 | |
217 /** | |
218 * The methods declared below are for unit testing only! | |
219 **/ | |
220 | |
221 void GetChildren(std::list<std::string>& childrenPublicIds, | 216 void GetChildren(std::list<std::string>& childrenPublicIds, |
222 int64_t id); | 217 int64_t id); |
223 | 218 |
224 int64_t GetTableRecordCount(const std::string& table); | 219 int64_t GetTableRecordCount(const std::string& table); |
225 | 220 |