CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #include "RelationalDeleter.h"
00002 #include "RelationalOperation.h"
00003 #include "RelationalBuffer.h"
00004 #include "MappingElement.h"
00005 #include "ContainerSchema.h"
00006 // externals
00007 #include "CoralBase/Attribute.h"
00008 
00009 ora::RelationalDeleter::RelationalDeleter( MappingElement& dataMapping ):
00010   m_mappings(),
00011   m_operations(){
00012   m_mappings.push_back( &dataMapping );
00013 }
00014 
00015 ora::RelationalDeleter::RelationalDeleter( const std::vector<MappingElement>& mappingList ):
00016   m_mappings(),
00017   m_operations(){
00018   for(  std::vector<MappingElement>::const_iterator iMe = mappingList.begin();
00019         iMe != mappingList.end(); ++iMe ){
00020     m_mappings.push_back( &(*iMe) );
00021   } 
00022 }
00023 
00024 ora::RelationalDeleter::~RelationalDeleter(){
00025   clear();
00026 }
00027 
00028 void ora::RelationalDeleter::clear(){
00029   m_operations.clear();
00030 }
00031 
00032 void ora::RelationalDeleter::build( RelationalBuffer& buffer ){
00033   m_operations.clear();
00034   for( std::vector<const MappingElement*>::iterator iMe = m_mappings.begin();
00035        iMe != m_mappings.end(); iMe++  ){
00036     std::vector<std::pair<std::string,std::string> > tableHierarchy = (*iMe)->tableHierarchy();
00037     size_t sz = tableHierarchy.size();
00038     for( size_t i=1; i<sz+1; i++ ){
00039       DeleteOperation& delOperation = buffer.newDelete( tableHierarchy[sz-i].first, i==sz );
00040       delOperation.addWhereId( tableHierarchy[sz-i].second );
00041       m_operations.push_back(&delOperation);      
00042     }
00043   }
00044 }
00045 
00046 void ora::RelationalDeleter::erase( int itemId ){
00047   for( std::vector<DeleteOperation*>::const_iterator iDel = m_operations.begin();
00048        iDel != m_operations.end(); ++iDel ){
00049     coral::AttributeList& whereData = (*iDel)->whereData();
00050     whereData.begin()->data<int>() = itemId;
00051   }
00052 }
00053