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::WriteBuffer Class Reference

Public Member Functions

size_t flush ()
 
void registerForWrite (int oid, const void *data)
 
 WriteBuffer (ContainerSchema &contSchema)
 
 ~WriteBuffer ()
 

Private Attributes

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

Detailed Description

Definition at line 20 of file DatabaseContainer.cc.

Constructor & Destructor Documentation

ora::WriteBuffer::WriteBuffer ( ContainerSchema contSchema)
inlineexplicit

Definition at line 22 of file DatabaseContainer.cc.

22  :
23  m_buffer(),
24  m_contSchema( contSchema ){
25  }
ContainerSchema & m_contSchema
std::vector< std::pair< int, const void * > > m_buffer
ora::WriteBuffer::~WriteBuffer ( )
inline

Definition at line 27 of file DatabaseContainer.cc.

27  {
28  }

Member Function Documentation

size_t ora::WriteBuffer::flush ( )
inline

Definition at line 34 of file DatabaseContainer.cc.

References ora::InputRelationalData::addId(), ora::MappingElement::columnNames(), data, ora::MappingElement::end(), ora::MappingElement::find(), m_buffer, m_contSchema, ora::ContainerSchema::mapping(), ora::RelationalStreamerFactory::newWriter(), ora::ContainerSchema::storageSchema(), ora::MappingElement::tableName(), ora::throwException(), ora::MappingTree::topElement(), and ora::ContainerSchema::type().

34  {
35  size_t nobj = 0;
36  if( m_buffer.size() ){
37  MappingElement& topLevelMapping = m_contSchema.mapping( true ).topElement();
38  RelationalBuffer operationBuffer( m_contSchema.storageSchema() );
39  InsertOperation* topLevelInsert = &operationBuffer.newInsert( topLevelMapping.tableName() );
40  topLevelInsert->addId( topLevelMapping.columnNames()[ 0 ] );
42  MappingElement::iterator iMap = topLevelMapping.find( type.Name(Reflex::SCOPED) );
43  // the first inner mapping is the relevant...
44  if( iMap == topLevelMapping.end()){
45  throwException("Could not find a mapping element for class \""+
46  type.Name(Reflex::SCOPED)+"\"",
47  "WriteBuffer::flush");
48  }
49  MappingElement& mapping = iMap->second;
50  RelationalStreamerFactory streamerFactory( m_contSchema );
51  DataElement topLevelElement;
52  std::auto_ptr<IRelationalWriter> writer( streamerFactory.newWriter( type, mapping ) );
53  writer->build( topLevelElement, *topLevelInsert, operationBuffer );
54 
55  for( std::vector<std::pair<int, const void*> >::const_iterator iW = m_buffer.begin();
56  iW != m_buffer.end(); ++iW ){
57  int oid = iW->first;
58  const void* data = iW->second;
59  coral::AttributeList& dataBuff = topLevelInsert->data();
60  dataBuff.begin()->data<int>() = oid;
61  writer->write( oid, data );
62  if( operationBuffer.flush() ) nobj++;
63  }
64  m_buffer.clear();
65  }
66  return nobj;
67  }
type
Definition: HCALResponse.h:22
ContainerSchema & m_contSchema
const Reflex::Type & type()
const MappingElement & topElement() const
Definition: MappingTree.h:143
std::vector< std::pair< int, const void * > > m_buffer
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
coral::ISchema & storageSchema()
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
MappingTree & mapping(bool writeEnabled=false)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::WriteBuffer::registerForWrite ( int  oid,
const void *  data 
)
inline

Definition at line 30 of file DatabaseContainer.cc.

References m_buffer.

30  {
31  m_buffer.push_back( std::make_pair(oid, data ) );
32  }
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::WriteBuffer::m_buffer
private

Definition at line 71 of file DatabaseContainer.cc.

Referenced by flush(), and registerForWrite().

ContainerSchema& ora::WriteBuffer::m_contSchema
private

Definition at line 72 of file DatabaseContainer.cc.

Referenced by flush().