CMS 3D CMS Logo

Public Member Functions | Private Attributes

ora::CArrayWriter Class Reference

#include <CArrayStreamer.h>

Inheritance diagram for ora::CArrayWriter:
ora::IRelationalWriter

List of all members.

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< 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.

                                                              :
  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.

                              {
}

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().

                                                                  {

  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 AlCaHLTBitMon_QueryRunRegistry::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  );
  size_t persistentSize = m_arrayHandler->persistentSize( data  );
  
  if ( containerSize == 0 || containerSize < persistentSize ) 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 ) );
  
}

Member Data Documentation

Definition at line 45 of file CArrayStreamer.h.

Definition at line 46 of file CArrayStreamer.h.

Definition at line 44 of file CArrayStreamer.h.

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.

Definition at line 43 of file CArrayStreamer.h.

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

Definition at line 39 of file CArrayStreamer.h.

Definition at line 38 of file CArrayStreamer.h.