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

RepositoryInMonetDB.h

Go to the documentation of this file.
00001 #ifndef Impala_Persistency_RepositoryInMonetDB_h
00002 #define Impala_Persistency_RepositoryInMonetDB_h
00003 
00004 #include "Link/Monet/Connection.h"
00005 #include "Basis/StringList.h"
00006 #include "Persistency/Locator.h"
00007 #include "Util/SimpleMap.h"
00008 
00009 namespace Impala
00010 {
00011 namespace Persistency
00012 {
00013 
00014 
00015 class RepositoryInMonetDB
00016 {
00017 public:
00018     typedef Link::Monet::Connection Connection;
00019 
00020     static RepositoryInMonetDB&
00021     GetInstance()
00022     {
00023         static RepositoryInMonetDB theRepositoryInMonetDB;
00024         return theRepositoryInMonetDB;
00025     }
00026 
00027     Connection*
00028     GetConnection(const Locator& loc)
00029     {
00030         Connection* conn = 0;
00031         if (mMap.Get(loc.ToString(), conn))
00032             return conn;
00033 
00034         StringList sl(loc.GetHost(), ':');
00035         std::cout << "list size = " << sl.size() << std::endl;
00036         StringListCI it = sl.begin();
00037         if (it == sl.end())
00038         {
00039             ILOG_ERROR("Missing host specification for mapi");
00040             return 0;
00041         }
00042 
00043         String host = *it++;
00044         if (it == sl.end())
00045         {
00046             ILOG_ERROR("Missing port specification for mapi");
00047             return 0;
00048         }
00049 
00050         int port = atol(*it++);
00051         String setName = loc.GetDataSet();
00052         String db = (it == sl.end()) ? FileNameBase(setName) : *it;
00053         ILOG_INFO("Mapi connection to " << host << ":" << port << ":" << db);
00054         conn = new Connection(host, port, db);
00055         if (!conn->Valid())
00056         {
00057             ILOG_ERROR("Failed to set up connection to " << host << ":" <<
00058                        port << ":" << db);
00059             delete conn;
00060             return 0;
00061         }
00062 
00063         mMap.Add(loc.ToString(), conn);
00064         return conn;
00065     }
00066 
00067 private:
00068 
00069     RepositoryInMonetDB()
00070     {
00071     }
00072 
00073     Util::SimpleMapDelete<String, Connection*> mMap;
00074 
00075     ILOG_VAR_DEC;
00076 
00077 };
00078 
00079 ILOG_VAR_INIT(RepositoryInMonetDB, Impala.Persistency);
00080 
00081 } // namespace Persistency
00082 } // namespace Impala
00083 
00084 #endif

Generated on Fri Mar 19 09:31:44 2010 for ImpalaSrc by  doxygen 1.5.1