Mercurial > hg > orthanc
comparison OrthancServer/DatabaseWrapper.cpp @ 1177:5b2d8c280ac2 db-changes
Plugins can monitor changes through callbacks
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 24 Sep 2014 17:37:44 +0200 |
parents | 3b372ab992ec |
children | 6b9b02a16e99 |
comparison
equal
deleted
inserted
replaced
1176:f24e04838054 | 1177:5b2d8c280ac2 |
---|---|
114 } | 114 } |
115 | 115 |
116 virtual void Compute(SQLite::FunctionContext& context) | 116 virtual void Compute(SQLite::FunctionContext& context) |
117 { | 117 { |
118 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1)); | 118 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1)); |
119 listener_.SignalResourceDeleted(type, context.GetStringValue(0)); | 119 listener_.SignalChange(ChangeType_Deleted, type, context.GetStringValue(0)); |
120 } | 120 } |
121 }; | 121 }; |
122 | 122 |
123 class SignalRemainingAncestor : public SQLite::IScalarFunction | 123 class SignalRemainingAncestor : public SQLite::IScalarFunction |
124 { | 124 { |
256 | 256 |
257 default: | 257 default: |
258 throw OrthancException(ErrorCode_InternalError); | 258 throw OrthancException(ErrorCode_InternalError); |
259 } | 259 } |
260 | 260 |
261 LogChange(changeType, id, type); | 261 LogChange(changeType, id, type, publicId); |
262 return id; | 262 return id; |
263 } | 263 } |
264 | 264 |
265 bool DatabaseWrapper::LookupResource(const std::string& publicId, | 265 bool DatabaseWrapper::LookupResource(const std::string& publicId, |
266 int64_t& id, | 266 int64_t& id, |
648 | 648 |
649 | 649 |
650 void DatabaseWrapper::LogChange(ChangeType changeType, | 650 void DatabaseWrapper::LogChange(ChangeType changeType, |
651 int64_t internalId, | 651 int64_t internalId, |
652 ResourceType resourceType, | 652 ResourceType resourceType, |
653 const boost::posix_time::ptime& date) | 653 const std::string& publicId) |
654 { | 654 { |
655 if (changeType == ChangeType_Deleted) | |
656 { | |
657 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
658 } | |
659 | |
660 const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); | |
661 | |
655 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)"); | 662 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)"); |
656 s.BindInt(0, changeType); | 663 s.BindInt(0, changeType); |
657 s.BindInt64(1, internalId); | 664 s.BindInt64(1, internalId); |
658 s.BindInt(2, resourceType); | 665 s.BindInt(2, resourceType); |
659 s.BindString(3, boost::posix_time::to_iso_string(date)); | 666 s.BindString(3, boost::posix_time::to_iso_string(now)); |
660 s.Run(); | 667 s.Run(); |
668 | |
669 listener_.SignalChange(changeType, resourceType, publicId); | |
661 } | 670 } |
662 | 671 |
663 | 672 |
664 void DatabaseWrapper::GetChangesInternal(Json::Value& target, | 673 void DatabaseWrapper::GetChangesInternal(Json::Value& target, |
665 SQLite::Statement& s, | 674 SQLite::Statement& s, |