#include <CArrayStreamer.h>
Public Member Functions | |
bool | build (DataElement &offset, IRelationalData &relationalData) |
CArrayReader (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema) | |
Constructor. | |
void | clear () |
void | read (void *address) |
Reads a data element. | |
void | select (int oid) |
void | setRecordId (const std::vector< int > &identity) |
virtual | ~CArrayReader () |
Private Attributes | |
std::auto_ptr< IArrayHandler > | m_arrayHandler |
std::auto_ptr< IRelationalReader > | m_dataReader |
DataElement | m_localElement |
MappingElement & | m_mappingElement |
Reflex::Type | m_objectType |
DataElement * | m_offset |
std::auto_ptr < MultiRecordSelectOperation > | m_query |
std::vector< int > | m_recordId |
ContainerSchema & | m_schema |
Definition at line 72 of file CArrayStreamer.h.
ora::CArrayReader::CArrayReader | ( | const Reflex::Type & | objectType, |
MappingElement & | mapping, | ||
ContainerSchema & | contSchema | ||
) |
Constructor.
Definition at line 170 of file CArrayStreamer.cc.
: m_objectType( objectType ), m_mappingElement( mapping ), m_schema( contSchema ), m_recordId(), m_localElement( ), m_offset(0 ), m_query(), m_arrayHandler(), m_dataReader(){ }
ora::CArrayReader::~CArrayReader | ( | ) | [virtual] |
Definition at line 184 of file CArrayStreamer.cc.
{ }
bool ora::CArrayReader::build | ( | DataElement & | offset, |
IRelationalData & | relationalData | ||
) | [virtual] |
Implements ora::IRelationalReader.
Definition at line 187 of file CArrayStreamer.cc.
References i, ora::ArrayHandlerFactory::newArrayHandler(), ora::RelationalStreamerFactory::newReader(), 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) + "\"", "CArrayReader::build" ); } RelationalStreamerFactory streamerFactory( m_schema ); // first open the insert on the extra table... m_query.reset(new MultiRecordSelectOperation( m_mappingElement.tableName(), m_schema.storageSchema() )); m_query->addWhereId( m_mappingElement.pkColumn() ); std::vector<std::string> recIdCols = m_mappingElement.recordIdColumns(); for( size_t i=0; i<recIdCols.size(); i++ ){ m_query->addId( recIdCols[ i ] ); m_query->addOrderId( recIdCols[ 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", "CArrayReader::build" ); } m_dataReader.reset( streamerFactory.newReader( arrayResolvedType, iMe->second ) ); m_dataReader->build( m_localElement, *m_query ); return true; }
void ora::CArrayReader::clear | ( | void | ) | [virtual] |
Implements ora::IRelationalReader.
Definition at line 309 of file CArrayStreamer.cc.
{ if(m_dataReader.get()) m_dataReader->clear(); }
void ora::CArrayReader::read | ( | void * | address | ) | [virtual] |
Reads a data element.
Implements ora::IRelationalReader.
Definition at line 255 of file CArrayStreamer.cc.
References i, and ora::throwException().
{ if(!m_offset){ throwException("The streamer has not been built.", "CArrayReader::read"); } void* address = m_offset->address( destinationData ); Reflex::Type iteratorDereferenceReturnType = m_arrayHandler->iteratorReturnType(); bool isElementFundamental = iteratorDereferenceReturnType.IsFundamental(); std::string positionColumn = m_mappingElement.posColumn(); size_t arraySize = m_objectType.ArrayLength(); m_arrayHandler->clear( address ); size_t cursorSize = m_query->selectionSize(m_recordId, m_recordId.size()-1); unsigned int i=0; while ( i< cursorSize ){ m_recordId[m_recordId.size()-1] = (int)i; m_query->selectRow( m_recordId ); coral::AttributeList& row = m_query->data(); int arrayIndex = row[positionColumn].data< int >(); // Create a new element for the array void* objectData = 0; if(arrayIndex >= (int)arraySize){ throwException("Found more element then array size.", "CArrayReader::read"); } // the memory has been allocated already! objectData = static_cast<char*>(address)+arrayIndex*iteratorDereferenceReturnType.SizeOf(); if(!isElementFundamental){ // in this case the initialization is required: use default constructor... iteratorDereferenceReturnType.Construct(Reflex::Type(0,0),std::vector< void* >(),objectData); } m_dataReader->setRecordId( m_recordId ); m_dataReader->read( objectData ); ++i; } m_arrayHandler->finalize( address ); }
void ora::CArrayReader::select | ( | int | oid | ) | [virtual] |
Implements ora::IRelationalReader.
Definition at line 235 of file CArrayStreamer.cc.
References ora::throwException().
{ if(!m_query.get()){ throwException("The streamer has not been built.", "CArrayReader::select"); } coral::AttributeList& whereData = m_query->whereData(); whereData[ m_mappingElement.pkColumn() ].data<int>() = oid; m_query->execute(); m_dataReader->select( oid ); }
void ora::CArrayReader::setRecordId | ( | const std::vector< int > & | identity | ) | [virtual] |
Implements ora::IRelationalReader.
Definition at line 246 of file CArrayStreamer.cc.
References i.
{ m_recordId.clear(); for(size_t i=0;i<identity.size();i++) { m_recordId.push_back( identity[i] ); } // allocate the element for the index... m_recordId.push_back( 0 ); }
std::auto_ptr<IArrayHandler> ora::CArrayReader::m_arrayHandler [private] |
Definition at line 102 of file CArrayStreamer.h.
std::auto_ptr<IRelationalReader> ora::CArrayReader::m_dataReader [private] |
Definition at line 103 of file CArrayStreamer.h.
DataElement ora::CArrayReader::m_localElement [private] |
Definition at line 97 of file CArrayStreamer.h.
Definition at line 94 of file CArrayStreamer.h.
Reflex::Type ora::CArrayReader::m_objectType [private] |
Definition at line 93 of file CArrayStreamer.h.
DataElement* ora::CArrayReader::m_offset [private] |
Definition at line 100 of file CArrayStreamer.h.
std::auto_ptr<MultiRecordSelectOperation> ora::CArrayReader::m_query [private] |
Definition at line 101 of file CArrayStreamer.h.
std::vector<int> ora::CArrayReader::m_recordId [private] |
Definition at line 96 of file CArrayStreamer.h.
ContainerSchema& ora::CArrayReader::m_schema [private] |
Definition at line 95 of file CArrayStreamer.h.