00001 #ifndef Impala_Persistency_RepositoryInFileSystem_h
00002 #define Impala_Persistency_RepositoryInFileSystem_h
00003
00004 #include "Persistency/File.h"
00005 #include "Persistency/FileLocator.h"
00006 #include "Util/SimpleMap.h"
00007 #include "Core/Feature/FeatureDefinition.h"
00008
00009 namespace Impala
00010 {
00011 namespace Persistency
00012 {
00013
00014
00017 class RepositoryInFileSystem
00018 {
00019 public:
00020
00021 static RepositoryInFileSystem&
00022 GetInstance()
00023 {
00024 static RepositoryInFileSystem theRepositoryInFileSystem;
00025 return theRepositoryInFileSystem;
00026 }
00027
00028 File
00029 GetFile(const Locator& loc, CString fileName, bool toWrite, bool silent)
00030 {
00031 FileSystem* fs = GetFS(loc);
00032 String path = fs->GetFilePath(loc.GetDataSet(), fileName, toWrite,
00033 silent);
00034 return File(path, fs);
00035 }
00036
00037 File
00038 GetFile(const Locator& loc, CString dir, CString file, bool toWrite,
00039 bool silent)
00040 {
00041 FileSystem* fs = GetFS(loc);
00042 if (toWrite)
00043 fs->MakeDir(dir);
00044 String path = fs->GetFilePath(dir, file, toWrite, silent);
00045 return File(path, fs);
00046 }
00047
00048 File
00049 GetFile(const FileLocator& loc, bool toWrite, bool silent)
00050 {
00051 FileSystem* fs = GetFS(loc);
00052 String path = fs->GetFilePath("", loc.GetName(), toWrite, silent);
00053 return File(path, fs);
00054 }
00055
00056 private:
00057
00058 RepositoryInFileSystem()
00059 {
00060 }
00061
00062 FileSystem*
00063 GetFS(const Locator& loc)
00064 {
00065 FileSystem* fs = 0;
00066 if (mMap.Get(loc.ToString(), fs))
00067 return fs;
00068
00069 String setName = loc.GetDataSet();
00070 String data("");
00071 if ((setName == "dot") || (setName == "."))
00072 {
00073 data = ".";
00074 ILOG_INFO_ONCE("'data' option for " << setName <<
00075 " has been set to: " << data);
00076 }
00077 else if (setName == "abs")
00078 {
00079 data = "";
00080 ILOG_INFO_ONCE("'data' option for " << setName <<
00081 " has been set to: <empty> (i.e. is absolute)");
00082 }
00083 else if (setName == "config")
00084 {
00085 char* ptr = getenv("IMPALAROOT");
00086 data = (ptr) ? String(ptr)+"/src/" : ".";
00087 ILOG_INFO_ONCE("'data' option for " << setName <<
00088 " has been set to: " << data);
00089 }
00090 else
00091 {
00092 CmdOptions& options = CmdOptions::GetInstance();
00093 data = StringReplaceAll(options.GetString("data"), ":", ";", false);
00094 String additionalData = options.GetString("data::"+setName, "");
00095 if (additionalData.empty() && !setName.empty())
00096 additionalData = "../" + FileNameBase(setName);
00097 if (!additionalData.empty())
00098 {
00099 data = additionalData + ";" + data;
00100 ILOG_INFO_ONCE("'data' option for " << setName <<
00101 " has been extended: " << data);
00102 }
00103 }
00104
00105 fs = new FileSystem(data, loc.GetHost());
00106 mMap.Add(loc.ToString(), fs);
00107 return fs;
00108 }
00109
00110 Util::SimpleMapDelete<String, FileSystem*> mMap;
00111
00112 ILOG_VAR_DEC;
00113
00114 };
00115
00116 ILOG_VAR_INIT(RepositoryInFileSystem, Impala.Persistency);
00117
00118 }
00119 }
00120
00121 #endif