CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
ora::OraReferenceStreamerBase Class Reference

#include <OraReferenceStreamer.h>

Inheritance diagram for ora::OraReferenceStreamerBase:
ora::OraReferenceReader ora::OraReferenceUpdater ora::OraReferenceWriter

Public Member Functions

void bindDataForRead (void *data)
 
void bindDataForUpdate (const void *data)
 
bool buildDataElement (DataElement &dataElement, IRelationalData &relationalData)
 
 OraReferenceStreamerBase (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
 
virtual ~OraReferenceStreamerBase ()
 

Private Attributes

const std::vector< std::string > & m_columns
 
DataElementm_dataElement
 
DataElementm_dataElemOId0
 
DataElementm_dataElemOId1
 
Reflex::Type m_objectType
 
IRelationalDatam_relationalData
 
ContainerSchemam_schema
 

Detailed Description

Definition at line 13 of file OraReferenceStreamer.h.

Constructor & Destructor Documentation

ora::OraReferenceStreamerBase::OraReferenceStreamerBase ( const Reflex::Type &  objectType,
MappingElement mapping,
ContainerSchema schema 
)
explicit

Definition at line 14 of file OraReferenceStreamer.cc.

16  :
17  m_objectType( objectType ),
18  m_columns( mapping.columnNames() ),
19  m_schema( schema ),
20  m_dataElement( 0 ),
21  m_dataElemOId0( 0 ),
22  m_dataElemOId1( 0 ),
23  m_relationalData( 0 ){
24 }
const std::vector< std::string > & m_columns
ora::OraReferenceStreamerBase::~OraReferenceStreamerBase ( )
virtual

Definition at line 26 of file OraReferenceStreamer.cc.

26  {
27 }

Member Function Documentation

void ora::OraReferenceStreamerBase::bindDataForRead ( void *  data)

Definition at line 84 of file OraReferenceStreamer.cc.

References ora::IReferenceHandler::onLoad(), and ora::throwException().

84  {
85  if(!m_relationalData){
86  throwException("The streamer has not been built.",
87  "OraReferenceStreamerBase::bindDataForRead");
88  }
89  if( m_columns.size()<2 ){
90  throwException("Expected column names have not been found in the mapping.",
91  "OraReferenceStreamerBase::bindDataForRead");
92  }
93  void* oid0Address = m_dataElemOId0->address( data );
94  coral::Attribute& oid0Attr = m_relationalData->data()[ m_columns[0] ];
95  *static_cast<int*>(oid0Address) = oid0Attr.data<int>();
96  void* oid1Address = m_dataElemOId1->address( data );
97  coral::Attribute& oid1Attr = m_relationalData->data()[ m_columns[1] ];
98  *static_cast<int*>( oid1Address ) = oid1Attr.data<int>();
99  IReferenceHandler* refHandler = m_schema.referenceHandler();
100  void* refPtr = m_dataElement->address( data );
101  if(refHandler) refHandler->onLoad( *static_cast<Reference*>( refPtr ) );
102 }
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:48
IReferenceHandler * referenceHandler()
virtual coral::AttributeList & data()=0
const std::vector< std::string > & m_columns
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::OraReferenceStreamerBase::bindDataForUpdate ( const void *  data)

Definition at line 67 of file OraReferenceStreamer.cc.

References ora::IReferenceHandler::onSave(), and ora::throwException().

67  {
68  if(!m_relationalData){
69  throwException("The streamer has not been built.",
70  "OraReferenceStreamerBase::bindDataForUpdate");
71  }
72 
73  void* oid0Address = m_dataElemOId0->address( data );
74  coral::Attribute& oid0Attr = m_relationalData->data()[ m_columns[0] ];
75  oid0Attr.data<int>()= *static_cast<int*>(oid0Address);
76  void* oid1Address = m_dataElemOId1->address( data );
77  coral::Attribute& oid1Attr = m_relationalData->data()[ m_columns[1] ];
78  oid1Attr.data<int>()= *static_cast<int*>(oid1Address) ;
79  IReferenceHandler* refHandler = m_schema.referenceHandler();
80  void* refPtr = m_dataElement->address( data );
81  if(refHandler) refHandler->onSave( *static_cast<Reference*>( refPtr ) );
82 }
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:48
IReferenceHandler * referenceHandler()
virtual coral::AttributeList & data()=0
const std::vector< std::string > & m_columns
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
bool ora::OraReferenceStreamerBase::buildDataElement ( DataElement dataElement,
IRelationalData relationalData 
)

Definition at line 30 of file OraReferenceStreamer.cc.

References ora::DataElement::addChild(), ora::IRelationalData::addData(), ora::ClassUtils::findBaseType(), and ora::throwException().

31  {
32  m_dataElement = &dataElement;
33  // first resolve the oid0 and oid2 data elements...
34  Reflex::Type refType = Reflex::Type::ByTypeInfo( typeid(Reference) );
35  //Reflex::Type oidType = Reflex::Type::ByTypeInfo( typeid(OId) );
36  Reflex::OffsetFunction baseOffsetFunc = 0;
37  if( m_objectType != refType ){
38  bool foundRef = ClassUtils::findBaseType( m_objectType, refType, baseOffsetFunc );
39  if(!foundRef){
40  throwException("Type \""+m_objectType.Name(Reflex::SCOPED)+"\" is not an Ora Reference.",
41  "OraReferenceStreamerBase::buildDataElement");
42  }
43  }
44  Reflex::Member contIdMember = refType.DataMemberByName("m_containerId");
45  Reflex::Member itemIdMember = refType.DataMemberByName("m_itemId");
46  if( !contIdMember || !itemIdMember ){
47  throwException("Data members for class OId not found.",
48  "OraReferenceStreamerBase::buildDataElement");
49  }
50  m_dataElemOId0 = &dataElement.addChild( contIdMember.Offset(), baseOffsetFunc );
51  m_dataElemOId1 = &dataElement.addChild( itemIdMember.Offset(), baseOffsetFunc);
52  // then book the columns in the data attribute...
53  if( m_columns.size()<2 ){
54  throwException("Expected column names have not been found in the mapping.",
55  "OraReferenceStreamerBase::buildDataElement");
56  }
57  const std::type_info& attrType = typeid(int);
58  for( std::vector<std::string>::const_iterator iCol = m_columns.begin();
59  iCol != m_columns.end(); ++iCol ){
60  relationalData.addData( *iCol, attrType );
61  }
62  m_relationalData = &relationalData;
63  return true;
64 }
DataElement & addChild(size_t declaringScopeOffset, Reflex::OffsetFunction offsetFunction)
Definition: DataElement.cc:26
bool findBaseType(Reflex::Type &type, Reflex::Type &baseType, Reflex::OffsetFunction &func)
Definition: ClassUtils.cc:58
const std::vector< std::string > & m_columns
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10

Member Data Documentation

const std::vector<std::string>& ora::OraReferenceStreamerBase::m_columns
private

Definition at line 30 of file OraReferenceStreamer.h.

DataElement* ora::OraReferenceStreamerBase::m_dataElement
private

Definition at line 32 of file OraReferenceStreamer.h.

DataElement* ora::OraReferenceStreamerBase::m_dataElemOId0
private

Definition at line 33 of file OraReferenceStreamer.h.

DataElement* ora::OraReferenceStreamerBase::m_dataElemOId1
private

Definition at line 34 of file OraReferenceStreamer.h.

Reflex::Type ora::OraReferenceStreamerBase::m_objectType
private

Definition at line 29 of file OraReferenceStreamer.h.

IRelationalData* ora::OraReferenceStreamerBase::m_relationalData
private

Definition at line 35 of file OraReferenceStreamer.h.

ContainerSchema& ora::OraReferenceStreamerBase::m_schema
private

Definition at line 31 of file OraReferenceStreamer.h.