comparison OrthancServer/Sources/Database/IDatabaseWrapper.h @ 4591:ff8170d17d90 db-changes

moving all accesses to databases from IDatabaseWrapper to ITransaction
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 15 Mar 2021 15:30:42 +0100
parents bec74e29f86b
children cc64385593ef
comparison
equal deleted inserted replaced
4590:4a0bf1019335 4591:ff8170d17d90
53 53
54 54
55 class IDatabaseWrapper : public boost::noncopyable 55 class IDatabaseWrapper : public boost::noncopyable
56 { 56 {
57 public: 57 public:
58 class ITransaction : public boost::noncopyable
59 {
60 public:
61 virtual ~ITransaction()
62 {
63 }
64
65 virtual void Rollback() = 0;
66
67 // The "fileSizeDelta" is used for older database plugins that
68 // have no fast way to compute the size of all the stored
69 // attachments (cf. "fastGetTotalSize_")
70 virtual void Commit(int64_t fileSizeDelta) = 0;
71 };
72
73
74 struct CreateInstanceResult 58 struct CreateInstanceResult
75 { 59 {
76 bool isNewPatient_; 60 bool isNewPatient_;
77 bool isNewStudy_; 61 bool isNewStudy_;
78 bool isNewSeries_; 62 bool isNewSeries_;
79 int64_t patientId_; 63 int64_t patientId_;
80 int64_t studyId_; 64 int64_t studyId_;
81 int64_t seriesId_; 65 int64_t seriesId_;
82 }; 66 };
83 67
68
69 class ITransaction : public boost::noncopyable
70 {
71 public:
72 virtual ~ITransaction()
73 {
74 }
75
76 virtual void Rollback() = 0;
77
78 // The "fileSizeDelta" is used for older database plugins that
79 // have no fast way to compute the size of all the stored
80 // attachments (cf. "fastGetTotalSize_")
81 virtual void Commit(int64_t fileSizeDelta) = 0;
82
83 virtual void AddAttachment(int64_t id,
84 const FileInfo& attachment) = 0;
85
86 virtual void ClearChanges() = 0;
87
88 virtual void ClearExportedResources() = 0;
89
90 virtual void DeleteAttachment(int64_t id,
91 FileContentType attachment) = 0;
92
93 virtual void DeleteMetadata(int64_t id,
94 MetadataType type) = 0;
95
96 virtual void DeleteResource(int64_t id) = 0;
97
98 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
99 int64_t id) = 0;
100
101 virtual void GetAllPublicIds(std::list<std::string>& target,
102 ResourceType resourceType) = 0;
103
104 virtual void GetAllPublicIds(std::list<std::string>& target,
105 ResourceType resourceType,
106 size_t since,
107 size_t limit) = 0;
108
109 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/,
110 bool& done /*out*/,
111 int64_t since,
112 uint32_t maxResults) = 0;
113
114 virtual void GetChildrenInternalId(std::list<int64_t>& target,
115 int64_t id) = 0;
116
117 virtual void GetChildrenPublicId(std::list<std::string>& target,
118 int64_t id) = 0;
119
120 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/,
121 bool& done /*out*/,
122 int64_t since,
123 uint32_t maxResults) = 0;
124
125 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) = 0;
126
127 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) = 0;
128
129 virtual void GetMainDicomTags(DicomMap& map,
130 int64_t id) = 0;
131
132 virtual std::string GetPublicId(int64_t resourceId) = 0;
133
134 virtual uint64_t GetResourceCount(ResourceType resourceType) = 0;
135
136 virtual ResourceType GetResourceType(int64_t resourceId) = 0;
137
138 virtual uint64_t GetTotalCompressedSize() = 0;
139
140 virtual uint64_t GetTotalUncompressedSize() = 0;
141
142 virtual bool IsExistingResource(int64_t internalId) = 0;
143
144 virtual bool IsProtectedPatient(int64_t internalId) = 0;
145
146 virtual void ListAvailableAttachments(std::set<FileContentType>& target,
147 int64_t id) = 0;
148
149 virtual void LogChange(int64_t internalId,
150 const ServerIndexChange& change) = 0;
151
152 virtual void LogExportedResource(const ExportedResource& resource) = 0;
153
154 virtual bool LookupAttachment(FileInfo& attachment,
155 int64_t id,
156 FileContentType contentType) = 0;
157
158 virtual bool LookupGlobalProperty(std::string& target,
159 GlobalProperty property) = 0;
160
161 virtual bool LookupMetadata(std::string& target,
162 int64_t id,
163 MetadataType type) = 0;
164
165 virtual bool LookupParent(int64_t& parentId,
166 int64_t resourceId) = 0;
167
168 virtual bool LookupResource(int64_t& id,
169 ResourceType& type,
170 const std::string& publicId) = 0;
171
172 virtual bool SelectPatientToRecycle(int64_t& internalId) = 0;
173
174 virtual bool SelectPatientToRecycle(int64_t& internalId,
175 int64_t patientIdToAvoid) = 0;
176
177 virtual void SetGlobalProperty(GlobalProperty property,
178 const std::string& value) = 0;
179
180 virtual void ClearMainDicomTags(int64_t id) = 0;
181
182 virtual void SetMetadata(int64_t id,
183 MetadataType type,
184 const std::string& value) = 0;
185
186 virtual void SetProtectedPatient(int64_t internalId,
187 bool isProtected) = 0;
188
189
190 /**
191 * Primitives introduced in Orthanc 1.5.2
192 **/
193
194 virtual bool IsDiskSizeAbove(uint64_t threshold) = 0;
195
196 virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
197 std::list<std::string>* instancesId, // Can be NULL if not needed
198 const std::vector<DatabaseConstraint>& lookup,
199 ResourceType queryLevel,
200 size_t limit) = 0;
201
202 // Returns "true" iff. the instance is new and has been inserted
203 // into the database. If "false" is returned, the content of
204 // "result" is undefined, but "instanceId" must be properly
205 // set. This method must also tag the parent patient as the most
206 // recent in the patient recycling order if it is not protected
207 // (so as to fix issue #58).
208 virtual bool CreateInstance(CreateInstanceResult& result, /* out */
209 int64_t& instanceId, /* out */
210 const std::string& patient,
211 const std::string& study,
212 const std::string& series,
213 const std::string& instance) = 0;
214
215 // It is guaranteed that the resources to be modified have no main
216 // DICOM tags, and no DICOM identifiers associated with
217 // them. However, some metadata might be already existing, and
218 // have to be overwritten.
219 virtual void SetResourcesContent(const ResourcesContent& content) = 0;
220
221 virtual void GetChildrenMetadata(std::list<std::string>& target,
222 int64_t resourceId,
223 MetadataType metadata) = 0;
224
225 virtual int64_t GetLastChangeIndex() = 0;
226
227
228 /**
229 * Primitives introduced in Orthanc 1.5.4
230 **/
231
232 virtual bool LookupResourceAndParent(int64_t& id,
233 ResourceType& type,
234 std::string& parentPublicId,
235 const std::string& publicId) = 0;
236 };
237
238
84 virtual ~IDatabaseWrapper() 239 virtual ~IDatabaseWrapper()
85 { 240 {
86 } 241 }
87 242
88 virtual void Open() = 0; 243 virtual void Open() = 0;
89 244
90 virtual void Close() = 0; 245 virtual void Close() = 0;
91 246
92 virtual void AddAttachment(int64_t id,
93 const FileInfo& attachment) = 0;
94
95 virtual void ClearChanges() = 0;
96
97 virtual void ClearExportedResources() = 0;
98
99 virtual void DeleteAttachment(int64_t id,
100 FileContentType attachment) = 0;
101
102 virtual void DeleteMetadata(int64_t id,
103 MetadataType type) = 0;
104
105 virtual void DeleteResource(int64_t id) = 0;
106
107 virtual void FlushToDisk() = 0; 247 virtual void FlushToDisk() = 0;
108 248
109 virtual bool HasFlushToDisk() const = 0; 249 virtual bool HasFlushToDisk() const = 0;
110
111 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
112 int64_t id) = 0;
113
114 virtual void GetAllPublicIds(std::list<std::string>& target,
115 ResourceType resourceType) = 0;
116
117 virtual void GetAllPublicIds(std::list<std::string>& target,
118 ResourceType resourceType,
119 size_t since,
120 size_t limit) = 0;
121
122 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/,
123 bool& done /*out*/,
124 int64_t since,
125 uint32_t maxResults) = 0;
126
127 virtual void GetChildrenInternalId(std::list<int64_t>& target,
128 int64_t id) = 0;
129
130 virtual void GetChildrenPublicId(std::list<std::string>& target,
131 int64_t id) = 0;
132
133 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/,
134 bool& done /*out*/,
135 int64_t since,
136 uint32_t maxResults) = 0;
137
138 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) = 0;
139
140 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) = 0;
141
142 virtual void GetMainDicomTags(DicomMap& map,
143 int64_t id) = 0;
144
145 virtual std::string GetPublicId(int64_t resourceId) = 0;
146
147 virtual uint64_t GetResourceCount(ResourceType resourceType) = 0;
148
149 virtual ResourceType GetResourceType(int64_t resourceId) = 0;
150
151 virtual uint64_t GetTotalCompressedSize() = 0;
152
153 virtual uint64_t GetTotalUncompressedSize() = 0;
154
155 virtual bool IsExistingResource(int64_t internalId) = 0;
156
157 virtual bool IsProtectedPatient(int64_t internalId) = 0;
158
159 virtual void ListAvailableAttachments(std::set<FileContentType>& target,
160 int64_t id) = 0;
161
162 virtual void LogChange(int64_t internalId,
163 const ServerIndexChange& change) = 0;
164
165 virtual void LogExportedResource(const ExportedResource& resource) = 0;
166
167 virtual bool LookupAttachment(FileInfo& attachment,
168 int64_t id,
169 FileContentType contentType) = 0;
170
171 virtual bool LookupGlobalProperty(std::string& target,
172 GlobalProperty property) = 0;
173
174 virtual bool LookupMetadata(std::string& target,
175 int64_t id,
176 MetadataType type) = 0;
177
178 virtual bool LookupParent(int64_t& parentId,
179 int64_t resourceId) = 0;
180
181 virtual bool LookupResource(int64_t& id,
182 ResourceType& type,
183 const std::string& publicId) = 0;
184
185 virtual bool SelectPatientToRecycle(int64_t& internalId) = 0;
186
187 virtual bool SelectPatientToRecycle(int64_t& internalId,
188 int64_t patientIdToAvoid) = 0;
189
190 virtual void SetGlobalProperty(GlobalProperty property,
191 const std::string& value) = 0;
192
193 virtual void ClearMainDicomTags(int64_t id) = 0;
194
195 virtual void SetMetadata(int64_t id,
196 MetadataType type,
197 const std::string& value) = 0;
198
199 virtual void SetProtectedPatient(int64_t internalId,
200 bool isProtected) = 0;
201 250
202 virtual ITransaction* StartTransaction(TransactionType type, 251 virtual ITransaction* StartTransaction(TransactionType type,
203 IDatabaseListener& listener) = 0; 252 IDatabaseListener& listener) = 0;
204 253
205 virtual unsigned int GetDatabaseVersion() = 0; 254 virtual unsigned int GetDatabaseVersion() = 0;
206 255
207 virtual void Upgrade(unsigned int targetVersion, 256 virtual void Upgrade(unsigned int targetVersion,
208 IStorageArea& storageArea) = 0; 257 IStorageArea& storageArea) = 0;
209
210
211 /**
212 * Primitives introduced in Orthanc 1.5.2
213 **/
214
215 virtual bool IsDiskSizeAbove(uint64_t threshold) = 0;
216
217 virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
218 std::list<std::string>* instancesId, // Can be NULL if not needed
219 const std::vector<DatabaseConstraint>& lookup,
220 ResourceType queryLevel,
221 size_t limit) = 0;
222
223 // Returns "true" iff. the instance is new and has been inserted
224 // into the database. If "false" is returned, the content of
225 // "result" is undefined, but "instanceId" must be properly
226 // set. This method must also tag the parent patient as the most
227 // recent in the patient recycling order if it is not protected
228 // (so as to fix issue #58).
229 virtual bool CreateInstance(CreateInstanceResult& result, /* out */
230 int64_t& instanceId, /* out */
231 const std::string& patient,
232 const std::string& study,
233 const std::string& series,
234 const std::string& instance) = 0;
235
236 // It is guaranteed that the resources to be modified have no main
237 // DICOM tags, and no DICOM identifiers associated with
238 // them. However, some metadata might be already existing, and
239 // have to be overwritten.
240 virtual void SetResourcesContent(const ResourcesContent& content) = 0;
241
242 virtual void GetChildrenMetadata(std::list<std::string>& target,
243 int64_t resourceId,
244 MetadataType metadata) = 0;
245
246 virtual int64_t GetLastChangeIndex() = 0;
247
248
249 /**
250 * Primitives introduced in Orthanc 1.5.4
251 **/
252
253 virtual bool LookupResourceAndParent(int64_t& id,
254 ResourceType& type,
255 std::string& parentPublicId,
256 const std::string& publicId) = 0;
257 }; 258 };
258 } 259 }