00001
00002
00003
00004
00005
00006
00007 #include "TableRowTranslator.h"
00008
00009 using namespace LcgInfo;
00010 using namespace std;
00011
00012
00013
00014 TableRowTranslator::TableRowTranslator():mMap(){
00015 cerr << "WARNING!!: No mapfile provided!";
00016 cerr << "Using \"./mappingGlueRGMA\" as default one" << endl;
00017 try{
00018 mMap->populate_from_config("./mappingGlueRGMA");
00019 }catch(LcgConfigBuffer::CBException& e){
00020 string msg="No valid mapping file. Aborting.";
00021 msg += "\nUnderlying LcgConfigBuffer::CBException message: " + e.what() + " +line: ";
00022 msg += int2str(e.get_line()) + " +file: " + e.get_file();
00023 throw QueryTranslationException(msg,__FILE__,__LINE__);
00024 }
00025 mOurMap=true;
00026 }
00027
00028
00029 TableRowTranslator::TableRowTranslator(string const & pMapFile):mMap(){
00030 try{
00031 mMap->populate_from_config(pMapFile);
00032 }catch(LcgConfigBuffer::CBException& e){
00033 string msg="No valid mapping file. Aborting.";
00034 msg += "\nUnderlying LcgConfigBuffer::CBException message: " + e.what() + " +line: ";
00035 msg += int2str(e.get_line()) + " +file: " + e.get_file();
00036 throw QueryTranslationException(msg,__FILE__,__LINE__);
00037 }
00038 mOurMap=true;
00039 }
00040
00041
00042 TableRowTranslator::TableRowTranslator(LcgConfigBuffer::ConfigBuffer & pMap):mMap(&pMap){
00043 mOurMap=false;
00044 }
00045
00046
00047 TableRowTranslator::~TableRowTranslator(){
00048 if(mOurMap){
00049 delete mMap;
00050 mMap=0;
00051 }
00052 }
00053
00054
00055 string TableRowTranslator::mapTableRow(string const & pTableRow){
00056 string msg;
00057 string mappedTR;
00058 unsigned int posPred=0;
00059 unsigned int posEnd=0;
00060
00061 mPredicates.clear();
00062
00063
00064 mappedTR=mMap->get_attribute_value(pTableRow);
00065
00066
00067 bool found=false;
00068 while(!found){
00069 posPred=mappedTR.find('{',posPred);
00070 if(posPred==string::npos) return mappedTR;
00071
00072
00073 int count=0;
00074 for(int i=posPred-1; mappedTR.at(i)=='\\'; i--, count++);
00075 if(count>0){
00076 mappedTR.erase(posPred-count/2,count/2);
00077 posPred-=count/2;
00078 if(count%2==0) found=true;
00079 else
00080 mappedTR.erase(posPred-1,1);
00081 }
00082 else found=true;
00083 }
00084
00085 if(found){
00086 vector<string> tokenArray;
00087 posEnd=mappedTR.find('}',posPred);
00088 if(posEnd!=string::npos)
00089 tokenizeStr(mappedTR.substr(posPred+1, posEnd-posPred-1), tokenArray,";");
00090 else
00091 tokenizeStr(mappedTR.substr(posPred+1), tokenArray,";");
00092 for(vector<string>::iterator i=tokenArray.begin(); i!=tokenArray.end(); i++){
00093 delSurroundingChars(*i);
00094 if(!(*i).empty()) mPredicates.push_back(*i);
00095 }
00096 }
00097 return mappedTR.substr(0,posPred);
00098 }
00099
00100
00101 bool TableRowTranslator::thereIsStructChange(){
00102 return !(mPredicates.empty());
00103 }
00104
00105
00106 vector<string>::iterator TableRowTranslator::getPredicatesBegin(){
00107 return mPredicates.begin();
00108 }
00109
00110 vector<string>::iterator TableRowTranslator::getPredicatesEnd(){
00111 return mPredicates.end();
00112 }