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:202
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  {
42  m_recordId.clear();
43  // allocate for the index...
44  m_recordId.push_back(0);
45 
46  RelationalStreamerFactory streamerFactory( m_schema );
47 
48  // first open the insert on the extra table...
49  m_insertOperation = &operationBuffer.newMultiRecordInsert( m_mappingElement.tableName() );
50  const std::vector<std::string>& columns = m_mappingElement.columnNames();
51  if( !columns.size() ){
52  throwException( "Id columns not found in the mapping.",
53  "STLContainerWriter::build");
54  }
55  for( size_t i=0; i<columns.size(); i++ ){
56  m_insertOperation->addId( columns[ i ] );
57  }
58 
59  m_offset = &offset;
60 
62 
63  Reflex::Type valueType;
64  if ( m_associative ){
65 
67  Reflex::Type keyResolvedType = ClassUtils::resolvedType(keyType);
68  if ( ! keyType || !keyResolvedType ) {
69  throwException( "Missing dictionary information for the key type of the container \"" +
70  m_objectType.Name(Reflex::SCOPED) + "\"",
71  "STLContainerWriter::build" );
72  }
73  std::string keyName = keyType.Name();
74  // Retrieve the relevant mapping element
76  if ( iMe == m_mappingElement.end() ) {
77  throwException( "Item for \"" + keyName + "\" not found in the mapping element",
78  "STLContainerWriter::build" );
79  }
80 
81  m_keyWriter.reset( streamerFactory.newWriter( keyResolvedType, iMe->second ) );
82  m_keyWriter->build( m_localElement, *m_insertOperation, operationBuffer );
84  } else {
86  }
87 
88  Reflex::Type valueResolvedType = ClassUtils::resolvedType(valueType);
89  // Check the component type
90  if ( ! valueType || !valueResolvedType ) {
91  throwException( "Missing dictionary information for the content type of the container \"" +
92  m_objectType.Name(Reflex::SCOPED) + "\"",
93  "STLContainerWriter::build" );
94  }
95 
96  std::string valueName = valueType.Name();
97  // Retrieve the relevant mapping element
99  if ( iMe == m_mappingElement.end() ) {
100  throwException( "Item for \"" + valueName + "\" not found in the mapping element",
101  "STLContainerWriter::build" );
102  }
103 
104  m_dataWriter.reset( streamerFactory.newWriter( valueResolvedType, iMe->second ) );
105  m_dataWriter->build( m_localElement, *m_insertOperation, operationBuffer );
106  //operationBuffer.addToExecutionBuffer( *m_insertOperation );
107  return true;
108 }
int i
Definition: DBlmapReader.cc:9
void addId(const std::string &columnName)
std::vector< int > m_recordId
std::auto_ptr< IRelationalWriter > m_keyWriter
Reflex::Type containerDataType(const Reflex::Type &typ)
Definition: ClassUtils.cc:349
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:333
Reflex::Type containerValueType(const Reflex::Type &typ)
Definition: ClassUtils.cc:317
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:380
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
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 110 of file STLContainerStreamer.cc.

References i.

110  {
111  m_recordId.clear();
112  for(size_t i=0;i<identity.size();i++) {
113  m_recordId.push_back( identity[i] );
114  }
115  m_recordId.push_back( 0 );
116 }
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 118 of file STLContainerStreamer.cc.

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

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