00001 #ifndef Impala_Persistency_KeywordListRepositoryInMonet_h
00002 #define Impala_Persistency_KeywordListRepositoryInMonet_h
00003
00004 #include "Persistency/RepositoryInMonetDB.h"
00005 #include "Persistency/RepositoryInFileSystem.h"
00006 #include "Core/Table/KeywordList.h"
00007 #include "Persistency/KeywordListLocator.h"
00008
00009 namespace Impala
00010 {
00011 namespace Persistency
00012 {
00013
00014
00015 class KeywordListRepositoryInMonet
00016 {
00017 public:
00018
00019 typedef Link::Monet::Connection Connection;
00020 typedef Core::Table::KeywordList KeywordList;
00021
00022 KeywordListRepositoryInMonet()
00023 {
00024 }
00025
00026 KeywordList*
00027 Get(const KeywordListLocator& loc)
00028 {
00029 Connection* conn = RepMonet().GetConnection(loc);
00030
00031 String vidSetBase = FileNameBase(loc.GetDataSet());
00032 String conceptSetBase = FileNameBase(loc.GetConceptSet());
00033 String query =
00034 "select k.keyword_name \
00035 from keyword k, keyword_set ks, keyword_sets kss, video_sets vss \
00036 where vss.set_name = '" + vidSetBase + "' and \
00037 kss.video_sets_id = vss.video_sets_id and \
00038 kss.set_name = '" + conceptSetBase + "' and \
00039 ks.keyword_sets_id = kss.keyword_sets_id and \
00040 k.keyword_id = ks.keyword_id \
00041 order by k.keyword_id;";
00042
00043 KeywordList* concepts = new KeywordList();
00044 MapiHdl hdl = conn->QueryPartStart(query);
00045 if (hdl == 0)
00046 return concepts;
00047
00048 if (!conn->QueryPartFetchString(hdl, 0, *concepts))
00049 return concepts;
00050
00051 conn->QueryPartEnd(hdl);
00052
00053 return concepts;
00054 }
00055
00056 void
00057 Add(const KeywordListLocator& loc, KeywordList* keyList)
00058 {
00059 Connection* conn = RepMonet().GetConnection(loc);
00060
00061 String vidSetBase = FileNameBase(loc.GetDataSet());
00062 String conceptSetBase = FileNameBase(loc.GetConceptSet());
00063 for (int i=0 ; i<keyList->size() ; i++)
00064 {
00065 String q = "select i_add_keyword('" + vidSetBase + "', '" +
00066 conceptSetBase + "', '" + (*keyList)[i] + "');";
00067 ILOG_INFO("q = [" + q + "]");
00068 conn->Query(q, false, false);
00069 }
00070 }
00071
00072 private:
00073
00074 RepositoryInMonetDB&
00075 RepMonet()
00076 {
00077 return RepositoryInMonetDB::GetInstance();
00078 }
00079
00080 ILOG_VAR_DEC;
00081 };
00082
00083 ILOG_VAR_INIT(KeywordListRepositoryInMonet, Impala.Persistency);
00084
00085 }
00086 }
00087
00088 #endif