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

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 170 of file UniqueRefStreamer.cc.

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

Definition at line 186 of file UniqueRefStreamer.cc.

                                    {
}

Member Function Documentation

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

Implements ora::IRelationalWriter.

Definition at line 189 of file UniqueRefStreamer.cc.

References ora::IRelationalData::addData().

                                                          {
  m_dataElement = &dataElement;

  const std::vector<std::string>& columns = m_mappingElement.columnNames();
  // booking for ref metadata 
  relationalData.addData( columns[0],typeid(std::string) );
  // booking for ref id 
  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 204 of file UniqueRefStreamer.cc.

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

Writes a data element.

Implements ora::IRelationalWriter.

Definition at line 208 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);

    // getting a new valid ref id
    refId = m_schema.containerSequences().getNextId( MappingRules::sequenceNameForDependentClass( m_schema.containerName(),className ));
    
    // building the dependent buffer
    MappingElement& depMapping =  m_schema.mappingForDependentClass( refType, true );    

    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_mappingElement.columnNames()[0]].data<std::string>()=className;
  parentData[m_mappingElement.columnNames()[1]].data<int>()=refId;
}

Member Data Documentation

Definition at line 43 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 45 of file UniqueRefStreamer.h.

Definition at line 44 of file UniqueRefStreamer.h.

Definition at line 42 of file UniqueRefStreamer.h.