00001 #ifndef Impala_Persistency_AnnotationTableRepositoryInFile_h
00002 #define Impala_Persistency_AnnotationTableRepositoryInFile_h
00003
00004 #include "Persistency/RepositoryInFileSystem.h"
00005 #include "Core/Table/AnnotationTable.h"
00006 #include "Persistency/AnnotationTableLocator.h"
00007 #include "Core/Table/Write.h"
00008
00009 namespace Impala
00010 {
00011 namespace Persistency
00012 {
00013
00014
00015 class AnnotationTableRepositoryInFile
00016 {
00017 public:
00018
00019 typedef Core::Table::AnnotationTable AnnotationTable;
00020
00021 AnnotationTableRepositoryInFile()
00022 {
00023 }
00024
00025 bool
00026 Exists(const AnnotationTableLocator& loc)
00027 {
00028 String dir = GetDir(loc);
00029 File file = RepFS().GetFile(loc, dir, loc.GetKeyword() + ".tab",
00030 false, true);
00031 return file.Valid();
00032 }
00033
00034 AnnotationTable*
00035 Get(const AnnotationTableLocator& loc)
00036 {
00037 AnnotationTable* res = new AnnotationTable(loc.GetKeyword(), 0);
00038 String dir = GetDir(loc);
00039 File file = RepFS().GetFile(loc, dir, loc.GetKeyword() + ".tab",
00040 false, false);
00041 if (!file.Valid())
00042 return 0;
00043 Read(res, file);
00044 return res;
00045 }
00046
00047 void
00048 Add(const AnnotationTableLocator& loc, AnnotationTable* tab)
00049 {
00050 String dir = GetDir(loc);
00051 File file = RepFS().GetFile(loc, dir, loc.GetKeyword() + ".tab",
00052 true, false);
00053 Write(tab, file);
00054 }
00055
00056 void
00057 Delete(const AnnotationTableLocator& loc)
00058 {
00059 String dir = GetDir(loc);
00060 File file = RepFS().GetFile(loc, dir, loc.GetKeyword() + ".tab",
00061 true, true);
00062 file.Delete();
00063 }
00064
00065 private:
00066
00067 RepositoryInFileSystem&
00068 RepFS()
00069 {
00070 return RepositoryInFileSystem::GetInstance();
00071 }
00072
00073 String
00074 GetDir(const AnnotationTableLocator& loc)
00075 {
00076 String dir = "Annotations";
00077 dir = FileNameConcat(dir, loc.GetQuidClassString());
00078 dir = FileNameConcat(dir, loc.GetConceptSet());
00079 return dir;
00080 }
00081
00082 ILOG_VAR_DEC;
00083 };
00084
00085 ILOG_VAR_INIT(AnnotationTableRepositoryInFile, Impala.Persistency);
00086
00087 }
00088 }
00089
00090 #endif