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

#include <CArrayStreamer.h>

Inheritance diagram for ora::CArrayWriter:
ora::IRelationalWriter

Public Member Functions

bool build (DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
 
 CArrayWriter (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
 Constructor. More...
 
void setRecordId (const std::vector< int > &identity)
 
void write (int oid, const void *data)
 Writes a data element. More...
 
virtual ~CArrayWriter ()
 
- Public Member Functions inherited from ora::IRelationalWriter
virtual ~IRelationalWriter ()
 Destructor. More...
 

Private Attributes

std::auto_ptr< IArrayHandlerm_arrayHandler
 
std::auto_ptr< IRelationalWriterm_dataWriter
 
MultiRecordInsertOperationm_insertOperation
 
DataElement m_localElement
 
MappingElementm_mappingElement
 
Reflex::Type m_objectType
 
DataElementm_offset
 
std::vector< int > m_recordId
 
ContainerSchemam_schema
 

Detailed Description

Definition at line 21 of file CArrayStreamer.h.

Constructor & Destructor Documentation

ora::CArrayWriter::CArrayWriter ( const Reflex::Type &  objectType,
MappingElement mapping,
ContainerSchema contSchema 
)

Constructor.

Definition at line 17 of file CArrayStreamer.cc.

19  :
20  m_objectType( objectType ),
21  m_mappingElement( mapping ),
22  m_schema( contSchema ),
23  m_recordId(),
24  m_localElement( ),
25  m_offset( 0 ),
26  m_insertOperation( 0 ),
28  m_dataWriter(){
29 }
MultiRecordInsertOperation * m_insertOperation
Reflex::Type m_objectType
std::vector< int > m_recordId
std::auto_ptr< IArrayHandler > m_arrayHandler
DataElement * m_offset
DataElement m_localElement
ContainerSchema & m_schema
MappingElement & m_mappingElement
std::auto_ptr< IRelationalWriter > m_dataWriter
ora::CArrayWriter::~CArrayWriter ( )
virtual

Definition at line 31 of file CArrayStreamer.cc.

31  {
32 }

Member Function Documentation

bool ora::CArrayWriter::build ( DataElement offset,
IRelationalData relationalData,
RelationalBuffer operationBuffer 
)
virtual

Implements ora::IRelationalWriter.

Definition at line 34 of file CArrayStreamer.cc.

References i, ora::ArrayHandlerFactory::newArrayHandler(), ora::RelationalBuffer::newMultiRecordInsert(), ora::RelationalStreamerFactory::newWriter(), evf::evtn::offset(), ora::ClassUtils::resolvedType(), AlCaHLTBitMon_QueryRunRegistry::string, and ora::throwException().

36  {
37 
39  m_recordId.clear();
40  // allocate for the index...
41  m_recordId.push_back(0);
42 
43  // Check the array type
44  Reflex::Type arrayType = m_objectType.ToType();
45  Reflex::Type arrayResolvedType = ClassUtils::resolvedType(arrayType);
46  // Check the component type
47  if ( ! arrayType || !arrayResolvedType ) {
48  throwException( "Missing dictionary information for the element type of the array \"" +
49  m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) + "\"",
50  "CArrayWriter::build" );
51  }
52 
53  RelationalStreamerFactory streamerFactory( m_schema );
54 
55  // first open the insert on the extra table...
56  m_insertOperation = &operationBuffer.newMultiRecordInsert( m_mappingElement.tableName() );
57  const std::vector<std::string>& columns = m_mappingElement.columnNames();
58  if( !columns.size() ){
59  throwException( "Id columns not found in the mapping.",
60  "CArrayWriter::build");
61  }
62  for( size_t i=0; i<columns.size(); i++ ){
63  m_insertOperation->addId( columns[ i ] );
64  }
65 
66  m_offset = &offset;
67 
69 
70  std::string arrayTypeName = arrayType.Name();
71  // Retrieve the relevant mapping element
72  MappingElement::iterator iMe = m_mappingElement.find( arrayTypeName );
73  if ( iMe == m_mappingElement.end() ) {
74  throwException( "Item for \"" + arrayTypeName + "\" not found in the mapping element",
75  "CArrayWriter::build" );
76  }
77 
78  m_dataWriter.reset( streamerFactory.newWriter( arrayResolvedType, iMe->second ));
79  m_dataWriter->build( m_localElement, *m_insertOperation, operationBuffer );
80  return true;
81 }
int i
Definition: DBlmapReader.cc:9
MultiRecordInsertOperation * m_insertOperation
Reflex::Type m_objectType
std::vector< int > m_recordId
static IArrayHandler * newArrayHandler(const Reflex::Type &arrayType)
iterator find(const std::string &key)
Retrieves a sub-element.
unsigned int offset(bool)
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
const std::vector< std::string > & columnNames() const
std::auto_ptr< IArrayHandler > m_arrayHandler
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:404
DataElement * m_offset
DataElement m_localElement
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
iterator end()
Returns an iterator in the end of the sequence.
const std::string & tableName() const
ContainerSchema & m_schema
MappingElement & m_mappingElement
std::auto_ptr< IRelationalWriter > m_dataWriter
int addId(const std::string &columnName)
void ora::CArrayWriter::setRecordId ( const std::vector< int > &  identity)
virtual

Implements ora::IRelationalWriter.

Definition at line 83 of file CArrayStreamer.cc.

References i.

83  {
84  m_recordId.clear();
85  for(size_t i=0;i<identity.size();i++) {
86  m_recordId.push_back( identity[i] );
87  }
88  m_recordId.push_back( 0 );
89 }
int i
Definition: DBlmapReader.cc:9
std::vector< int > m_recordId
void ora::CArrayWriter::write ( int  oid,
const void *  data 
)
virtual

Writes a data element.

Implements ora::IRelationalWriter.

Definition at line 91 of file CArrayStreamer.cc.

References data, i, ora::InsertCache::processNextIteration(), and ora::throwException().

Referenced by pkg.AbstractPkg::generate().

92  {
93 
94  if(!m_offset){
95  throwException("The streamer has not been built.",
96  "CArrayWriter::write");
97  }
98  const std::vector<std::string>& columns = m_mappingElement.columnNames();
99  if( columns.size() != m_recordId.size()+1){
100  throwException( "Record id elements provided are not matching with the mapped id columns.",
101  "CArrayWriter::write");
102  }
103 
104  void* data = m_offset->address( inputData );
105 
106  // Use the iterator to loop over the elements of the container.
107  size_t containerSize = m_arrayHandler->size( data );
108 
109  if ( containerSize == 0 ) return;
110 
111  size_t startElementIndex = m_arrayHandler->startElementIndex( data );
112 
113  std::auto_ptr<IArrayIteratorHandler> iteratorHandler( m_arrayHandler->iterate( data ) );
114 
115  InsertCache& bulkOperation = m_insertOperation->setUp( containerSize-startElementIndex+1 );
116 
117  for ( size_t iIndex = startElementIndex; iIndex < containerSize; ++iIndex ) {
118 
119  m_recordId[m_recordId.size()-1] = iIndex;
120  coral::AttributeList& dataBuff = m_insertOperation->data();
121 
122  dataBuff[ columns[0] ].data<int>() = oid;
123  for( size_t i = 1;i < columns.size(); i++ ){
124  dataBuff[ columns[i] ].data<int>() = m_recordId[i-1];
125  }
126 
127  void* objectReference = iteratorHandler->object();
128 
129  m_dataWriter->setRecordId( m_recordId );
130  m_dataWriter->write( oid, objectReference );
131 
132  bulkOperation.processNextIteration();
133  // Increment the iterator
134  iteratorHandler->increment();
135  }
136 
137  m_arrayHandler->finalize( const_cast<void*>( data ) );
138 
139 }
int i
Definition: DBlmapReader.cc:9
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:48
MultiRecordInsertOperation * m_insertOperation
std::vector< int > m_recordId
const std::vector< std::string > & columnNames() const
std::auto_ptr< IArrayHandler > m_arrayHandler
DataElement * m_offset
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
InsertCache & setUp(int rowCacheSize)
MappingElement & m_mappingElement
std::auto_ptr< IRelationalWriter > m_dataWriter
tuple inputData
Definition: idDealer.py:72

Member Data Documentation

std::auto_ptr<IArrayHandler> ora::CArrayWriter::m_arrayHandler
private

Definition at line 45 of file CArrayStreamer.h.

std::auto_ptr<IRelationalWriter> ora::CArrayWriter::m_dataWriter
private

Definition at line 46 of file CArrayStreamer.h.

MultiRecordInsertOperation* ora::CArrayWriter::m_insertOperation
private

Definition at line 44 of file CArrayStreamer.h.

DataElement ora::CArrayWriter::m_localElement
private

Definition at line 40 of file CArrayStreamer.h.

MappingElement& ora::CArrayWriter::m_mappingElement
private

Definition at line 37 of file CArrayStreamer.h.

Reflex::Type ora::CArrayWriter::m_objectType
private

Definition at line 36 of file CArrayStreamer.h.

DataElement* ora::CArrayWriter::m_offset
private

Definition at line 43 of file CArrayStreamer.h.

std::vector<int> ora::CArrayWriter::m_recordId
private

Definition at line 39 of file CArrayStreamer.h.

ContainerSchema& ora::CArrayWriter::m_schema
private

Definition at line 38 of file CArrayStreamer.h.