Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerIndex.cpp @ 4560:929409e40008 db-changes
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Mar 2021 18:42:25 +0100 |
parents | 19b1921aee06 |
children | 02510325d869 |
comparison
equal
deleted
inserted
replaced
4559:19b1921aee06 | 4560:929409e40008 |
---|---|
1438 | 1438 |
1439 t.Commit(0); | 1439 t.Commit(0); |
1440 } | 1440 } |
1441 | 1441 |
1442 | 1442 |
1443 bool ServerIndex::LookupMetadata(std::string& target, | |
1444 const std::string& publicId, | |
1445 ResourceType expectedType, | |
1446 MetadataType type) | |
1447 { | |
1448 boost::mutex::scoped_lock lock(mutex_); | |
1449 | |
1450 ResourceType rtype; | |
1451 int64_t id; | |
1452 if (!db_.LookupResource(id, rtype, publicId) || | |
1453 rtype != expectedType) | |
1454 { | |
1455 throw OrthancException(ErrorCode_UnknownResource); | |
1456 } | |
1457 | |
1458 return db_.LookupMetadata(target, id, type); | |
1459 } | |
1460 | |
1461 | |
1462 void ServerIndex::ListAvailableAttachments(std::set<FileContentType>& target, | |
1463 const std::string& publicId, | |
1464 ResourceType expectedType) | |
1465 { | |
1466 boost::mutex::scoped_lock lock(mutex_); | |
1467 | |
1468 ResourceType type; | |
1469 int64_t id; | |
1470 if (!db_.LookupResource(id, type, publicId) || | |
1471 expectedType != type) | |
1472 { | |
1473 throw OrthancException(ErrorCode_UnknownResource); | |
1474 } | |
1475 | |
1476 db_.ListAvailableAttachments(target, id); | |
1477 } | |
1478 | |
1479 | |
1480 bool ServerIndex::LookupParent(std::string& target, | |
1481 const std::string& publicId) | |
1482 { | |
1483 boost::mutex::scoped_lock lock(mutex_); | |
1484 | |
1485 ResourceType type; | |
1486 int64_t id; | |
1487 if (!db_.LookupResource(id, type, publicId)) | |
1488 { | |
1489 throw OrthancException(ErrorCode_UnknownResource); | |
1490 } | |
1491 | |
1492 int64_t parentId; | |
1493 if (db_.LookupParent(parentId, id)) | |
1494 { | |
1495 target = db_.GetPublicId(parentId); | |
1496 return true; | |
1497 } | |
1498 else | |
1499 { | |
1500 return false; | |
1501 } | |
1502 } | |
1503 | |
1504 | |
1505 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence) | 1443 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence) |
1506 { | 1444 { |
1507 boost::mutex::scoped_lock lock(mutex_); | 1445 boost::mutex::scoped_lock lock(mutex_); |
1508 Transaction transaction(*this); | 1446 Transaction transaction(*this); |
1509 | 1447 |
3128 }; | 3066 }; |
3129 | 3067 |
3130 Operations operations; | 3068 Operations operations; |
3131 operations.Apply(*this, &result, publicId); | 3069 operations.Apply(*this, &result, publicId); |
3132 } | 3070 } |
3071 | |
3072 | |
3073 bool ServerIndex::LookupMetadata(std::string& target, | |
3074 const std::string& publicId, | |
3075 ResourceType expectedType, | |
3076 MetadataType type) | |
3077 { | |
3078 class Operations : public ReadOnlyOperationsT4<std::string*, std::string, ResourceType, MetadataType> | |
3079 { | |
3080 private: | |
3081 bool found_; | |
3082 | |
3083 public: | |
3084 Operations() : | |
3085 found_(false) | |
3086 { | |
3087 } | |
3088 | |
3089 bool HasFound() | |
3090 { | |
3091 return found_; | |
3092 } | |
3093 | |
3094 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
3095 const Tuple& tuple) ORTHANC_OVERRIDE | |
3096 { | |
3097 ResourceType rtype; | |
3098 int64_t id; | |
3099 if (!transaction.LookupResource(id, rtype, tuple.get<1>()) || | |
3100 rtype != tuple.get<2>()) | |
3101 { | |
3102 throw OrthancException(ErrorCode_UnknownResource); | |
3103 } | |
3104 else | |
3105 { | |
3106 found_ = transaction.LookupMetadata(*tuple.get<0>(), id, tuple.get<3>()); | |
3107 } | |
3108 } | |
3109 }; | |
3110 | |
3111 Operations operations; | |
3112 operations.Apply(*this, &target, publicId, expectedType, type); | |
3113 return operations.HasFound(); | |
3114 } | |
3115 | |
3116 | |
3117 void ServerIndex::ListAvailableAttachments(std::set<FileContentType>& target, | |
3118 const std::string& publicId, | |
3119 ResourceType expectedType) | |
3120 { | |
3121 class Operations : public ReadOnlyOperationsT3<std::set<FileContentType>*, std::string, ResourceType> | |
3122 { | |
3123 public: | |
3124 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
3125 const Tuple& tuple) ORTHANC_OVERRIDE | |
3126 { | |
3127 ResourceType type; | |
3128 int64_t id; | |
3129 if (!transaction.LookupResource(id, type, tuple.get<1>()) || | |
3130 tuple.get<2>() != type) | |
3131 { | |
3132 throw OrthancException(ErrorCode_UnknownResource); | |
3133 } | |
3134 else | |
3135 { | |
3136 transaction.ListAvailableAttachments(*tuple.get<0>(), id); | |
3137 } | |
3138 } | |
3139 }; | |
3140 | |
3141 Operations operations; | |
3142 operations.Apply(*this, &target, publicId, expectedType); | |
3143 } | |
3144 | |
3145 | |
3146 bool ServerIndex::LookupParent(std::string& target, | |
3147 const std::string& publicId) | |
3148 { | |
3149 class Operations : public ReadOnlyOperationsT2<std::string*, std::string> | |
3150 { | |
3151 private: | |
3152 bool found_; | |
3153 | |
3154 public: | |
3155 Operations() : | |
3156 found_(false) | |
3157 { | |
3158 } | |
3159 | |
3160 bool HasFound() | |
3161 { | |
3162 return found_; | |
3163 } | |
3164 | |
3165 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
3166 const Tuple& tuple) ORTHANC_OVERRIDE | |
3167 { | |
3168 ResourceType type; | |
3169 int64_t id; | |
3170 if (!transaction.LookupResource(id, type, tuple.get<1>())) | |
3171 { | |
3172 throw OrthancException(ErrorCode_UnknownResource); | |
3173 } | |
3174 else | |
3175 { | |
3176 int64_t parentId; | |
3177 if (transaction.LookupParent(parentId, id)) | |
3178 { | |
3179 *tuple.get<0>() = transaction.GetPublicId(parentId); | |
3180 found_ = true; | |
3181 } | |
3182 } | |
3183 } | |
3184 }; | |
3185 | |
3186 Operations operations; | |
3187 operations.Apply(*this, &target, publicId); | |
3188 return operations.HasFound(); | |
3189 } | |
3133 } | 3190 } |