comparison OrthancServer/Sources/ServerIndex.cpp @ 4568:a3e6aa2b07b0 db-changes

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Mar 2021 15:00:58 +0100
parents b812a5f2cef3
children 19ea4ecd6d9a
comparison
equal deleted inserted replaced
4567:b812a5f2cef3 4568:a3e6aa2b07b0
1203 Recycle(0, ""); 1203 Recycle(0, "");
1204 t.Commit(0); 1204 t.Commit(0);
1205 } 1205 }
1206 1206
1207 1207
1208 void ServerIndex::LogChange(ChangeType changeType,
1209 const std::string& publicId)
1210 {
1211 boost::mutex::scoped_lock lock(mutex_);
1212 Transaction transaction(*this);
1213
1214 int64_t id;
1215 ResourceType type;
1216 if (!db_.LookupResource(id, type, publicId))
1217 {
1218 throw OrthancException(ErrorCode_UnknownResource);
1219 }
1220
1221 LogChange(id, changeType, type, publicId);
1222 transaction.Commit(0);
1223 }
1224
1225
1226 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that, 1208 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that,
1227 unsigned int threadSleep) 1209 unsigned int threadSleep)
1228 { 1210 {
1229 int stableAge; 1211 int stableAge;
1230 1212
1351 } 1333 }
1352 1334
1353 t.Commit(attachment.GetCompressedSize()); 1335 t.Commit(attachment.GetCompressedSize());
1354 1336
1355 return StoreStatus_Success; 1337 return StoreStatus_Success;
1356 }
1357
1358
1359 void ServerIndex::DeleteAttachment(const std::string& publicId,
1360 FileContentType type)
1361 {
1362 boost::mutex::scoped_lock lock(mutex_);
1363 Transaction t(*this);
1364
1365 ResourceType rtype;
1366 int64_t id;
1367 if (!db_.LookupResource(id, rtype, publicId))
1368 {
1369 throw OrthancException(ErrorCode_UnknownResource);
1370 }
1371
1372 db_.DeleteAttachment(id, type);
1373
1374 if (IsUserContentType(type))
1375 {
1376 LogChange(id, ChangeType_UpdatedAttachment, rtype, publicId);
1377 }
1378
1379 t.Commit(0);
1380 } 1338 }
1381 1339
1382 1340
1383 void ServerIndex::ReconstructInstance(const ParsedDicomFile& dicom) 1341 void ServerIndex::ReconstructInstance(const ParsedDicomFile& dicom)
1384 { 1342 {
3401 }; 3359 };
3402 3360
3403 Operations operations(property, value); 3361 Operations operations(property, value);
3404 Apply(operations); 3362 Apply(operations);
3405 } 3363 }
3364
3365
3366 void ServerIndex::DeleteAttachment(const std::string& publicId,
3367 FileContentType type)
3368 {
3369 class Operations : public IReadWriteOperations
3370 {
3371 private:
3372 const std::string& publicId_;
3373 FileContentType type_;
3374
3375 public:
3376 Operations(const std::string& publicId,
3377 FileContentType type) :
3378 publicId_(publicId),
3379 type_(type)
3380 {
3381 }
3382
3383 virtual void Apply(ReadWriteTransaction& transaction,
3384 Listener& listener) ORTHANC_OVERRIDE
3385 {
3386 ResourceType rtype;
3387 int64_t id;
3388 if (!transaction.LookupResource(id, rtype, publicId_))
3389 {
3390 throw OrthancException(ErrorCode_UnknownResource);
3391 }
3392 else
3393 {
3394 transaction.DeleteAttachment(id, type_);
3395
3396 if (IsUserContentType(type_))
3397 {
3398 transaction.LogChange(id, ChangeType_UpdatedAttachment, rtype, publicId_);
3399 }
3400 }
3401 }
3402 };
3403
3404 Operations operations(publicId, type);
3405 Apply(operations);
3406 }
3407
3408
3409 void ServerIndex::LogChange(ChangeType changeType,
3410 const std::string& publicId)
3411 {
3412 class Operations : public IReadWriteOperations
3413 {
3414 private:
3415 ChangeType changeType_;
3416 const std::string& publicId_;
3417
3418 public:
3419 Operations(ChangeType changeType,
3420 const std::string& publicId) :
3421 changeType_(changeType),
3422 publicId_(publicId)
3423 {
3424 }
3425
3426 virtual void Apply(ReadWriteTransaction& transaction,
3427 Listener& listener) ORTHANC_OVERRIDE
3428 {
3429 int64_t id;
3430 ResourceType type;
3431 if (!transaction.LookupResource(id, type, publicId_))
3432 {
3433 throw OrthancException(ErrorCode_UnknownResource);
3434 }
3435 else
3436 {
3437 transaction.LogChange(id, changeType_, type, publicId_);
3438 }
3439 }
3440 };
3441
3442 Operations operations(changeType, publicId);
3443 Apply(operations);
3444 }
3406 } 3445 }