Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

AnnotationTableSetRepository.h

Go to the documentation of this file.
00001 #ifndef Impala_Persistency_AnnotationTableSetRepository_h
00002 #define Impala_Persistency_AnnotationTableSetRepository_h
00003 
00004 #include "Persistency/RepositoryDispatcher.h"
00005 #include "Persistency/RepositoryStub.h"
00006 #include "Core/Table/AnnotationTableSet.h"
00007 #include "Persistency/AnnotationTableSetLocator.h"
00008 #include "Persistency/KeywordListRepository.h"
00009 #include "Persistency/AnnotationTableRepository.h"
00010 
00011 namespace Impala
00012 {
00013 namespace Persistency
00014 {
00015 
00016 
00017 class AnnotationTableSetRepository
00018     : public RepositoryDispatcher<AnnotationTableSetLocator,
00019                                   Core::Table::AnnotationTableSet,
00020                                   RepositoryStub,
00021                                   RepositoryStub>
00022 {
00023 public:
00024 
00025     typedef Core::Table::AnnotationTableSet AnnotationTableSet;
00026     typedef Core::Table::AnnotationTable AnnotationTable;
00027     typedef Core::Table::KeywordList KeywordList;
00028 
00029     bool
00030     Exists(const AnnotationTableSetLocator& loc)
00031     {
00032         KeywordListLocator keyListLoc(loc, loc.GetConceptSet());
00033         if (!KeywordListRepository().Exists(keyListLoc))
00034             return false;
00035         KeywordList keyList = *(KeywordListRepository().Get(keyListLoc));
00036 
00037         int nrFound = 0;
00038         AnnotationTableLocator tabLoc(loc, loc.GetQuidClass(),
00039                                       loc.GetConceptSet(), "dummy");
00040         for (int i=0 ; i<keyList.size() ; i++)
00041         {
00042             tabLoc.SetKeyword(keyList[i]);
00043             if (AnnotationTableRepository().Exists(tabLoc))
00044                 nrFound++;
00045         }
00046         if (nrFound == 0)
00047             return false;
00048         return true;
00049     }
00050 
00051     AnnotationTableSet*
00052     Get(const AnnotationTableSetLocator& loc)
00053     {
00054         KeywordListLocator keyListLoc(loc, loc.GetConceptSet());
00055         KeywordList keyList = *(KeywordListRepository().Get(keyListLoc));
00056         if (keyList.size() == 0)
00057         {
00058             ILOG_ERROR("Could find keywords");
00059             return 0;
00060         }
00061 
00062         AnnotationTableSet* res = new AnnotationTableSet();
00063         int nrFound = 0;
00064         AnnotationTableLocator tabLoc(loc, loc.GetQuidClass(),
00065                                       loc.GetConceptSet(), "dummy");
00066         for (int i=0 ; i<keyList.size() ; i++)
00067         {
00068             tabLoc.SetKeyword(keyList[i]);
00069             AnnotationTable* table = 0;
00070             if (AnnotationTableRepository().Exists(tabLoc))
00071                 table = AnnotationTableRepository().Get(tabLoc);
00072             else
00073                 ILOG_WARN("Table for " << keyList[i] << " doesn't exist");
00074             if (table)
00075                 nrFound++;
00076             else
00077                 table = new AnnotationTable(keyList[i], 0);
00078             res->Add(table);
00079         }
00080         if (nrFound == 0)
00081             ILOG_ERROR("No tables found");
00082         return res;
00083     }
00084 
00085     void
00086     Add(const AnnotationTableSetLocator& loc, AnnotationTableSet* tSet)
00087     {
00088         KeywordListLocator keyListLoc(loc, loc.GetConceptSet());
00089         if (!KeywordListRepository().Exists(keyListLoc))
00090         {
00091             KeywordList keys = tSet->GetLabels();
00092             KeywordListRepository().Add(keyListLoc, &keys);
00093         }
00094         for (int i=0 ; i<tSet->Size() ; i++)
00095         {
00096             AnnotationTable* tab = tSet->GetTable(i);
00097             if (tab->Size() == 0)
00098                 continue;
00099             //int qClass = tab->GetQuidClass();
00100             int qClass = loc.GetQuidClass();
00101             if (qClass == QUID_CLASS_UNKNOWN)
00102                 qClass = tab->GetQuidClass();
00103             if (qClass != tab->GetQuidClass())
00104                 ILOG_WARN("Locator and Table have different QuidClass");
00105             AnnotationTableLocator tabLoc(loc, qClass, loc.GetConceptSet(),
00106                                           tab->GetLabel());
00107             AnnotationTableRepository().Add(tabLoc, tab);
00108         }
00109     }
00110 
00111     void
00112     Delete(const AnnotationTableSetLocator& loc)
00113     {
00114         KeywordListLocator keyListLoc(loc, loc.GetConceptSet());
00115         if (!KeywordListRepository().Exists(keyListLoc))
00116             return;
00117 
00118         KeywordList keyList = *(KeywordListRepository().Get(keyListLoc));
00119         AnnotationTableLocator tabLoc(loc, loc.GetQuidClass(),
00120                                       loc.GetConceptSet(), "dummy");
00121         for (int i=0 ; i<keyList.size() ; i++)
00122         {
00123             tabLoc.SetKeyword(keyList[i]);
00124             AnnotationTableRepository().Delete(tabLoc);
00125         }
00126         KeywordListRepository().Delete(keyListLoc);
00127     }
00128 
00129     void
00130     Sync(const AnnotationTableSetLocator& loc, AnnotationTableSet* tSet)
00131     {
00132         if (!Exists(loc)) // Todo: add a check in timestamp etc.
00133             Add(loc, tSet);
00134     }
00135 
00136     void
00137     Replace(const AnnotationTableSetLocator& loc, AnnotationTableSet* tSet)
00138     {
00139         Delete(loc);
00140         Add(loc, tSet);
00141     }
00142 
00143 private:
00144 
00145     ILOG_VAR_DEC;
00146 
00147 };
00148 
00149 ILOG_VAR_INIT(AnnotationTableSetRepository, Impala.Persistency);
00150 
00151 } // namespace Persistency
00152 } // namespace Impala
00153 
00154 #endif

Generated on Thu Jan 13 09:05:01 2011 for ImpalaSrc by  doxygen 1.5.1