Mercurial > hg > orthanc-databases
comparison MySQL/Plugins/MySQLIndex.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 |
---|---|
267 } | 267 } |
268 | 268 |
269 | 269 |
270 MySQLIndex::MySQLIndex(OrthancPluginContext* context, | 270 MySQLIndex::MySQLIndex(OrthancPluginContext* context, |
271 const MySQLParameters& parameters) : | 271 const MySQLParameters& parameters) : |
272 IndexBackend(context, new Factory(*this)), | 272 IndexBackend(context), |
273 parameters_(parameters), | 273 parameters_(parameters), |
274 clearAll_(false) | 274 clearAll_(false) |
275 { | 275 { |
276 } | 276 } |
277 | 277 |
278 | 278 |
279 int64_t MySQLIndex::CreateResource(const char* publicId, | 279 int64_t MySQLIndex::CreateResource(DatabaseManager& manager, |
280 const char* publicId, | |
280 OrthancPluginResourceType type) | 281 OrthancPluginResourceType type) |
281 { | 282 { |
282 { | 283 { |
283 DatabaseManager::CachedStatement statement( | 284 DatabaseManager::CachedStatement statement( |
284 STATEMENT_FROM_HERE, GetManager(), | 285 STATEMENT_FROM_HERE, manager, |
285 "INSERT INTO Resources VALUES(${}, ${type}, ${id}, NULL)"); | 286 "INSERT INTO Resources VALUES(${}, ${type}, ${id}, NULL)"); |
286 | 287 |
287 statement.SetParameterType("id", ValueType_Utf8String); | 288 statement.SetParameterType("id", ValueType_Utf8String); |
288 statement.SetParameterType("type", ValueType_Integer64); | 289 statement.SetParameterType("type", ValueType_Integer64); |
289 | 290 |
294 statement.Execute(args); | 295 statement.Execute(args); |
295 } | 296 } |
296 | 297 |
297 { | 298 { |
298 DatabaseManager::CachedStatement statement( | 299 DatabaseManager::CachedStatement statement( |
299 STATEMENT_FROM_HERE, GetManager(), | 300 STATEMENT_FROM_HERE, manager, |
300 "SELECT LAST_INSERT_ID()"); | 301 "SELECT LAST_INSERT_ID()"); |
301 | 302 |
302 statement.Execute(); | 303 statement.Execute(); |
303 | 304 |
304 return ReadInteger64(statement, 0); | 305 return ReadInteger64(statement, 0); |
305 } | 306 } |
306 } | 307 } |
307 | 308 |
308 | 309 |
309 void MySQLIndex::DeleteResource(IDatabaseBackendOutput& output, | 310 void MySQLIndex::DeleteResource(IDatabaseBackendOutput& output, |
311 DatabaseManager& manager, | |
310 int64_t id) | 312 int64_t id) |
311 { | 313 { |
312 ClearDeletedFiles(); | 314 ClearDeletedFiles(manager); |
313 | 315 |
314 // Recursive exploration of resources to be deleted, from the "id" | 316 // Recursive exploration of resources to be deleted, from the "id" |
315 // resource to the top of the tree of resources | 317 // resource to the top of the tree of resources |
316 | 318 |
317 bool done = false; | 319 bool done = false; |
320 { | 322 { |
321 int64_t parentId; | 323 int64_t parentId; |
322 | 324 |
323 { | 325 { |
324 DatabaseManager::CachedStatement lookupSiblings( | 326 DatabaseManager::CachedStatement lookupSiblings( |
325 STATEMENT_FROM_HERE, GetManager(), | 327 STATEMENT_FROM_HERE, manager, |
326 "SELECT parentId FROM Resources " | 328 "SELECT parentId FROM Resources " |
327 "WHERE parentId = (SELECT parentId FROM Resources WHERE internalId=${id});"); | 329 "WHERE parentId = (SELECT parentId FROM Resources WHERE internalId=${id});"); |
328 | 330 |
329 lookupSiblings.SetParameterType("id", ValueType_Integer64); | 331 lookupSiblings.SetParameterType("id", ValueType_Integer64); |
330 | 332 |
353 { | 355 { |
354 // "id" has at least one sibling node: the parent node is the remaining ancestor | 356 // "id" has at least one sibling node: the parent node is the remaining ancestor |
355 done = true; | 357 done = true; |
356 | 358 |
357 DatabaseManager::CachedStatement parent( | 359 DatabaseManager::CachedStatement parent( |
358 STATEMENT_FROM_HERE, GetManager(), | 360 STATEMENT_FROM_HERE, manager, |
359 "SELECT publicId, resourceType FROM Resources WHERE internalId=${id};"); | 361 "SELECT publicId, resourceType FROM Resources WHERE internalId=${id};"); |
360 | 362 |
361 parent.SetParameterType("id", ValueType_Integer64); | 363 parent.SetParameterType("id", ValueType_Integer64); |
362 | 364 |
363 Dictionary args; | 365 Dictionary args; |
373 } | 375 } |
374 } | 376 } |
375 | 377 |
376 { | 378 { |
377 DatabaseManager::CachedStatement deleteHierarchy( | 379 DatabaseManager::CachedStatement deleteHierarchy( |
378 STATEMENT_FROM_HERE, GetManager(), | 380 STATEMENT_FROM_HERE, manager, |
379 "DELETE FROM Resources WHERE internalId IN (SELECT * FROM (SELECT internalId FROM Resources WHERE internalId=${id} OR parentId=${id} OR parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}) OR parentId IN (SELECT internalId FROM Resources WHERE parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}))) as t);"); | 381 "DELETE FROM Resources WHERE internalId IN (SELECT * FROM (SELECT internalId FROM Resources WHERE internalId=${id} OR parentId=${id} OR parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}) OR parentId IN (SELECT internalId FROM Resources WHERE parentId IN (SELECT internalId FROM Resources WHERE parentId=${id}))) as t);"); |
380 | 382 |
381 deleteHierarchy.SetParameterType("id", ValueType_Integer64); | 383 deleteHierarchy.SetParameterType("id", ValueType_Integer64); |
382 | 384 |
383 Dictionary args; | 385 Dictionary args; |
384 args.SetIntegerValue("id", id); | 386 args.SetIntegerValue("id", id); |
385 | 387 |
386 deleteHierarchy.Execute(args); | 388 deleteHierarchy.Execute(args); |
387 } | 389 } |
388 | 390 |
389 SignalDeletedFiles(output); | 391 SignalDeletedFiles(output, manager); |
390 } | 392 } |
391 | 393 |
392 | 394 |
393 int64_t MySQLIndex::GetLastChangeIndex() | 395 int64_t MySQLIndex::GetLastChangeIndex(DatabaseManager& manager) |
394 { | 396 { |
395 DatabaseManager::CachedStatement statement( | 397 DatabaseManager::CachedStatement statement( |
396 STATEMENT_FROM_HERE, GetManager(), | 398 STATEMENT_FROM_HERE, manager, |
397 "SELECT value FROM GlobalIntegers WHERE property = 0"); | 399 "SELECT value FROM GlobalIntegers WHERE property = 0"); |
398 | 400 |
399 statement.SetReadOnly(true); | 401 statement.SetReadOnly(true); |
400 statement.Execute(); | 402 statement.Execute(); |
401 | 403 |
403 } | 405 } |
404 | 406 |
405 | 407 |
406 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 | 408 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
407 void MySQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, | 409 void MySQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, |
410 DatabaseManager& manager, | |
408 const char* hashPatient, | 411 const char* hashPatient, |
409 const char* hashStudy, | 412 const char* hashStudy, |
410 const char* hashSeries, | 413 const char* hashSeries, |
411 const char* hashInstance) | 414 const char* hashInstance) |
412 { | 415 { |
413 { | 416 { |
414 DatabaseManager::CachedStatement statement( | 417 DatabaseManager::CachedStatement statement( |
415 STATEMENT_FROM_HERE, GetManager(), | 418 STATEMENT_FROM_HERE, manager, |
416 "CALL CreateInstance(${patient}, ${study}, ${series}, ${instance}, " | 419 "CALL CreateInstance(${patient}, ${study}, ${series}, ${instance}, " |
417 "@isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, " | 420 "@isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, " |
418 "@patientKey, @studyKey, @seriesKey, @instanceKey)"); | 421 "@patientKey, @studyKey, @seriesKey, @instanceKey)"); |
419 | 422 |
420 statement.SetParameterType("patient", ValueType_Utf8String); | 423 statement.SetParameterType("patient", ValueType_Utf8String); |
436 } | 439 } |
437 } | 440 } |
438 | 441 |
439 { | 442 { |
440 DatabaseManager::CachedStatement statement( | 443 DatabaseManager::CachedStatement statement( |
441 STATEMENT_FROM_HERE, GetManager(), | 444 STATEMENT_FROM_HERE, manager, |
442 "SELECT @isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, " | 445 "SELECT @isNewPatient, @isNewStudy, @isNewSeries, @isNewInstance, " |
443 "@patientKey, @studyKey, @seriesKey, @instanceKey"); | 446 "@patientKey, @studyKey, @seriesKey, @instanceKey"); |
444 | 447 |
445 statement.Execute(); | 448 statement.Execute(); |
446 | 449 |