From: caballero Date: Thu, 30 Apr 2009 13:56:10 +0000 (+0000) Subject: Added functionality of timestamp and maintenance databases when using multiple sources X-Git-Tag: EED.02Oct2009~76 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=8b74b6a37dfc8b8a3ebb4f9f8e4b46429da0e4c7;p=creaImageIO.git Added functionality of timestamp and maintenance databases when using multiple sources --- diff --git a/appli/TestWxGimmickReaderDialog/main.cxx b/appli/TestWxGimmickReaderDialog/main.cxx index 19afb05..45c72d6 100644 --- a/appli/TestWxGimmickReaderDialog/main.cxx +++ b/appli/TestWxGimmickReaderDialog/main.cxx @@ -62,6 +62,7 @@ bool myApp::OnInit( ) //Puts images std::vector images; w.GetSelectedImages(images,output_dim); + std::cout<Delete(); diff --git a/appli/gimmick/main.cxx b/appli/gimmick/main.cxx index b456e3f..ab08f62 100644 --- a/appli/gimmick/main.cxx +++ b/appli/gimmick/main.cxx @@ -27,7 +27,7 @@ int main(int ac, char* av[]) ("print,p","Prints the local database tree (default=off)") ("file,f",po::value< vector >(),"Adds the file to the local database") ("dir,d",po::value< vector >(),"Adds the directory to the local database") - ("sync,s","Synchronizes the local database with the files") + ("sync,s",po::value< vector >(),"Synchronizes the local database with the files") ("recurse,r","Recurse into sub-directories (default=off)") ("repair,R","Repair the database (on synchronization) (default=off)") ("check,c","Check for attribute differences (on synchronization) (default=off)"); @@ -97,13 +97,14 @@ int main(int ac, char* av[]) if (vm.count("sync")) { bool rep=false; bool chk=false; + std::vector name=vm["sync"].as< vector >(); std::stringstream out; out<RemoveNode("PATH",node); + mTimestampDatabase->RemoveNode("PATH",node,d); mImageAdder.RemoveFile(node); } //======================================================================== //======================================================================== - std::string Gimmick::Synchronize(bool repair, bool checkAttributes) + std::string Gimmick::Synchronize(const std::string& d, bool repair, bool checkAttributes) { - TreeHandler * handler=GetTreeHandler("Local database"); + TreeHandler * handler=GetTreeHandler(d); + mImageAdder.SetCurrentDatabase(d); mImageAdder.SetTreeHandler(handler); mImageAdder.SetTimestampHandler(mTimestampDatabase); mImageAdder.SetSynchronizer(mSynchronizer); diff --git a/src2/creaImageIOGimmick.h b/src2/creaImageIOGimmick.h index b316b1b..b97df6f 100644 --- a/src2/creaImageIOGimmick.h +++ b/src2/creaImageIOGimmick.h @@ -96,9 +96,9 @@ namespace creaImageIO void RemoveFile(const std::string& d, tree::Node* filename); - ///Synchronizes the loaded data with the database. If remove is true the database will be updated, otherwise + ///Synchronizes the loaded data with the database d. If repair is true the database will be updated, otherwise ///only a warning sign will be issued - std::string Synchronize(bool repair, bool checkAttributes); + std::string Synchronize(const std::string& d, bool repair, bool checkAttributes); /// Prints the tree handled by the handler void Print(const std::string& handler); diff --git a/src2/creaImageIOSynchron.cpp b/src2/creaImageIOSynchron.cpp index 9ec4bae..136c29e 100644 --- a/src2/creaImageIOSynchron.cpp +++ b/src2/creaImageIOSynchron.cpp @@ -72,7 +72,7 @@ namespace creaImageIO } } // get the ADD operations List - UpdateAddList(); + //UpdateAddList(pathDB); } //===================================================================== @@ -87,6 +87,7 @@ namespace creaImageIO command += ",\nPATH text"; command += ",\nRECURSIVE boolean"; command += ",\nFILES_ADDED int"; + command += ",\nREFERENCEDDB text"; command += "\n)"; UPDATESYNCDB(command); @@ -117,9 +118,9 @@ namespace creaImageIO } //===================================================================== - void Synchronizer::GetFileList(std::vector & list) + void Synchronizer::GetFileList(std::vector & list, const std::string& refdb) { - CleanList(); + CleanList(refdb); list=mAddList; } @@ -130,9 +131,9 @@ namespace creaImageIO } //===================================================================== - void Synchronizer::UpdateAddList() + void Synchronizer::UpdateAddList(const std::string& refdb) { - std::string query = "SELECT * FROM ADD_OPS"; + std::string query = "SELECT * FROM ADD_OPS WHERE REFERENCEDDB = '"+refdb+"';"; CppSQLite3Query res; QUERYSYNCDB(query, res); while (!res.eof()) @@ -157,12 +158,13 @@ namespace creaImageIO ///////////////////////////////////////////////////////////////////////////////////////////////// // clean DataBase if an operation has no child anymore + // @param refdb: the database segement to clean // @result : - ///////////////////////////////////////////////////////////////////////////////////////////////// - void Synchronizer::CleanList() + void Synchronizer::CleanList(const std::string& refdb) { mAddList.clear(); - UpdateAddList(); + UpdateAddList(refdb); std::vector::iterator it_add = mAddList.begin(); for(;it_add & files); + void GetFileList(std::vector& files , const std::string& refdb); void GetIgnoredFiles(const std::string& key, std::vector &ignoreList); std::string GetAttribute(const std::string& attribute, const std::string& table, const std::string& searchParam, - const std::string& searchValue); + const std::string& searchValue, + const std::string& refdb); void SetAttribute(const std::string& attribute, const std::string& table, const std::string& value, const std::string& searchParam, - const std::string& searchValue); + const std::string& searchValue, + const std::string& refdb); std::vector mAddList; std::vector mIgnoreList; private : @@ -79,8 +83,8 @@ namespace creaImageIO CppSQLite3DB* mDB; std::string pathDB; void CreateDB(); - void UpdateAddList(); - void CleanList(); + void UpdateAddList(const std::string& refdb); + void CleanList(const std::string& refdb); void CleanName(std::string& str) const; std::vector GetIgnoreList(const std::string &i_key); diff --git a/src2/creaImageIOTimestampDatabaseHandler.cpp b/src2/creaImageIOTimestampDatabaseHandler.cpp index be586d8..167224b 100644 --- a/src2/creaImageIOTimestampDatabaseHandler.cpp +++ b/src2/creaImageIOTimestampDatabaseHandler.cpp @@ -169,6 +169,7 @@ namespace creaImageIO command += ",\nLastModified datetext"; command += ",\nLastRead datetext"; command += ",\nTopLevelNodeId text"; + command += ",\nReferencedDB text"; command += ",\nconstraint FK_PARENT foreign key (PARENT_ID) references "; command += "FILES"; command += "(ID) on delete restrict on update restrict"; @@ -182,7 +183,7 @@ namespace creaImageIO //===================================================================== - void TimestampDatabaseHandler::CleanName(std::string& str) const + void TimestampDatabaseHandler::CleanPath(std::string& str) const { size_t pos; do @@ -195,56 +196,55 @@ namespace creaImageIO } while ((int)pos!=-1); } - - //===================================================================== bool TimestampDatabaseHandler::AddDirectory(const std::string& parent, const std::string& path, const time_t lastModif, - const time_t lastRead) + const time_t lastRead, + const std::string& refdb) { bool valid=false; std::string par=parent.c_str(); std::string pat=path.c_str(); - CleanName(par); - CleanName(pat); + CleanPath(par); + CleanPath(pat); - std::string pathId=IsIndexed(pat); + std::string pathId=IsIndexed(pat,refdb); //Case: It is a root parent if(parent.compare("")==0) { if(pathId.compare("")==0) { - AddFile(pat,lastModif,lastRead); + AddFile(pat,lastModif,lastRead,refdb); valid=true; } else { - valid=CheckTimestamp(pathId, lastModif); + valid=CheckTimestamp(pathId, lastModif, refdb); } } else { - std::string parentId=IsIndexed(par); + std::string parentId=IsIndexed(par,refdb); //Case: Parent is not in database if(parentId.compare("")==0) { - AddFile(par,lastModif,lastRead); - parentId=IsIndexed(par); + AddFile(par,lastModif,lastRead,refdb); + parentId=IsIndexed(par,refdb); } //Case path is not in database if(pathId.compare("")==0) { - AddFile(parentId,pat,lastModif,lastRead); + AddFile(parentId,pat,lastModif,lastRead,refdb); valid=true; } //Parent and path are in the database else { SetAttribute("PARENT_ID",parentId,"ID", pathId); - valid=CheckTimestamp(pathId, lastModif); + valid=CheckTimestamp(pathId, lastModif, refdb); } } return valid; @@ -253,11 +253,11 @@ namespace creaImageIO //===================================================================== - void TimestampDatabaseHandler::AddFile(const std::string& path, const time_t lastModif, const time_t lastRead) + void TimestampDatabaseHandler::AddFile(const std::string& path, const time_t lastModif, const time_t lastRead, const std::string& refdb) { std::stringstream out; - out<<"INSERT INTO FILES (PARENT_ID,PATH,LastModified,LastRead) VALUES(0,'"<GetNumberOfChildren(); if(n>0) @@ -331,26 +332,26 @@ namespace creaImageIO std::vector::iterator it; for(it=children.begin();it!=children.end();++it) { - RemoveNode(searchAtt,(*it)); + RemoveNode(searchAtt,(*it),refdb); } } else if(node->GetLevel()==3) { - RemoveFile(searchAtt,node->GetAttribute("FullFileName")); + RemoveFile(searchAtt,node->GetAttribute("FullFileName"),refdb); } else { - DBRemove("TopLevelNodeId",node->GetAttribute("ID")); + DBRemove("TopLevelNodeId",node->GetAttribute("ID"),refdb); } } //===================================================================== - void TimestampDatabaseHandler::RemoveFile(const std::string& searchAtt, const std::string& searchVal) + void TimestampDatabaseHandler::RemoveFile(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb ) { std::stringstream result; - std::string sel="SELECT PARENT_ID FROM FILES WHERE "+searchAtt+"='"+searchVal+"'"; + std::string sel="SELECT PARENT_ID FROM FILES WHERE "+searchAtt+"='"+searchVal+"' AND REFERENCEDDB='"+refdb+"';"; CppSQLite3Query q; QUERYTIMESTAMPDB(sel,q); @@ -363,7 +364,7 @@ namespace creaImageIO } q.nextRow(); } - DBRemove(searchAtt,searchVal); + DBRemove(searchAtt,searchVal,refdb); int nChildren=0; sel="SELECT ID FROM FILES WHERE PARENT_ID='"+result.str()+"'"; @@ -378,27 +379,27 @@ namespace creaImageIO { if(!result.str().compare("0")) { - RemoveFile("ID",result.str()); + RemoveFile("ID",result.str(),refdb); } else { - DBRemove("ID",result.str()); + DBRemove("ID",result.str(),refdb); } } } //===================================================================== - void TimestampDatabaseHandler::DBRemove(const std::string& searchAtt, const std::string& searchVal) + void TimestampDatabaseHandler::DBRemove(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb) { - std::string query = "DELETE FROM FILES WHERE "+searchAtt+"='"+ searchVal + "';"; + std::string query = "DELETE FROM FILES WHERE "+searchAtt+"='"+ searchVal + "' AND REFERENCEDDB='"+refdb+"';"; UPDATETIMESTAMPDB(query); } //===================================================================== - bool TimestampDatabaseHandler::CheckTimestamp(const std::string pathId, const time_t lastModif) + bool TimestampDatabaseHandler::CheckTimestamp(const std::string pathId, const time_t lastModif, const std::string& refdb) { - std::string sel="SELECT LastModified FROM FILES WHERE ID='"+pathId+"';"; + std::string sel="SELECT LastModified FROM FILES WHERE ID='"+pathId+"' AND REFERENCEDDB='"+refdb+"';"; CppSQLite3Query q; QUERYTIMESTAMPDB(sel,q); double timestamp; diff --git a/src2/creaImageIOTimestampDatabaseHandler.h b/src2/creaImageIOTimestampDatabaseHandler.h index 2a6d78e..4727fe3 100644 --- a/src2/creaImageIOTimestampDatabaseHandler.h +++ b/src2/creaImageIOTimestampDatabaseHandler.h @@ -45,30 +45,31 @@ namespace creaImageIO //==================================================================== //==================================================================== ///Returns the id of the path if it's indexed, blank otherwise - std::string IsIndexed(const std::string& path); + std::string IsIndexed(const std::string& path, const std::string& refdb); ///Sets the current path's parent bool AddDirectory(const std::string& parent, const std::string& path, const time_t lastModif, - const time_t lastRead); + const time_t lastRead, + const std::string& refdb); ///Adds a new file to the database without a parent - void AddFile(const std::string& path, const time_t lastModif, const time_t lastRead); + void AddFile(const std::string& path, const time_t lastModif, const time_t lastRead, const std::string& refdb); ///Adds a new file to the database with a parent - void AddFile(const std::string& parentId,const std::string& path, const time_t lastModif, const time_t lastRead); + void AddFile(const std::string& parentId,const std::string& path, const time_t lastModif, const time_t lastRead, const std::string& refdb); ///Sets the attribute to the value passed as parameter where the searchParameter is searchValue void SetAttribute(const std::string& attName, const std::string& attValue, const std::string& searchParam, const std::string& searchValue); ///Removes the given node - void RemoveNode(const std::string& searchAtt, const tree::Node* node); + void RemoveNode(const std::string& searchAtt, const tree::Node* node, const std::string& refdb); ///Removes the filename with the given pathname - void RemoveFile(const std::string& searchAtt, const std::string& searchVal); + void RemoveFile(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb); ///Cleans the path name - void CleanName(std::string& str) const; + void CleanPath(std::string& str) const; ///Checks the timestamp in the database and compares it with the given one. //If there is a difference, it will return false, otherwise it will return true. - bool CheckTimestamp(const std::string pathId, const time_t lastModif); + bool CheckTimestamp(const std::string pathId, const time_t lastModif, const std::string& refdb); //==================================================================== @@ -85,7 +86,7 @@ namespace creaImageIO //====================================================================== //====================================================================== // Removes a file from the database - void DBRemove(const std::string& searchAtt, const std::string& searchVal); + void DBRemove(const std::string& searchAtt, const std::string& searchVal, const std::string& refdb); private: /// The DB diff --git a/src2/creaImageIOTreeHandlerImageAdder.cpp b/src2/creaImageIOTreeHandlerImageAdder.cpp index 22c727b..2d6ab3a 100644 --- a/src2/creaImageIOTreeHandlerImageAdder.cpp +++ b/src2/creaImageIOTreeHandlerImageAdder.cpp @@ -50,16 +50,16 @@ namespace creaImageIO std::vector::const_iterator i; for (i=filenames.begin();i!=filenames.end();++i) { - mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0)); + mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0),mCurrentDB); mProgress.IncNumberScannedFiles(); if (IsHandledFile(*i)) { mProgress.IncNumberHandledFiles(); - mSynchronizer->InsertAddOp((*i),"0","1"); - std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i)); + mSynchronizer->InsertAddOp((*i),"0","1",mCurrentDB); + std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",(*i),mCurrentDB); std::stringstream removedOn; removedOn<InsertIgnoreFile(addKey,(*i),"0",removedOn.str()); + mSynchronizer->InsertIgnoreFile(addKey,(*i),"0",removedOn.str(),mCurrentDB); AddFile(*i); } mProgressSignal(mProgress); @@ -77,13 +77,13 @@ namespace creaImageIO std::stringstream rec; rec<InsertAddOp(directory,rec.str(),"0"); - std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory); + mSynchronizer->InsertAddOp(directory,rec.str(),"0",mCurrentDB); + std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","ADD_OPS","PATH",directory,mCurrentDB); AddDirectoryRecursor( directory, recurse, addKey ); int nFiles=GetProgress().GetNumberAddedFiles(); files<SetAttribute("FILES_ADDED","ADD_OPS",files.str(),"ADD_KEY",addKey); + mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",files.str(),"ADD_KEY",addKey,mCurrentDB); GimmickDebugMessage(3,mProgress<GetAttribute("FullFileName"); //Gets the add key - std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path); + std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB); //Gets the number of files added - int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey)).c_str()); + int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str()); files=files-1; std::stringstream out; out<SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey); + mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB); //Sets the file as removed - mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH",path); + mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB); } } @@ -144,16 +144,16 @@ namespace creaImageIO { std::string path=(*it)->GetAttribute("FullFileName"); //Gets the add key - std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path); + std::string addKey=mSynchronizer->GetAttribute("ADD_KEY","IGNORED_FILES","PATH",path,mCurrentDB); //Gets the number of files added - int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey)).c_str()); + int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",addKey,mCurrentDB)).c_str()); files=files-1; std::stringstream out; out<SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey); + mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",addKey,mCurrentDB); //Sets the file as removed - mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH",path); + mSynchronizer->SetAttribute("REMOVE","IGNORED_FILES","1","PATH = '"+path+"' AND ADD_KEY",addKey,mCurrentDB); } } @@ -186,7 +186,7 @@ namespace creaImageIO else { std::string parent_id; - bool valid=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0)); + bool valid=mTimestampHandler->AddDirectory(dirpath, itr->string(), lastModif, time(0),mCurrentDB); if(valid) { mProgress.IncNumberScannedFiles(); @@ -198,7 +198,7 @@ namespace creaImageIO mTimestampHandler->SetAttribute("TopLevelNodeId",parent_id,"PATH",itr->string()); std::stringstream removedOn; removedOn<InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str()); + mSynchronizer->InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str(),mCurrentDB); } mProgressSignal(mProgress); if (mProgress.GetStop()) @@ -279,7 +279,7 @@ namespace creaImageIO std::vector::iterator iter; //Gets the list of added files - mSynchronizer->GetFileList(fileList); + mSynchronizer->GetFileList(fileList,mCurrentDB); std::vector::iterator i; //Actions to take if the user doesn't want to repair @@ -348,19 +348,19 @@ namespace creaImageIO //For the new files, add them for (i=newFiles.begin();i!=newFiles.end();++i) { - mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0)); + mTimestampHandler->AddFile((*i), fs::last_write_time(*i), time(0),mCurrentDB); if (IsHandledFile(*i)) { std::stringstream removedOn; removedOn<InsertIgnoreFile((*iter).key,(*i),"0",removedOn.str()); + mSynchronizer->InsertIgnoreFile((*iter).key,(*i),"0",removedOn.str(),mCurrentDB); //Gets the number of files added - int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",(*iter).key)).c_str()); + int files=atoi((mSynchronizer->GetAttribute("FILES_ADDED","ADD_OPS","ADD_KEY",(*iter).key,mCurrentDB)).c_str()); files=files+1; std::stringstream out; out<SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",(*iter).key); + mSynchronizer->SetAttribute("FILES_ADDED","ADD_OPS",out.str(),"ADD_KEY",(*iter).key,mCurrentDB); AddFile(*i); } } diff --git a/src2/creaImageIOTreeHandlerImageAdder.h b/src2/creaImageIOTreeHandlerImageAdder.h index 6065491..8311fdd 100644 --- a/src2/creaImageIOTreeHandlerImageAdder.h +++ b/src2/creaImageIOTreeHandlerImageAdder.h @@ -37,6 +37,8 @@ namespace creaImageIO void SetTimestampHandler(TimestampDatabaseHandler* tdh) { mTimestampHandler = tdh;} /// Sets the synchronizer void SetSynchronizer(Synchronizer* s){mSynchronizer=s;} + /// Sets the synchronizer + void SetCurrentDatabase(std::string cur){mCurrentDB=cur;} //==================================================================== //==================================================================== @@ -147,6 +149,7 @@ namespace creaImageIO TimestampDatabaseHandler* mTimestampHandler; Synchronizer* mSynchronizer; ImageReader mReader; + std::string mCurrentDB; Progress mProgress; ProgressSignalType mProgressSignal; diff --git a/src2/creaImageIOWxGimmickView.cpp b/src2/creaImageIOWxGimmickView.cpp index 646782c..4381a6e 100644 --- a/src2/creaImageIOWxGimmickView.cpp +++ b/src2/creaImageIOWxGimmickView.cpp @@ -607,8 +607,8 @@ namespace creaImageIO //================================================= void WxGimmickView::AddIgnoreFile(tree::Node* toRemove) { - mGimmick->RemoveFile("Local database",toRemove); - GetTreeViewMap()["Local database"]->UpdateLevel(1); + mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove); + GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1); } //================================================= @@ -635,9 +635,11 @@ namespace creaImageIO bool checkAttributes=false; if(sel==2 || sel==3){repair=true;} if(sel==1 || sel==3){checkAttributes=true;} - std::string mess=mGimmick->Synchronize(repair, checkAttributes); + std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes); wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this); - GetTreeViewMap()["Local database"]->UpdateLevel(1); + if(sel==2 || sel==3){ + GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1); + } } }