Mercurial > hg > orthanc-databases
comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 225:94c9908e6aca
removed DatabaseManager member out of class IndexBackend
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 01 Apr 2021 19:18:19 +0200 |
parents | 73cc85f3d9c1 |
children | a4918d57435c |
comparison
equal
deleted
inserted
replaced
224:61c309e06797 | 225:94c9908e6aca |
---|---|
257 } | 257 } |
258 | 258 |
259 | 259 |
260 PostgreSQLIndex::PostgreSQLIndex(OrthancPluginContext* context, | 260 PostgreSQLIndex::PostgreSQLIndex(OrthancPluginContext* context, |
261 const PostgreSQLParameters& parameters) : | 261 const PostgreSQLParameters& parameters) : |
262 IndexBackend(context, new Factory(*this)), | 262 IndexBackend(context), |
263 parameters_(parameters), | 263 parameters_(parameters), |
264 clearAll_(false) | 264 clearAll_(false) |
265 { | 265 { |
266 } | 266 } |
267 | 267 |
268 | 268 |
269 int64_t PostgreSQLIndex::CreateResource(const char* publicId, | 269 int64_t PostgreSQLIndex::CreateResource(DatabaseManager& manager, |
270 const char* publicId, | |
270 OrthancPluginResourceType type) | 271 OrthancPluginResourceType type) |
271 { | 272 { |
272 DatabaseManager::CachedStatement statement( | 273 DatabaseManager::CachedStatement statement( |
273 STATEMENT_FROM_HERE, GetManager(), | 274 STATEMENT_FROM_HERE, manager, |
274 "INSERT INTO Resources VALUES(${}, ${type}, ${id}, NULL) RETURNING internalId"); | 275 "INSERT INTO Resources VALUES(${}, ${type}, ${id}, NULL) RETURNING internalId"); |
275 | 276 |
276 statement.SetParameterType("id", ValueType_Utf8String); | 277 statement.SetParameterType("id", ValueType_Utf8String); |
277 statement.SetParameterType("type", ValueType_Integer64); | 278 statement.SetParameterType("type", ValueType_Integer64); |
278 | 279 |
284 | 285 |
285 return ReadInteger64(statement, 0); | 286 return ReadInteger64(statement, 0); |
286 } | 287 } |
287 | 288 |
288 | 289 |
289 uint64_t PostgreSQLIndex::GetTotalCompressedSize() | 290 uint64_t PostgreSQLIndex::GetTotalCompressedSize(DatabaseManager& manager) |
290 { | 291 { |
291 // Fast version if extension "./FastTotalSize.sql" is installed | 292 // Fast version if extension "./FastTotalSize.sql" is installed |
292 uint64_t result; | 293 uint64_t result; |
293 | 294 |
294 { | 295 { |
295 DatabaseManager::CachedStatement statement( | 296 DatabaseManager::CachedStatement statement( |
296 STATEMENT_FROM_HERE, GetManager(), | 297 STATEMENT_FROM_HERE, manager, |
297 "SELECT value FROM GlobalIntegers WHERE key = 0"); | 298 "SELECT value FROM GlobalIntegers WHERE key = 0"); |
298 | 299 |
299 statement.SetReadOnly(true); | 300 statement.SetReadOnly(true); |
300 statement.Execute(); | 301 statement.Execute(); |
301 | 302 |
302 result = static_cast<uint64_t>(ReadInteger64(statement, 0)); | 303 result = static_cast<uint64_t>(ReadInteger64(statement, 0)); |
303 } | 304 } |
304 | 305 |
305 assert(result == IndexBackend::GetTotalCompressedSize()); | 306 assert(result == IndexBackend::GetTotalCompressedSize(manager)); |
306 return result; | 307 return result; |
307 } | 308 } |
308 | 309 |
309 | 310 |
310 uint64_t PostgreSQLIndex::GetTotalUncompressedSize() | 311 uint64_t PostgreSQLIndex::GetTotalUncompressedSize(DatabaseManager& manager) |
311 { | 312 { |
312 // Fast version if extension "./FastTotalSize.sql" is installed | 313 // Fast version if extension "./FastTotalSize.sql" is installed |
313 uint64_t result; | 314 uint64_t result; |
314 | 315 |
315 { | 316 { |
316 DatabaseManager::CachedStatement statement( | 317 DatabaseManager::CachedStatement statement( |
317 STATEMENT_FROM_HERE, GetManager(), | 318 STATEMENT_FROM_HERE, manager, |
318 "SELECT value FROM GlobalIntegers WHERE key = 1"); | 319 "SELECT value FROM GlobalIntegers WHERE key = 1"); |
319 | 320 |
320 statement.SetReadOnly(true); | 321 statement.SetReadOnly(true); |
321 statement.Execute(); | 322 statement.Execute(); |
322 | 323 |
323 result = static_cast<uint64_t>(ReadInteger64(statement, 0)); | 324 result = static_cast<uint64_t>(ReadInteger64(statement, 0)); |
324 } | 325 } |
325 | 326 |
326 assert(result == IndexBackend::GetTotalUncompressedSize()); | 327 assert(result == IndexBackend::GetTotalUncompressedSize(manager)); |
327 return result; | 328 return result; |
328 } | 329 } |
329 | 330 |
330 | 331 |
331 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | 332 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
332 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, | 333 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, |
334 DatabaseManager& manager, | |
333 const char* hashPatient, | 335 const char* hashPatient, |
334 const char* hashStudy, | 336 const char* hashStudy, |
335 const char* hashSeries, | 337 const char* hashSeries, |
336 const char* hashInstance) | 338 const char* hashInstance) |
337 { | 339 { |
338 DatabaseManager::CachedStatement statement( | 340 DatabaseManager::CachedStatement statement( |
339 STATEMENT_FROM_HERE, GetManager(), | 341 STATEMENT_FROM_HERE, manager, |
340 "SELECT * FROM CreateInstance(${patient}, ${study}, ${series}, ${instance})"); | 342 "SELECT * FROM CreateInstance(${patient}, ${study}, ${series}, ${instance})"); |
341 | 343 |
342 statement.SetParameterType("patient", ValueType_Utf8String); | 344 statement.SetParameterType("patient", ValueType_Utf8String); |
343 statement.SetParameterType("study", ValueType_Utf8String); | 345 statement.SetParameterType("study", ValueType_Utf8String); |
344 statement.SetParameterType("series", ValueType_Utf8String); | 346 statement.SetParameterType("series", ValueType_Utf8String); |
377 } | 379 } |
378 } | 380 } |
379 #endif | 381 #endif |
380 | 382 |
381 | 383 |
382 uint64_t PostgreSQLIndex::GetResourcesCount(OrthancPluginResourceType resourceType) | 384 uint64_t PostgreSQLIndex::GetResourcesCount(DatabaseManager& manager, |
385 OrthancPluginResourceType resourceType) | |
383 { | 386 { |
384 // Optimized version thanks to the "FastCountResources.sql" extension | 387 // Optimized version thanks to the "FastCountResources.sql" extension |
385 | 388 |
386 assert(OrthancPluginResourceType_Patient == 0 && | 389 assert(OrthancPluginResourceType_Patient == 0 && |
387 OrthancPluginResourceType_Study == 1 && | 390 OrthancPluginResourceType_Study == 1 && |
390 | 393 |
391 uint64_t result; | 394 uint64_t result; |
392 | 395 |
393 { | 396 { |
394 DatabaseManager::CachedStatement statement( | 397 DatabaseManager::CachedStatement statement( |
395 STATEMENT_FROM_HERE, GetManager(), | 398 STATEMENT_FROM_HERE, manager, |
396 "SELECT value FROM GlobalIntegers WHERE key = ${key}"); | 399 "SELECT value FROM GlobalIntegers WHERE key = ${key}"); |
397 | 400 |
398 statement.SetParameterType("key", ValueType_Integer64); | 401 statement.SetParameterType("key", ValueType_Integer64); |
399 | 402 |
400 Dictionary args; | 403 Dictionary args; |
406 statement.Execute(args); | 409 statement.Execute(args); |
407 | 410 |
408 result = static_cast<uint64_t>(ReadInteger64(statement, 0)); | 411 result = static_cast<uint64_t>(ReadInteger64(statement, 0)); |
409 } | 412 } |
410 | 413 |
411 assert(result == IndexBackend::GetResourcesCount(resourceType)); | 414 assert(result == IndexBackend::GetResourcesCount(manager, resourceType)); |
412 return result; | 415 return result; |
413 } | 416 } |
414 | 417 |
415 | 418 |
416 int64_t PostgreSQLIndex::GetLastChangeIndex() | 419 int64_t PostgreSQLIndex::GetLastChangeIndex(DatabaseManager& manager) |
417 { | 420 { |
418 DatabaseManager::CachedStatement statement( | 421 DatabaseManager::CachedStatement statement( |
419 STATEMENT_FROM_HERE, GetManager(), | 422 STATEMENT_FROM_HERE, manager, |
420 "SELECT value FROM GlobalIntegers WHERE key = 6"); | 423 "SELECT value FROM GlobalIntegers WHERE key = 6"); |
421 | 424 |
422 statement.SetReadOnly(true); | 425 statement.SetReadOnly(true); |
423 statement.Execute(); | 426 statement.Execute(); |
424 | 427 |
425 return ReadInteger64(statement, 0); | 428 return ReadInteger64(statement, 0); |
426 } | 429 } |
427 | 430 |
428 | 431 |
429 void PostgreSQLIndex::TagMostRecentPatient(int64_t patient) | 432 void PostgreSQLIndex::TagMostRecentPatient(DatabaseManager& manager, |
433 int64_t patient) | |
430 { | 434 { |
431 // This behavior is implemented in "CreateInstance()", and no | 435 // This behavior is implemented in "CreateInstance()", and no |
432 // backward compatibility is necessary | 436 // backward compatibility is necessary |
433 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | 437 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
434 } | 438 } |