CMS 3D CMS Logo

Public Member Functions | Private Attributes

ora::UniqueRefWriter Class Reference

#include <UniqueRefStreamer.h>

Inheritance diagram for ora::UniqueRefWriter:
ora::IRelationalWriter

List of all members.

Public Member Functions

bool build (DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
void setRecordId (const std::vector< int > &identity)
 UniqueRefWriter (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
void write (int oid, const void *data)
 Writes a data element.
virtual ~UniqueRefWriter ()

Private Attributes

int m_columnIndexes [2]
DataElementm_dataElement
MappingElementm_mappingElement
Reflex::Type m_objectType
RelationalBufferm_operationBuffer
IRelationalDatam_relationalData
ContainerSchemam_schema

Detailed Description

Definition at line 23 of file UniqueRefStreamer.h.


Constructor & Destructor Documentation

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

Definition at line 171 of file UniqueRefStreamer.cc.

References m_columnIndexes.

                                                                    :
  m_objectType( objectType ),
  m_mappingElement( mapping ),
  m_schema( contSchema ),
  m_dataElement( 0 ),
  m_relationalData( 0 ),
  m_operationBuffer( 0 ){
  m_columnIndexes[0]=-1;  
  m_columnIndexes[1]=-1;  
}
ora::UniqueRefWriter::~UniqueRefWriter ( ) [virtual]

Definition at line 189 of file UniqueRefStreamer.cc.

                                    {
}

Member Function Documentation

bool ora::UniqueRefWriter::build ( DataElement dataElement,
IRelationalData relationalData,
RelationalBuffer operationBuffer 
) [virtual]

Implements ora::IRelationalWriter.

Definition at line 192 of file UniqueRefStreamer.cc.

References ora::IRelationalData::addData(), and ora::throwException().

                                                          {
  m_dataElement = &dataElement;

  const std::vector<std::string>& columns = m_mappingElement.columnNames();
  if( columns.size() < 2 ){
    throwException("Expected column names have not been found in the mapping.",
                   "UniqueRefWriter::build");    
  }
  // booking for ref metadata 
  m_columnIndexes[0] = relationalData.addData( columns[0],typeid(std::string) );
  // booking for ref id 
  m_columnIndexes[1] = relationalData.addData( columns[1],typeid(int) );
  m_relationalData = &relationalData;
  m_operationBuffer = &buffer;
  return true;
}
void ora::UniqueRefWriter::setRecordId ( const std::vector< int > &  identity) [virtual]

Implements ora::IRelationalWriter.

Definition at line 211 of file UniqueRefStreamer.cc.

                                                           {
}
void ora::UniqueRefWriter::write ( int  oid,
const void *  data 
) [virtual]

Writes a data element.

Implements ora::IRelationalWriter.

Definition at line 215 of file UniqueRefStreamer.cc.

References ora::DependentClassWriter::build(), className(), ora::ClassUtils::lookupDictionary(), ora::MappingRules::sequenceNameForDependentClass(), ora::throwException(), ora::uniqueRefNullLabel(), and ora::DependentClassWriter::write().

                                                    {

  if(!m_dataElement){
    throwException("The streamer has not been built.",
                   "UniqueRefWriter::write");
  }

  void* refAddress = m_dataElement->address( data );

  Reflex::Object refObj( m_objectType, const_cast<void*>(refAddress));

  bool isNull;
  refObj.Invoke("operator!",isNull);

  int refId = 0;
  std::string className = uniqueRefNullLabel();

  if(!isNull){
    // resolving the ref type
    std::type_info* refTypeInfo = 0;
    refObj.Invoke("typeInfo",refTypeInfo);
    Reflex::Type refType = ClassUtils::lookupDictionary(*refTypeInfo);
    className = refType.Name(Reflex::SCOPED);

    // building the dependent buffer
    MappingElement& depMapping =  m_schema.mappingForDependentClass( refType, true );    

    // getting a new valid ref id
    refId = m_schema.containerSequences().getNextId( MappingRules::sequenceNameForDependentClass( m_schema.containerName(),className ));
    
    DependentClassWriter writer;
    writer.build( refType, depMapping, m_schema, m_operationBuffer->addVolatileBuffer() );
    void* refData;
    refObj.Invoke("operator*",refData);
    writer.write( oid, refId, refData );

  }
  // writing in the parent table
  coral::AttributeList& parentData = m_relationalData->data();
  parentData[m_columnIndexes[0]].data<std::string>()=className;
  parentData[m_columnIndexes[1]].data<int>()=refId;
}

Member Data Documentation

Definition at line 42 of file UniqueRefStreamer.h.

Referenced by UniqueRefWriter().

Definition at line 44 of file UniqueRefStreamer.h.

Definition at line 41 of file UniqueRefStreamer.h.

Reflex::Type ora::UniqueRefWriter::m_objectType [private]

Definition at line 40 of file UniqueRefStreamer.h.

Definition at line 46 of file UniqueRefStreamer.h.

Definition at line 45 of file UniqueRefStreamer.h.

Definition at line 43 of file UniqueRefStreamer.h.