comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 4607:f75c63aa9de0 db-changes

differentiating between shared and private global properties
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Mar 2021 18:10:27 +0200
parents cfdd1f59ff6f
children 37de0a5ebe86
comparison
equal deleted inserted replaced
4606:d01702fb29a9 4607:f75c63aa9de0
1656 Apply(operations); 1656 Apply(operations);
1657 } 1657 }
1658 1658
1659 1659
1660 bool StatelessDatabaseOperations::LookupGlobalProperty(std::string& value, 1660 bool StatelessDatabaseOperations::LookupGlobalProperty(std::string& value,
1661 GlobalProperty property) 1661 GlobalProperty property,
1662 { 1662 bool shared)
1663 class Operations : public ReadOnlyOperationsT3<bool&, std::string&, GlobalProperty> 1663 {
1664 class Operations : public ReadOnlyOperationsT4<bool&, std::string&, GlobalProperty, bool>
1664 { 1665 {
1665 public: 1666 public:
1666 virtual void ApplyTuple(ReadOnlyTransaction& transaction, 1667 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
1667 const Tuple& tuple) ORTHANC_OVERRIDE 1668 const Tuple& tuple) ORTHANC_OVERRIDE
1668 { 1669 {
1669 // TODO - CANDIDATE FOR "TransactionType_Implicit" 1670 // TODO - CANDIDATE FOR "TransactionType_Implicit"
1670 tuple.get<0>() = transaction.LookupGlobalProperty(tuple.get<1>(), tuple.get<2>()); 1671 tuple.get<0>() = transaction.LookupGlobalProperty(tuple.get<1>(), tuple.get<2>(), tuple.get<3>());
1671 } 1672 }
1672 }; 1673 };
1673 1674
1674 bool found; 1675 bool found;
1675 Operations operations; 1676 Operations operations;
1676 operations.Apply(*this, found, value, property); 1677 operations.Apply(*this, found, value, property, shared);
1677 return found; 1678 return found;
1678 } 1679 }
1679 1680
1680 1681
1681 std::string StatelessDatabaseOperations::GetGlobalProperty(GlobalProperty property, 1682 std::string StatelessDatabaseOperations::GetGlobalProperty(GlobalProperty property,
1683 bool shared,
1682 const std::string& defaultValue) 1684 const std::string& defaultValue)
1683 { 1685 {
1684 std::string s; 1686 std::string s;
1685 if (LookupGlobalProperty(s, property)) 1687 if (LookupGlobalProperty(s, property, shared))
1686 { 1688 {
1687 return s; 1689 return s;
1688 } 1690 }
1689 else 1691 else
1690 { 1692 {
2271 Operations operations(publicId, type); 2273 Operations operations(publicId, type);
2272 Apply(operations); 2274 Apply(operations);
2273 } 2275 }
2274 2276
2275 2277
2276 uint64_t StatelessDatabaseOperations::IncrementGlobalSequence(GlobalProperty sequence) 2278 uint64_t StatelessDatabaseOperations::IncrementGlobalSequence(GlobalProperty sequence,
2279 bool shared)
2277 { 2280 {
2278 class Operations : public IReadWriteOperations 2281 class Operations : public IReadWriteOperations
2279 { 2282 {
2280 private: 2283 private:
2281 uint64_t newValue_; 2284 uint64_t newValue_;
2282 GlobalProperty sequence_; 2285 GlobalProperty sequence_;
2283 2286 bool shared_;
2284 public: 2287
2285 explicit Operations(GlobalProperty sequence) : 2288 public:
2289 Operations(GlobalProperty sequence,
2290 bool shared) :
2286 newValue_(0), // Dummy initialization 2291 newValue_(0), // Dummy initialization
2287 sequence_(sequence) 2292 sequence_(sequence),
2293 shared_(shared)
2288 { 2294 {
2289 } 2295 }
2290 2296
2291 uint64_t GetNewValue() const 2297 uint64_t GetNewValue() const
2292 { 2298 {
2295 2301
2296 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE 2302 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
2297 { 2303 {
2298 std::string oldString; 2304 std::string oldString;
2299 2305
2300 if (transaction.LookupGlobalProperty(oldString, sequence_)) 2306 if (transaction.LookupGlobalProperty(oldString, sequence_, shared_))
2301 { 2307 {
2302 uint64_t oldValue; 2308 uint64_t oldValue;
2303 2309
2304 try 2310 try
2305 { 2311 {
2318 { 2324 {
2319 // Initialize the sequence at "1" 2325 // Initialize the sequence at "1"
2320 newValue_ = 1; 2326 newValue_ = 1;
2321 } 2327 }
2322 2328
2323 transaction.SetGlobalProperty(sequence_, boost::lexical_cast<std::string>(newValue_)); 2329 transaction.SetGlobalProperty(sequence_, shared_, boost::lexical_cast<std::string>(newValue_));
2324 } 2330 }
2325 }; 2331 };
2326 2332
2327 Operations operations(sequence); 2333 Operations operations(sequence, shared);
2328 Apply(operations); 2334 Apply(operations);
2329 assert(operations.GetNewValue() != 0); 2335 assert(operations.GetNewValue() != 0);
2330 return operations.GetNewValue(); 2336 return operations.GetNewValue();
2331 } 2337 }
2332 2338
2362 Apply(operations); 2368 Apply(operations);
2363 } 2369 }
2364 2370
2365 2371
2366 void StatelessDatabaseOperations::SetGlobalProperty(GlobalProperty property, 2372 void StatelessDatabaseOperations::SetGlobalProperty(GlobalProperty property,
2373 bool shared,
2367 const std::string& value) 2374 const std::string& value)
2368 { 2375 {
2369 class Operations : public IReadWriteOperations 2376 class Operations : public IReadWriteOperations
2370 { 2377 {
2371 private: 2378 private:
2372 GlobalProperty property_; 2379 GlobalProperty property_;
2380 bool shared_;
2373 const std::string& value_; 2381 const std::string& value_;
2374 2382
2375 public: 2383 public:
2376 Operations(GlobalProperty property, 2384 Operations(GlobalProperty property,
2385 bool shared,
2377 const std::string& value) : 2386 const std::string& value) :
2378 property_(property), 2387 property_(property),
2388 shared_(shared),
2379 value_(value) 2389 value_(value)
2380 { 2390 {
2381 } 2391 }
2382 2392
2383 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE 2393 virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
2384 { 2394 {
2385 transaction.SetGlobalProperty(property_, value_); 2395 transaction.SetGlobalProperty(property_, shared_, value_);
2386 } 2396 }
2387 }; 2397 };
2388 2398
2389 Operations operations(property, value); 2399 Operations operations(property, shared, value);
2390 Apply(operations); 2400 Apply(operations);
2391 } 2401 }
2392 2402
2393 2403
2394 void StatelessDatabaseOperations::DeleteAttachment(const std::string& publicId, 2404 void StatelessDatabaseOperations::DeleteAttachment(const std::string& publicId,