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

RepositoryDispatcher.h

Go to the documentation of this file.
00001 #ifndef Impala_Persistency_RepositoryDispatcher_h
00002 #define Impala_Persistency_RepositoryDispatcher_h
00003 
00004 #include "Basis/ILog.h"
00005 
00006 namespace Impala
00007 {
00008 namespace Persistency
00009 {
00010 
00011 
00015 template<class LocatorType, class DataType,
00016          class RepositoryInFileType, class RepositoryInMonetType>
00017 class RepositoryDispatcher
00018 {
00019 public:
00020 
00021     RepositoryDispatcher()
00022     {
00023     }
00024 
00025     bool
00026     Exists(const LocatorType& loc)
00027     {
00028         String protocol = loc.GetProtocol();
00029         if ((protocol == "file") || (protocol == "dataServer"))
00030         {
00031             return mRepFile.Exists(loc);
00032         }
00033         /*
00034         if (protocol == "mapi")
00035         {
00036             return mRepMonet.Get(loc);
00037         }
00038         */
00039         ILOG_ERROR("Exists: unknown protocol: [" << loc.GetProtocol() << "] in "
00040                    << loc);
00041         return false;
00042     }
00043 
00044     DataType*
00045     Get(const LocatorType& loc)
00046     {
00047         String protocol = loc.GetProtocol();
00048         if ((protocol == "file") || (protocol == "dataServer"))
00049         {
00050             return mRepFile.Get(loc);
00051         }
00052         if (protocol == "mapi")
00053         {
00054             return mRepMonet.Get(loc);
00055         }
00056         ILOG_ERROR("Get: unknown protocol: [" << loc.GetProtocol() << "] in "
00057                    << loc);
00058         return 0;
00059     }
00060 
00061     void
00062     Add(const LocatorType& loc, DataType* data)
00063     {
00064         String protocol = loc.GetProtocol();
00065         if ((protocol == "file") || (protocol == "dataServer"))
00066         {
00067             return mRepFile.Add(loc, data);
00068         }
00069         if (protocol == "mapi")
00070         {
00071             return mRepMonet.Add(loc, data);
00072         }
00073         ILOG_ERROR("Add: unknown protocol: [" << loc.GetProtocol() << "] in "
00074                    << loc);
00075     }
00076 
00077     void
00078     Delete(const LocatorType& loc)
00079     {
00080         String protocol = loc.GetProtocol();
00081         if ((protocol == "file") || (protocol == "dataServer"))
00082         {
00083             return mRepFile.Delete(loc);
00084         }
00085         /*
00086         if (protocol == "mapi")
00087         {
00088             return mRepMonet.Delete(loc);
00089         }
00090         */
00091         ILOG_ERROR("Delete: unknown protocol: [" << loc.GetProtocol() << "] in "
00092                    << loc);
00093     }
00094 
00095     void
00096     Sync(const LocatorType& loc, DataType* data)
00097     {
00098         if (!Exists(loc)) // Todo: add a check in timestamp etc.
00099             Add(loc, data);
00100     }
00101 
00102     void
00103     Replace(const LocatorType& loc, DataType* data)
00104     {
00105         Delete(loc);
00106         Add(loc, data);
00107     }
00108 
00109 protected:
00110 
00111     RepositoryInFileType  mRepFile;
00112     RepositoryInMonetType mRepMonet;
00113 
00114     ILOG_VAR_DEC;
00115 };
00116 
00117 ILOG_VAR_INIT_TEMPL_4(RepositoryDispatcher, LocatorType, DataType,
00118                       RepositoryInFileType, RepositoryInMonetType,
00119                       Impala.Persistency);
00120 
00121 } // namespace Persistency
00122 } // namespace Impala
00123 
00124 #endif

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