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(), 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
void addId(const std::string &columnName)
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:380
DataElement * m_offset
DataElement m_localElement
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
ContainerSchema & m_schema
MappingElement & m_mappingElement
std::auto_ptr< IRelationalWriter > m_dataWriter
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 runTheMatrix::data, i, ora::InsertCache::processNextIteration(), and ora::throwException().

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  size_t persistentSize = m_arrayHandler->persistentSize( data );
109 
110  if ( containerSize == 0 || containerSize < persistentSize ) return;
111 
112  size_t startElementIndex = m_arrayHandler->startElementIndex( data );
113 
114  std::auto_ptr<IArrayIteratorHandler> iteratorHandler( m_arrayHandler->iterate( data ) );
115 
116  InsertCache& bulkOperation = m_insertOperation->setUp( containerSize-startElementIndex+1 );
117 
118  for ( size_t iIndex = startElementIndex; iIndex < containerSize; ++iIndex ) {
119 
120  m_recordId[m_recordId.size()-1] = iIndex;
121  coral::AttributeList& dataBuff = m_insertOperation->data();
122 
123  dataBuff[ columns[0] ].data<int>() = oid;
124  for( size_t i = 1;i < columns.size(); i++ ){
125  dataBuff[ columns[i] ].data<int>() = m_recordId[i-1];
126  }
127 
128  void* objectReference = iteratorHandler->object();
129 
130  m_dataWriter->setRecordId( m_recordId );
131  m_dataWriter->write( oid, objectReference );
132 
133  bulkOperation.processNextIteration();
134  // Increment the iterator
135  iteratorHandler->increment();
136  }
137 
138  m_arrayHandler->finalize( const_cast<void*>( data ) );
139 
140 }
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
InsertCache & setUp(int rowCacheSize)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
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.