SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "DatabaseManager.h" 00003 #include "NetworkDaoThread.h" 00004 #include "ArchiveDao.h" 00005 #include "AnalysisDao.h" 00006 #include "SpikeStreamException.h" 00007 using namespace spikestream; 00008 00009 //Qt includes 00010 #include <QDebug> 00011 00012 00014 DatabaseManager::DatabaseManager(const DBInfo& networkDBInfo, const DBInfo& archiveDBInfo, const DBInfo& analysisDBInfo) : SpikeStreamThread() { 00015 this->networkDBInfo = networkDBInfo; 00016 this->archiveDBInfo = archiveDBInfo; 00017 this->analysisDBInfo = analysisDBInfo; 00018 } 00019 00020 00022 DatabaseManager::~DatabaseManager(){ 00023 } 00024 00025 00026 /*----------------------------------------------------------*/ 00027 /*----- PUBLIC METHODS -----*/ 00028 /*----------------------------------------------------------*/ 00029 00031 void DatabaseManager::startClearDatabases(){ 00032 taskID = CLEAR_DATABASES_TASK; 00033 start(); 00034 } 00035 00036 00038 void DatabaseManager::run(){ 00039 clearError(); 00040 00041 //Create databases within the thread 00042 NetworkDaoThread networkDaoThread(networkDBInfo); 00043 ArchiveDao archiveDao(archiveDBInfo); 00044 AnalysisDao analysisDao(analysisDBInfo); 00045 00046 try{ 00047 switch(taskID){ 00048 case CLEAR_DATABASES_TASK:{ 00049 analysisDao.deleteAllAnalyses(); 00050 archiveDao.deleteAllArchives(); 00051 QList<NetworkInfo> netInfoList = networkDaoThread.getNetworksInfo(); 00052 foreach(NetworkInfo netInfo, netInfoList){ 00053 networkDaoThread.startDeleteNetwork(netInfo.getID()); 00054 networkDaoThread.wait(); 00055 } 00056 } 00057 break; 00058 default: 00059 setError("TaskID not recognized."); 00060 } 00061 } 00062 catch(SpikeStreamException& ex){ 00063 setError(ex.getMessage()); 00064 } 00065 catch(...){ 00066 setError("DatabaseManager: unknown exception."); 00067 } 00068 } 00069 00070 00071 /*----------------------------------------------------------*/ 00072 /*----- PRIVATE METHODS -----*/ 00073 /*----------------------------------------------------------*/ 00074 00075 00076