00001
00002
00003
00004
00005
00006 #include "SQLtoSQLQuerier.h"
00007
00008 using namespace std;
00009 using namespace LcgInfo;
00010
00011 typedef vector<vector<string> >::iterator matrStrIt;
00012 typedef vector<string>::iterator vecStrIt;
00013 typedef string::size_type strPos;
00014
00015
00019 extern "C" {
00020 Querier* SQLtoSQLQuerier_create(){
00021 return new SQLtoSQLQuerier();
00022 }
00023 }
00024
00028 extern "C" {
00029 void SQLtoSQLQuerier_destroy(Querier *p){
00030 delete p;
00031 }
00032 }
00033
00034
00035
00036 SQLtoSQLQuerier::SQLtoSQLQuerier()
00037 :mConf(0),mTranslator(0),mSql(0){
00038 }
00039
00040 SQLtoSQLQuerier::~SQLtoSQLQuerier(){
00041 }
00042
00043 void SQLtoSQLQuerier::setConfig(LcgConfigBuffer::ConfigBuffer & pConf){
00044 mConf=&pConf;
00045 mSql=new InfoFromLDAP();
00046 mSql->setConfig(pConf);
00047 mMap=new LcgConfigBuffer::ConfigBuffer();
00048
00049
00050 try{
00051 string mappingfile=mConf->get_attribute_value("SCHEMA_MAPPING_FILE");
00052 mMap->populate_from_config(mappingfile);
00053 }catch(LcgConfigBuffer::CBException& e){
00054 string msg="No valid mapping file. aborting.";
00055 msg += "\nUnderlying CBException message: " + e.what() + " +line: ";
00056 msg += int2str(e.get_line()) + " +file: " + e.get_file();
00057 throw QueryTranslationException(msg,__FILE__,__LINE__);
00058 }
00059 mTranslator=new SQLtoSQLQueryTranslator(*mMap);
00060 }
00061
00062 vector<vector<string> > SQLtoSQLQuerier::query(string const & pcanonical){
00063
00064 vector<vector<string> > results;
00065
00066 try{
00067 string input=pcanonical;
00068 vector<string> translation=mTranslator->translateQuery(input);
00069
00070
00071
00072 cout << "asking: " << translation.front() << endl;
00073
00074
00075
00076 string filter=translation.front();
00077 vector<string> attribs;
00078 attribs.push_back("glueceuniqueid");
00079 attribs.push_back("gluecename");
00080 try{
00081 results=mSql->query(filter,attribs);
00082 }catch(LcgConfigBuffer::CBException e){
00083 string msg="Error while querying the ldap interface. aborting.";
00084 msg += "\nUnderlying CBException message: " + e.what() + " +line: ";
00085 msg += int2str(e.get_line()) + " +file: " + e.get_file();
00086 throw LcgInfoException(msg,__FILE__,__LINE__);
00087 }
00088
00089
00090
00091
00092 cout << "Getting: ";
00093 for(matrStrIt r=results.begin(); r!=results.end(); r++){
00094 cout << "\n ";
00095 for(vecStrIt k=(*r).begin(); k!=(*r).end(); k++)
00096 cout << *k << " ";
00097 }
00098 cout << endl;
00099 cout << " ############################################## ";
00100
00101
00102 return results;
00103
00104 }catch(QueryTranslationException &e){
00105 cerr << e.what() << " +line: " << e.get_line() << " +file: " << e.get_file() << endl;;
00106 return results;
00107 }
00108
00109 }