Mercurial > hg > orthanc-databases
comparison Framework/Plugins/StorageBackend.cpp @ 12:41543239072d
transactions for storage area
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Jul 2018 18:34:56 +0200 |
parents | d17b2631bb67 |
children | 9774802fd05f |
comparison
equal
deleted
inserted
replaced
11:0217486720b3 | 12:41543239072d |
---|---|
46 } | 46 } |
47 | 47 |
48 | 48 |
49 namespace OrthancDatabases | 49 namespace OrthancDatabases |
50 { | 50 { |
51 void StorageBackend::ReadFromString(void*& buffer, | |
52 size_t& size, | |
53 const std::string& content) | |
54 { | |
55 size = content.size(); | |
56 | |
57 if (content.empty()) | |
58 { | |
59 buffer = NULL; | |
60 } | |
61 else | |
62 { | |
63 buffer = malloc(size); | |
64 | |
65 if (buffer == NULL) | |
66 { | |
67 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory); | |
68 } | |
69 | |
70 memcpy(buffer, content.c_str(), size); | |
71 } | |
72 } | |
73 | |
74 | |
51 StorageBackend::StorageBackend(IDatabaseFactory* factory) : | 75 StorageBackend::StorageBackend(IDatabaseFactory* factory) : |
52 manager_(factory) | 76 manager_(factory) |
53 { | 77 { |
54 } | 78 } |
55 | 79 |
56 | 80 |
57 | |
58 static OrthancPluginContext* context_ = NULL; | 81 static OrthancPluginContext* context_ = NULL; |
59 static std::auto_ptr<StorageBackend> backend_; | 82 static std::auto_ptr<StorageBackend> backend_; |
60 | 83 |
84 | |
61 static OrthancPluginErrorCode StorageCreate(const char* uuid, | 85 static OrthancPluginErrorCode StorageCreate(const char* uuid, |
62 const void* content, | 86 const void* content, |
63 int64_t size, | 87 int64_t size, |
64 OrthancPluginContentType type) | 88 OrthancPluginContentType type) |
65 { | 89 { |
66 try | 90 try |
67 { | 91 { |
68 backend_->Create(uuid, content, static_cast<size_t>(size), type); | 92 DatabaseManager::Transaction transaction(backend_->GetManager()); |
93 backend_->Create(transaction, uuid, content, static_cast<size_t>(size), type); | |
94 transaction.Commit(); | |
69 return OrthancPluginErrorCode_Success; | 95 return OrthancPluginErrorCode_Success; |
70 } | 96 } |
71 ORTHANC_PLUGINS_DATABASE_CATCH; | 97 ORTHANC_PLUGINS_DATABASE_CATCH; |
72 } | 98 } |
73 | 99 |
77 const char* uuid, | 103 const char* uuid, |
78 OrthancPluginContentType type) | 104 OrthancPluginContentType type) |
79 { | 105 { |
80 try | 106 try |
81 { | 107 { |
108 DatabaseManager::Transaction transaction(backend_->GetManager()); | |
82 size_t tmp; | 109 size_t tmp; |
83 backend_->Read(*content, tmp, uuid, type); | 110 backend_->Read(*content, tmp, transaction, uuid, type); |
84 *size = static_cast<int64_t>(tmp); | 111 *size = static_cast<int64_t>(tmp); |
112 transaction.Commit(); | |
85 return OrthancPluginErrorCode_Success; | 113 return OrthancPluginErrorCode_Success; |
86 } | 114 } |
87 ORTHANC_PLUGINS_DATABASE_CATCH; | 115 ORTHANC_PLUGINS_DATABASE_CATCH; |
88 } | 116 } |
89 | 117 |
91 static OrthancPluginErrorCode StorageRemove(const char* uuid, | 119 static OrthancPluginErrorCode StorageRemove(const char* uuid, |
92 OrthancPluginContentType type) | 120 OrthancPluginContentType type) |
93 { | 121 { |
94 try | 122 try |
95 { | 123 { |
96 backend_->Remove(uuid, type); | 124 DatabaseManager::Transaction transaction(backend_->GetManager()); |
125 backend_->Remove(transaction, uuid, type); | |
126 transaction.Commit(); | |
97 return OrthancPluginErrorCode_Success; | 127 return OrthancPluginErrorCode_Success; |
98 } | 128 } |
99 ORTHANC_PLUGINS_DATABASE_CATCH; | 129 ORTHANC_PLUGINS_DATABASE_CATCH; |
100 } | 130 } |
101 | 131 |