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

Constructor & Destructor Documentation

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

Definition at line 24 of file DatabaseContainer.cc.

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

Definition at line 29 of file DatabaseContainer.cc.

29  {
30  }

Member Function Documentation

size_t ora::WriteBuffer::flush ( )
inline

Definition at line 36 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().

36  {
37  size_t nobj = 0;
38  if( m_buffer.size() ){
39  MappingElement& topLevelMapping = m_contSchema.mapping( true ).topElement();
40  RelationalBuffer operationBuffer( m_contSchema.storageSchema() );
41  InsertOperation* topLevelInsert = &operationBuffer.newInsert( topLevelMapping.tableName() );
42  topLevelInsert->addId( topLevelMapping.columnNames()[ 0 ] );
44  MappingElement::iterator iMap = topLevelMapping.find( type.Name(Reflex::SCOPED) );
45  // the first inner mapping is the relevant...
46  if( iMap == topLevelMapping.end()){
47  throwException("Could not find a mapping element for class \""+
48  type.Name(Reflex::SCOPED)+"\"",
49  "WriteBuffer::flush");
50  }
51  MappingElement& mapping = iMap->second;
52  RelationalStreamerFactory streamerFactory( m_contSchema );
53  DataElement topLevelElement;
54  std::auto_ptr<IRelationalWriter> writer( streamerFactory.newWriter( type, mapping ) );
55  writer->build( topLevelElement, *topLevelInsert, operationBuffer );
56 
57  for( std::vector<std::pair<int, const void*> >::const_iterator iW = m_buffer.begin();
58  iW != m_buffer.end(); ++iW ){
59  int oid = iW->first;
60  const void* data = iW->second;
61  coral::AttributeList& dataBuff = topLevelInsert->data();
62  dataBuff.begin()->data<int>() = oid;
63  writer->write( oid, data );
64  if( operationBuffer.flush() ) nobj++;
65  }
66  m_buffer.clear();
67  }
68  return nobj;
69  }
type
Definition: HCALResponse.h:21
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()
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)
void ora::WriteBuffer::registerForWrite ( int  oid,
const void *  data 
)
inline

Definition at line 32 of file DatabaseContainer.cc.

References m_buffer.

32  {
33  m_buffer.push_back( std::make_pair(oid, data ) );
34  }
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 73 of file DatabaseContainer.cc.

Referenced by flush(), and registerForWrite().

ContainerSchema& ora::WriteBuffer::m_contSchema
private

Definition at line 74 of file DatabaseContainer.cc.

Referenced by flush().