CMS 3D CMS Logo

Public Member Functions | Private Attributes

ora::UpdateBuffer Class Reference

List of all members.

Public Member Functions

size_t flush ()
void registerForUpdate (int oid, const void *data)
 UpdateBuffer (ContainerSchema &contSchema)
 ~UpdateBuffer ()

Private Attributes

std::vector< std::pair< int,
const void * > > 
m_buffer
ContainerSchemam_contSchema

Detailed Description

Definition at line 76 of file DatabaseContainer.cc.


Constructor & Destructor Documentation

ora::UpdateBuffer::UpdateBuffer ( ContainerSchema contSchema) [inline, explicit]

Definition at line 78 of file DatabaseContainer.cc.

                                                          :
        m_buffer(),
        m_contSchema( contSchema ){
      }
ora::UpdateBuffer::~UpdateBuffer ( ) [inline]

Definition at line 83 of file DatabaseContainer.cc.

                     {
      }

Member Function Documentation

size_t ora::UpdateBuffer::flush ( ) [inline]

Definition at line 92 of file DatabaseContainer.cc.

References ora::InputRelationalData::addId(), ora::InputRelationalData::addWhereId(), ora::RelationalDeleter::build(), ora::MappingElement::columnNames(), ora::InputRelationalData::data(), AlCaHLTBitMon_QueryRunRegistry::data, ora::MappingElement::end(), ora::RelationalDeleter::erase(), ora::MappingElement::find(), m_buffer, m_contSchema, ora::ContainerSchema::mapping(), ora::ContainerSchema::mappingForDependentClasses(), ora::RelationalStreamerFactory::newUpdater(), ora::ContainerSchema::storageSchema(), ora::MappingElement::tableName(), ora::throwException(), ora::MappingTree::topElement(), funct::true, ora::ContainerSchema::type(), and ora::InputRelationalData::whereData().

                    {
        size_t nobj = 0;
        if( m_buffer.size() ){
          RelationalBuffer operationBuffer( m_contSchema.storageSchema() );
          std::vector<MappingElement> dependentMappings;
          m_contSchema.mappingForDependentClasses( dependentMappings );
          RelationalDeleter depDeleter( dependentMappings );
          depDeleter.build( operationBuffer );
          dependentMappings.clear();
          
          MappingElement& topLevelMapping = m_contSchema.mapping( true ).topElement();
          UpdateOperation* topLevelUpdate = &operationBuffer.newUpdate( topLevelMapping.tableName(), true );
          topLevelUpdate->addId(  topLevelMapping.columnNames()[ 0 ] );
          topLevelUpdate->addWhereId(  topLevelMapping.columnNames()[ 0 ] );
          const Reflex::Type& type = m_contSchema.type();
          MappingElement::iterator iMap = topLevelMapping.find( type.Name(Reflex::SCOPED) );
          // the first inner mapping is the relevant...
          if( iMap == topLevelMapping.end()){
            throwException("Could not find a mapping element for class \""+
                           type.Name(Reflex::SCOPED)+"\"",
                           "UpdateBuffer::flush");
          }
          MappingElement& mapping = iMap->second;
          RelationalStreamerFactory streamerFactory( m_contSchema );
          DataElement topLevelElement;
          std::auto_ptr<IRelationalUpdater> updater( streamerFactory.newUpdater( type, mapping ));
          updater->build( topLevelElement, *topLevelUpdate, operationBuffer );
          for( std::vector<std::pair<int, const void*> >::const_iterator iU = m_buffer.begin();
               iU != m_buffer.end(); ++iU ){
            int oid = iU->first;
            const void* data = iU->second;
            // erase the dependencies (they cannot be updated...)
            depDeleter.erase( oid );
            coral::AttributeList& dataBuff = topLevelUpdate->data();
            dataBuff.begin()->data<int>() = oid;
            coral::AttributeList& whereDataBuff = topLevelUpdate->whereData();
            whereDataBuff.begin()->data<int>() = oid;
            updater->update( oid, data );
            if( operationBuffer.flush()) nobj++;
          }
          m_buffer.clear();
        }
        return nobj;
      }
void ora::UpdateBuffer::registerForUpdate ( int  oid,
const void *  data 
) [inline]

Definition at line 87 of file DatabaseContainer.cc.

References m_buffer.

                                                         {
        m_buffer.push_back( std::make_pair( oid, data ));
      }

Member Data Documentation

std::vector<std::pair<int, const void*> > ora::UpdateBuffer::m_buffer [private]

Definition at line 138 of file DatabaseContainer.cc.

Referenced by flush(), and registerForUpdate().

Definition at line 139 of file DatabaseContainer.cc.

Referenced by flush().