CMS 3D CMS Logo

Public Member Functions | Private Attributes

ora::CArrayReader Class Reference

#include <CArrayStreamer.h>

Inheritance diagram for ora::CArrayReader:
ora::IRelationalReader

List of all members.

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< IArrayHandlerm_arrayHandler
std::auto_ptr< IRelationalReaderm_dataReader
DataElement m_localElement
MappingElementm_mappingElement
Reflex::Type m_objectType
DataElementm_offset
std::auto_ptr
< MultiRecordSelectOperation
m_query
std::vector< int > m_recordId
ContainerSchemam_schema

Detailed Description

Definition at line 72 of file CArrayStreamer.h.


Constructor & Destructor Documentation

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

Constructor.

Definition at line 169 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 183 of file CArrayStreamer.cc.

                              {
}

Member Function Documentation

bool ora::CArrayReader::build ( DataElement offset,
IRelationalData relationalData 
) [virtual]

Implements ora::IRelationalReader.

Definition at line 186 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 308 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 254 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 234 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 245 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 );
}

Member Data Documentation

Definition at line 102 of file CArrayStreamer.h.

Definition at line 103 of file CArrayStreamer.h.

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.

Definition at line 100 of file CArrayStreamer.h.

Definition at line 101 of file CArrayStreamer.h.

std::vector<int> ora::CArrayReader::m_recordId [private]

Definition at line 96 of file CArrayStreamer.h.

Definition at line 95 of file CArrayStreamer.h.