CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondCore/ORA/src/TableRegister.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Exception.h"
00002 #include "TableRegister.h"
00003 // externals
00004 #include "RelationalAccess/IColumn.h"
00005 #include "RelationalAccess/ISchema.h"
00006 #include "RelationalAccess/ITable.h"
00007 #include "RelationalAccess/ITableDescription.h"
00008 
00009 ora::TableRegister::TableRegister( coral::ISchema& schema ):
00010   m_schema( schema ),m_init(false),m_register(),m_currentTable(0),m_currentColumns(0){
00011 }
00012 
00013 ora::TableRegister::~TableRegister(){
00014 }
00015 
00016 void ora::TableRegister::init(){
00017   if(!m_init){
00018     std::set<std::string> tableList = m_schema.listTables();
00019     for( std::set<std::string>::const_iterator iT = tableList.begin(); iT != tableList.end(); ++iT ){
00020       coral::ITable& table = m_schema.tableHandle( *iT );
00021       std::map<std::string,std::set<std::string> >::iterator iEntry =
00022         m_register.insert( std::make_pair( *iT, std::set<std::string>() ) ).first;
00023       int ncols = table.description().numberOfColumns();
00024       for(int i=0;i<ncols;i++){
00025         iEntry->second.insert( table.description().columnDescription( i ).name() );
00026       }
00027     }
00028     m_init = true;
00029   }
00030 }
00031 
00032 bool ora::TableRegister::checkTable(const std::string& tableName){
00033   init();
00034   if(!m_currentTable || (tableName!=*m_currentTable)){
00035     std::map<std::string, std::set<std::string> >::iterator iT = m_register.find( tableName );
00036     if(iT==m_register.end()) {
00037       m_currentTable = 0;
00038       m_currentColumns = 0;
00039       return false;
00040     }
00041     m_currentTable = &iT->first;
00042     m_currentColumns = &iT->second;
00043   }
00044   return true;
00045 }
00046 
00047 bool ora::TableRegister::checkColumn(const std::string& tableName,
00048                                      const std::string& columnName){
00049   init();
00050   if(!m_currentTable || (tableName!=*m_currentTable)){
00051     std::map<std::string, std::set<std::string> >::iterator iT = m_register.find( tableName );
00052     if(iT==m_register.end()) {
00053       m_currentTable = 0;
00054       m_currentColumns = 0;      
00055       return false;
00056     }
00057     m_currentTable = &iT->first;
00058     m_currentColumns = &iT->second;
00059   }
00060   return m_currentColumns->find(columnName)!=m_currentColumns->end();
00061 }
00062 
00063 void
00064 ora::TableRegister::insertTable(const std::string& tableName){
00065   init();
00066   m_register.insert( std::make_pair(tableName, std::set<std::string>()) );
00067   m_currentTable = 0;
00068   m_currentColumns = 0;
00069 }
00070 
00071 bool ora::TableRegister::insertColumn(const std::string& tableName,
00072                                       const std::string& columnName){
00073   init();
00074   if(!m_currentTable || (tableName!=*m_currentTable)){
00075     std::map<std::string, std::set<std::string> >::iterator iT = m_register.find( tableName );
00076     if(iT==m_register.end()) {
00077       m_currentTable = 0;
00078       m_currentColumns = 0;      
00079       return false;
00080     }
00081     m_currentTable = &iT->first;
00082     m_currentColumns = &iT->second;
00083   }
00084   m_currentColumns->insert( columnName );
00085   return true;
00086 }
00087 
00088 bool ora::TableRegister::insertColumns(const std::string& tableName,
00089                                        const std::vector<std::string>& columns ){
00090   
00091   init();
00092   if(!m_currentTable || (tableName!=*m_currentTable)){
00093     std::map<std::string, std::set<std::string> >::iterator iT = m_register.find( tableName );
00094     if(iT==m_register.end()) {
00095       m_currentTable = 0;
00096       m_currentColumns = 0;      
00097       return false;
00098     }
00099     m_currentTable = &iT->first;
00100     m_currentColumns = &iT->second;
00101   }
00102   for( std::vector<std::string>::const_iterator iC = columns.begin(); iC != columns.end(); iC++ ){
00103     m_currentColumns->insert( *iC );
00104   }
00105   return true;
00106 }
00107 
00108 size_t ora::TableRegister::numberOfColumns(const std::string& tableName){
00109   init();
00110   if(!m_currentTable || (tableName!=*m_currentTable)){
00111     std::map<std::string, std::set<std::string> >::iterator iT = m_register.find( tableName );
00112     if(iT==m_register.end()) {
00113       m_currentTable = 0;
00114       m_currentColumns = 0;      
00115       return 0;
00116     }
00117     m_currentTable = &iT->first;
00118     m_currentColumns = &iT->second;
00119   }
00120   return m_currentColumns->size();
00121 }
00122 
00123