CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
ora::UpdateBuffer Class Reference

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 78 of file DatabaseContainer.cc.

Constructor & Destructor Documentation

ora::UpdateBuffer::UpdateBuffer ( ContainerSchema contSchema)
inlineexplicit

Definition at line 80 of file DatabaseContainer.cc.

80  :
81  m_buffer(),
82  m_contSchema( contSchema ){
83  }
std::vector< std::pair< int, const void * > > m_buffer
ContainerSchema & m_contSchema
ora::UpdateBuffer::~UpdateBuffer ( )
inline

Definition at line 85 of file DatabaseContainer.cc.

85  {
86  }

Member Function Documentation

size_t ora::UpdateBuffer::flush ( )
inline

Definition at line 94 of file DatabaseContainer.cc.

References ora::InputRelationalData::addId(), ora::InputRelationalData::addWhereId(), ora::RelationalDeleter::build(), ora::MappingElement::columnNames(), edm::TypeWithDict::cppName(), ora::InputRelationalData::data(), 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().

94  {
95  size_t nobj = 0;
96  if( m_buffer.size() ){
97  RelationalBuffer operationBuffer( m_contSchema.storageSchema() );
98  std::vector<MappingElement> dependentMappings;
99  m_contSchema.mappingForDependentClasses( dependentMappings );
100  RelationalDeleter depDeleter( dependentMappings );
101  depDeleter.build( operationBuffer );
102  dependentMappings.clear();
103 
104  MappingElement& topLevelMapping = m_contSchema.mapping( true ).topElement();
105  UpdateOperation* topLevelUpdate = &operationBuffer.newUpdate( topLevelMapping.tableName(), true );
106  topLevelUpdate->addId( topLevelMapping.columnNames()[ 0 ] );
107  topLevelUpdate->addWhereId( topLevelMapping.columnNames()[ 0 ] );
109  MappingElement::iterator iMap = topLevelMapping.find( type.cppName() );
110  // the first inner mapping is the relevant...
111  if( iMap == topLevelMapping.end()){
112  throwException("Could not find a mapping element for class \""+
113  type.cppName()+"\"",
114  "UpdateBuffer::flush");
115  }
116  MappingElement& mapping = iMap->second;
117  RelationalStreamerFactory streamerFactory( m_contSchema );
118  DataElement topLevelElement;
119  std::auto_ptr<IRelationalUpdater> updater( streamerFactory.newUpdater( type, mapping ));
120  updater->build( topLevelElement, *topLevelUpdate, operationBuffer );
121  for( std::vector<std::pair<int, const void*> >::const_iterator iU = m_buffer.begin();
122  iU != m_buffer.end(); ++iU ){
123  int oid = iU->first;
124  const void* data = iU->second;
125  // erase the dependencies (they cannot be updated...)
126  depDeleter.erase( oid );
127  coral::AttributeList& dataBuff = topLevelUpdate->data();
128  dataBuff.begin()->data<int>() = oid;
129  coral::AttributeList& whereDataBuff = topLevelUpdate->whereData();
130  whereDataBuff.begin()->data<int>() = oid;
131  updater->update( oid, data );
132  if( operationBuffer.flush()) nobj++;
133  }
134  m_buffer.clear();
135  }
136  return nobj;
137  }
type
Definition: HCALResponse.h:21
std::string cppName() const
bool mappingForDependentClasses(std::vector< MappingElement > &destination)
const MappingElement & topElement() const
Definition: MappingTree.h:143
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
const edm::TypeWithDict & type()
std::vector< std::pair< int, const void * > > m_buffer
coral::ISchema & storageSchema()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
MappingTree & mapping(bool writeEnabled=false)
ContainerSchema & m_contSchema
void ora::UpdateBuffer::registerForUpdate ( int  oid,
const void *  data 
)
inline

Definition at line 89 of file DatabaseContainer.cc.

References m_buffer.

89  {
90  m_buffer.push_back( std::make_pair( oid, data ));
91  }
std::vector< std::pair< int, const void * > > m_buffer
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82

Member Data Documentation

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

Definition at line 140 of file DatabaseContainer.cc.

Referenced by flush(), and registerForUpdate().

ContainerSchema& ora::UpdateBuffer::m_contSchema
private

Definition at line 141 of file DatabaseContainer.cc.

Referenced by flush().