comparison OrthancServer/DatabaseWrapper.cpp @ 1198:1169528a9a5f db-changes

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 Oct 2014 13:52:01 +0200
parents 6b9b02a16e99
children 178de5edc0a8
comparison
equal deleted inserted replaced
1197:61b71ccac362 1198:1169528a9a5f
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_.SignalChange(ChangeType_Deleted, type, context.GetStringValue(0)); 119 ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0));
120 listener_.SignalChange(change);
120 } 121 }
121 }; 122 };
122 123
123 class SignalRemainingAncestor : public SQLite::IScalarFunction 124 class SignalRemainingAncestor : public SQLite::IScalarFunction
124 { 125 {
256 257
257 default: 258 default:
258 throw OrthancException(ErrorCode_InternalError); 259 throw OrthancException(ErrorCode_InternalError);
259 } 260 }
260 261
261 LogChange(changeType, id, type, publicId); 262 LogChange(id, changeType, type, publicId);
262 return id; 263 return id;
263 } 264 }
264 265
265 bool DatabaseWrapper::LookupResource(const std::string& publicId, 266 bool DatabaseWrapper::LookupResource(const std::string& publicId,
266 int64_t& id, 267 int64_t& id,
645 result.push_back(s.ColumnInt64(0)); 646 result.push_back(s.ColumnInt64(0));
646 } 647 }
647 } 648 }
648 649
649 650
650 void DatabaseWrapper::LogChange(ChangeType changeType, 651 void DatabaseWrapper::LogChange(int64_t internalId,
651 int64_t internalId, 652 const ServerIndexChange& change)
652 ResourceType resourceType, 653 {
653 const std::string& publicId) 654 if (change.GetChangeType() <= ChangeType_INTERNAL_LastLogged)
654 {
655 if (changeType <= ChangeType_INTERNAL_LastLogged)
656 { 655 {
657 const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); 656 const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
658 657
659 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)"); 658 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)");
660 s.BindInt(0, changeType); 659 s.BindInt(0, change.GetChangeType());
661 s.BindInt64(1, internalId); 660 s.BindInt64(1, internalId);
662 s.BindInt(2, resourceType); 661 s.BindInt(2, change.GetResourceType());
663 s.BindString(3, boost::posix_time::to_iso_string(now)); 662 s.BindString(3, boost::posix_time::to_iso_string(now));
664 s.Run(); 663 s.Run();
665 } 664 }
666 665
667 listener_.SignalChange(changeType, resourceType, publicId); 666 listener_.SignalChange(change);
668 } 667 }
669 668
670 669
671 void DatabaseWrapper::GetChangesInternal(Json::Value& target, 670 void DatabaseWrapper::GetChangesInternal(Json::Value& target,
672 SQLite::Statement& s, 671 SQLite::Statement& s,