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

#include <STLContainerStreamer.h>

Inheritance diagram for ora::STLContainerWriter:
ora::IRelationalWriter

Public Member Functions

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

Private Attributes

std::auto_ptr< IArrayHandlerm_arrayHandler
 
bool m_associative
 
std::auto_ptr< IRelationalWriterm_dataWriter
 
MultiRecordInsertOperationm_insertOperation
 
std::auto_ptr< IRelationalWriterm_keyWriter
 
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 STLContainerStreamer.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 19 of file STLContainerStreamer.cc.

21  :
22  m_objectType( objectType ),
24  m_schema( contSchema ),
25  m_recordId(),
28  m_offset( 0 ),
29  m_insertOperation( 0 ),
31  m_keyWriter(),
32  m_dataWriter(){
33 }
bool isTypeAssociativeContainer(const Reflex::Type &typ)
Definition: ClassUtils.cc:211
std::vector< int > m_recordId
std::auto_ptr< IRelationalWriter > m_keyWriter
MultiRecordInsertOperation * m_insertOperation
std::auto_ptr< IRelationalWriter > m_dataWriter
MappingElement & m_mappingElement
std::auto_ptr< IArrayHandler > m_arrayHandler
ora::STLContainerWriter::~STLContainerWriter ( )
virtual

Definition at line 35 of file STLContainerStreamer.cc.

35  {
36 }

Member Function Documentation

ora::IArrayHandler * ora::STLContainerWriter::arrayHandler ( )
inline

Definition at line 151 of file STLContainerStreamer.h.

151  {
152  return m_arrayHandler.get();
153 }
std::auto_ptr< IArrayHandler > m_arrayHandler
bool ora::STLContainerWriter::build ( DataElement offset,
IRelationalData relationalData,
RelationalBuffer operationBuffer 
)
virtual

Implements ora::IRelationalWriter.

Definition at line 38 of file STLContainerStreamer.cc.

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

40  {
41  if( !m_objectType ){
42  throwException( "Missing dictionary information for the type of the container \"" +
43  m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) + "\"",
44  "STLContainerWriter::build" );
45  }
47  m_recordId.clear();
48  // allocate for the index...
49  m_recordId.push_back(0);
50 
51  RelationalStreamerFactory streamerFactory( m_schema );
52 
53  // first open the insert on the extra table...
54  m_insertOperation = &operationBuffer.newMultiRecordInsert( m_mappingElement.tableName() );
55  const std::vector<std::string>& columns = m_mappingElement.columnNames();
56  if( !columns.size() ){
57  throwException( "Id columns not found in the mapping.",
58  "STLContainerWriter::build");
59  }
60  for( size_t i=0; i<columns.size(); i++ ){
61  m_insertOperation->addId( columns[ i ] );
62  }
63 
64  m_offset = &offset;
65 
67 
68  Reflex::Type valueType;
69  if ( m_associative ){
70 
72  Reflex::Type keyResolvedType = ClassUtils::resolvedType(keyType);
73  if ( ! keyType || !keyResolvedType ) {
74  throwException( "Missing dictionary information for the key type of the container \"" +
75  m_objectType.Name(Reflex::SCOPED) + "\"",
76  "STLContainerWriter::build" );
77  }
78  std::string keyName = keyType.Name();
79  // Retrieve the relevant mapping element
81  if ( iMe == m_mappingElement.end() ) {
82  throwException( "Item for \"" + keyName + "\" not found in the mapping element",
83  "STLContainerWriter::build" );
84  }
85 
86  m_keyWriter.reset( streamerFactory.newWriter( keyResolvedType, iMe->second ) );
87  m_keyWriter->build( m_localElement, *m_insertOperation, operationBuffer );
89  } else {
91  }
92 
93  Reflex::Type valueResolvedType = ClassUtils::resolvedType(valueType);
94  // Check the component type
95  if ( ! valueType || !valueResolvedType ) {
96  throwException( "Missing dictionary information for the content type of the container \"" +
97  m_objectType.Name(Reflex::SCOPED) + "\"",
98  "STLContainerWriter::build" );
99  }
100 
101  std::string valueName = valueType.Name();
102  // Retrieve the relevant mapping element
104  if ( iMe == m_mappingElement.end() ) {
105  throwException( "Item for \"" + valueName + "\" not found in the mapping element",
106  "STLContainerWriter::build" );
107  }
108 
109  m_dataWriter.reset( streamerFactory.newWriter( valueResolvedType, iMe->second ) );
110  m_dataWriter->build( m_localElement, *m_insertOperation, operationBuffer );
111  //operationBuffer.addToExecutionBuffer( *m_insertOperation );
112  return true;
113 }
int i
Definition: DBlmapReader.cc:9
std::vector< int > m_recordId
std::auto_ptr< IRelationalWriter > m_keyWriter
Reflex::Type containerDataType(const Reflex::Type &typ)
Definition: ClassUtils.cc:373
MultiRecordInsertOperation * m_insertOperation
static IArrayHandler * newArrayHandler(const Reflex::Type &arrayType)
std::auto_ptr< IRelationalWriter > m_dataWriter
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
Reflex::Type containerKeyType(const Reflex::Type &typ)
Definition: ClassUtils.cc:357
Reflex::Type containerValueType(const Reflex::Type &typ)
Definition: ClassUtils.cc:341
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:404
iterator end()
Returns an iterator in the end of the sequence.
const std::string & tableName() const
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
MappingElement & m_mappingElement
std::auto_ptr< IArrayHandler > m_arrayHandler
int addId(const std::string &columnName)
ora::DataElement * ora::STLContainerWriter::dataElement ( )
inline

