#include <CArrayStreamer.h>
Public Member Functions | |
bool | build (DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer) |
CArrayWriter (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema) | |
Constructor. | |
void | setRecordId (const std::vector< int > &identity) |
void | write (int oid, const void *data) |
Writes a data element. | |
virtual | ~CArrayWriter () |
Private Attributes | |
std::auto_ptr< IArrayHandler > | m_arrayHandler |
std::auto_ptr< IRelationalWriter > | m_dataWriter |
MultiRecordInsertOperation * | m_insertOperation |
DataElement | m_localElement |
MappingElement & | m_mappingElement |
Reflex::Type | m_objectType |
DataElement * | m_offset |
std::vector< int > | m_recordId |
ContainerSchema & | m_schema |
Definition at line 21 of file CArrayStreamer.h.
ora::CArrayWriter::CArrayWriter | ( | const Reflex::Type & | objectType, |
MappingElement & | mapping, | ||
ContainerSchema & | contSchema | ||
) |
Constructor.
Definition at line 17 of file CArrayStreamer.cc.
: m_objectType( objectType ), m_mappingElement( mapping ), m_schema( contSchema ), m_recordId(), m_localElement( ), m_offset( 0 ), m_insertOperation( 0 ), m_arrayHandler(), m_dataWriter(){ }
ora::CArrayWriter::~CArrayWriter | ( | ) | [virtual] |
Definition at line 31 of file CArrayStreamer.cc.
{ }
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().
{ m_localElement.clear(); m_recordId.clear(); // allocate for the index... m_recordId.push_back(0); // Check the array type Reflex::Type arrayType = m_objectType.ToType(); Reflex::Type arrayResolvedType = ClassUtils::resolvedType(arrayType); // Check the component type if ( ! arrayType || !arrayResolvedType ) { throwException( "Missing dictionary information for the element type of the array \"" + m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) + "\"", "CArrayWriter::build" ); } RelationalStreamerFactory streamerFactory( m_schema ); // first open the insert on the extra table... m_insertOperation = &operationBuffer.newMultiRecordInsert( m_mappingElement.tableName() ); const std::vector<std::string>& columns = m_mappingElement.columnNames(); if( !columns.size() ){ throwException( "Id columns not found in the mapping.", "CArrayWriter::build"); } for( size_t i=0; i<columns.size(); i++ ){ m_insertOperation->addId( columns[ i ] ); } m_offset = &offset; m_arrayHandler.reset( ArrayHandlerFactory::newArrayHandler( m_objectType ) ); std::string arrayTypeName = arrayType.Name(); // Retrieve the relevant mapping element MappingElement::iterator iMe = m_mappingElement.find( arrayTypeName ); if ( iMe == m_mappingElement.end() ) { throwException( "Item for \"" + arrayTypeName + "\" not found in the mapping element", "CArrayWriter::build" ); } m_dataWriter.reset( streamerFactory.newWriter( arrayResolvedType, iMe->second )); m_dataWriter->build( m_localElement, *m_insertOperation, operationBuffer ); return true; }
void ora::CArrayWriter::setRecordId | ( | const std::vector< int > & | identity | ) | [virtual] |
Implements ora::IRelationalWriter.
Definition at line 83 of file CArrayStreamer.cc.
References i.
{ m_recordId.clear(); for(size_t i=0;i<identity.size();i++) { m_recordId.push_back( identity[i] ); } m_recordId.push_back( 0 ); }
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().
{ if(!m_offset){ throwException("The streamer has not been built.", "CArrayWriter::write"); } const std::vector<std::string>& columns = m_mappingElement.columnNames(); if( columns.size() != m_recordId.size()+1){ throwException( "Record id elements provided are not matching with the mapped id columns.", "CArrayWriter::write"); } void* data = m_offset->address( inputData ); // Use the iterator to loop over the elements of the container. size_t containerSize = m_arrayHandler->size( data ); if ( containerSize == 0 ) return; size_t startElementIndex = m_arrayHandler->startElementIndex( data ); std::auto_ptr<IArrayIteratorHandler> iteratorHandler( m_arrayHandler->iterate( data ) ); InsertCache& bulkOperation = m_insertOperation->setUp( containerSize-startElementIndex+1 ); for ( size_t iIndex = startElementIndex; iIndex < containerSize; ++iIndex ) { m_recordId[m_recordId.size()-1] = iIndex; coral::AttributeList& dataBuff = m_insertOperation->data(); dataBuff[ columns[0] ].data<int>() = oid; for( size_t i = 1;i < columns.size(); i++ ){ dataBuff[ columns[i] ].data<int>() = m_recordId[i-1]; } void* objectReference = iteratorHandler->object(); m_dataWriter->setRecordId( m_recordId ); m_dataWriter->write( oid, objectReference ); bulkOperation.processNextIteration(); // Increment the iterator iteratorHandler->increment(); } m_arrayHandler->finalize( const_cast<void*>( data ) ); }
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.
Definition at line 44 of file CArrayStreamer.h.
DataElement ora::CArrayWriter::m_localElement [private] |
Definition at line 40 of file CArrayStreamer.h.
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.