Definition at line 145 of file STLContainerStreamer.h.

145  {
146  return m_offset;
147 }
ora::MappingElement & ora::STLContainerWriter::mapping ( )
inline

Definition at line 139 of file STLContainerStreamer.h.

References m_mappingElement.

139  {
140  return m_mappingElement;
141 }
MappingElement & m_mappingElement
void ora::STLContainerWriter::setRecordId ( const std::vector< int > &  identity)
virtual

Implements ora::IRelationalWriter.

Definition at line 115 of file STLContainerStreamer.cc.

References i.

115  {
116  m_recordId.clear();
117  for(size_t i=0;i<identity.size();i++) {
118  m_recordId.push_back( identity[i] );
119  }
120  m_recordId.push_back( 0 );
121 }
int i
Definition: DBlmapReader.cc:9
std::vector< int > m_recordId
void ora::STLContainerWriter::write ( int  oid,
const void *  data 
)
virtual

Writes a data element.

Implements ora::IRelationalWriter.

Definition at line 123 of file STLContainerStreamer.cc.

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

124  {
125 
126  if(!m_offset){
127  throwException("The streamer has not been built.",
128  "STLContainerWriter::write");
129  }
130 
131  const std::vector<std::string>& columns = m_mappingElement.columnNames();
132  if( columns.size() != m_recordId.size()+1){
133  throwException( "Object id elements provided are not matching with the mapped id columns.",
134  "STLContainerWriter::write");
135  }
136 
137  const Reflex::Type& iteratorReturnType = m_arrayHandler->iteratorReturnType();
138  // Retrieve the container type
139  Reflex::Type keyType;
140  if ( m_associative ) keyType = m_objectType.TemplateArgumentAt(0);
141  Reflex::Member firstMember;
142  Reflex::Member secondMember;
143  if( keyType ){
144  firstMember = iteratorReturnType.MemberByName( "first" );
145  if ( ! firstMember ) {
146  throwException( "Could not find the data member \"first\" for the class \"" +
147  iteratorReturnType.Name(Reflex::SCOPED) + "\"",
148  "STLContainerWriter::write" );
149  }
150  secondMember = iteratorReturnType.MemberByName( "second" );
151  if ( ! secondMember ) {
152  throwException( "Could not retrieve the data member \"second\" for the class \"" +
153  iteratorReturnType.Name(Reflex::SCOPED) + "\"",
154  "STLContainerWriter::write" );
155  }
156  }
157 
158  void* data = m_offset->address( inputData );
159 
160  // Use the iterator to loop over the elements of the container.
161  size_t containerSize = m_arrayHandler->size( data );
162 
163  if ( containerSize == 0 ) return;
164 
165  size_t startElementIndex = m_arrayHandler->startElementIndex( data );
166  std::auto_ptr<IArrayIteratorHandler> iteratorHandler( m_arrayHandler->iterate( data ) );
167 
168  InsertCache& bulkInsert = m_insertOperation->setUp( containerSize-startElementIndex+1 );
169 
170  for ( size_t iIndex = startElementIndex; iIndex < containerSize; ++iIndex ) {
171 
172  m_recordId[m_recordId.size()-1] = iIndex;
173  coral::AttributeList& dataBuff = m_insertOperation->data();
174 
175  dataBuff[ columns[0] ].data<int>() = oid;
176  for( size_t i = 1;i < columns.size(); i++ ){
177  dataBuff[ columns[i] ].data<int>() = m_recordId[i-1];
178  }
179 
180  void* objectReference = iteratorHandler->object();
181  void* componentData = objectReference;
182 
183  if ( keyType ) { // treat the key object first
184  void* keyData = static_cast< char* >( objectReference ) + firstMember.Offset();
185  m_keyWriter->setRecordId( m_recordId );
186  m_keyWriter->write( oid, keyData );
187 
188  componentData = static_cast< char* >( objectReference ) + secondMember.Offset();
189  }
190  m_dataWriter->setRecordId( m_recordId );
191 
192  m_dataWriter->write( oid, componentData );
193  bulkInsert.processNextIteration();
194 
195  // Increment the iterator
196  iteratorHandler->increment();
197  }
198 
199  // execute the insert...
200  m_arrayHandler->finalize( const_cast<void*>( data ) );
201 
202 }
int i
Definition: DBlmapReader.cc:9
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:48
std::vector< int > m_recordId
std::auto_ptr< IRelationalWriter > m_keyWriter
MultiRecordInsertOperation * m_insertOperation
std::auto_ptr< IRelationalWriter > m_dataWriter
const std::vector< std::string > & columnNames() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
InsertCache & setUp(int rowCacheSize)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
MappingElement & m_mappingElement
std::auto_ptr< IArrayHandler > m_arrayHandler
tuple inputData
Definition: idDealer.py:72

Member Data Documentation

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

Definition at line 52 of file STLContainerStreamer.h.

bool ora::STLContainerWriter::m_associative
private

Definition at line 49 of file STLContainerStreamer.h.

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

Definition at line 54 of file STLContainerStreamer.h.

MultiRecordInsertOperation* ora::STLContainerWriter::m_insertOperation
private

Definition at line 51 of file STLContainerStreamer.h.

std::auto_ptr<IRelationalWriter> ora::STLContainerWriter::m_keyWriter
private

Definition at line 53 of file STLContainerStreamer.h.

DataElement ora::STLContainerWriter::m_localElement
private

Definition at line 46 of file STLContainerStreamer.h.

MappingElement& ora::STLContainerWriter::m_mappingElement
private

Definition at line 43 of file STLContainerStreamer.h.

Referenced by mapping().

Reflex::Type ora::STLContainerWriter::m_objectType
private

Definition at line 42 of file STLContainerStreamer.h.

DataElement* ora::STLContainerWriter::m_offset
private

Definition at line 50 of file STLContainerStreamer.h.

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

Definition at line 45 of file STLContainerStreamer.h.

ContainerSchema& ora::STLContainerWriter::m_schema
private

Definition at line 44 of file STLContainerStreamer.h.