CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OraReferenceStreamer.cc
Go to the documentation of this file.
4 #include "OraReferenceStreamer.h"
5 #include "DataElement.h"
6 #include "MappingElement.h"
7 #include "ContainerSchema.h"
8 #include "RelationalOperation.h"
9 #include "ClassUtils.h"
10 // externals
11 #include "CoralBase/Attribute.h"
12 #include "Reflex/Member.h"
13 
15  MappingElement& mapping,
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 }
25 
27 }
28 
29 
31  IRelationalData& relationalData){
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 }
65 
66 
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 }
83 
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 }
103 
105  MappingElement& mapping,
107  OraReferenceStreamerBase( objectType, mapping, schema ){
108 }
109 
111 }
112 
114  IRelationalData& relationalData,
116  return buildDataElement( dataElement, relationalData );
117 }
118 
119 void ora::OraReferenceWriter::setRecordId( const std::vector<int>& ){
120 }
121 
123  const void* data ){
124  bindDataForUpdate( data );
125 }
126 
128  MappingElement& mapping,
130  OraReferenceStreamerBase( objectType, mapping, schema ){
131 }
132 
134 }
135 
137  IRelationalData& relationalData,
139  return buildDataElement( dataElement, relationalData );
140 }
141 
142 void ora::OraReferenceUpdater::setRecordId( const std::vector<int>& ){
143 }
144 
146  const void* data ){
147  bindDataForUpdate( data );
148 }
149 
151  MappingElement& mapping,
153  OraReferenceStreamerBase( objectType, mapping, schema ){
154 }
155 
157 }
158 
160  IRelationalData& relationalData){
161  return buildDataElement( dataElement, relationalData );
162 }
163 
165 }
166 
167 void ora::OraReferenceReader::setRecordId( const std::vector<int>& ){
168 }
169 
171  bindDataForRead( data );
172 }
173 
175 }
176 
177 
179  MappingElement& mapping,
181  m_objectType( objectType ),
182  m_mapping( mapping ),
183  m_schema( schema ){
184 }
185 
187 }
188 
190  return new OraReferenceWriter( m_objectType, m_mapping, m_schema );
191 }
192 
194  return new OraReferenceUpdater( m_objectType, m_mapping, m_schema );
195 }
196 
198  return new OraReferenceReader( m_objectType, m_mapping, m_schema );
199 }
bool build(DataElement &dataElement, IRelationalData &relationalData)
OraReferenceUpdater(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
void write(int oid, const void *data)
Writes a data element.
virtual bool onLoad(ora::Reference &ref)=0
IRelationalWriter * newWriter()
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
OraReferenceStreamer(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
void setRecordId(const std::vector< int > &identity)
OraReferenceStreamerBase(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
virtual bool onSave(ora::Reference &ref)=0
bool buildDataElement(DataElement &dataElement, IRelationalData &relationalData)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
void read(void *data)
Reads a data element.
void setRecordId(const std::vector< int > &identity)
void update(int oid, const void *data)
Updates a data element.
OraReferenceReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
void setRecordId(const std::vector< int > &identity)
void bindDataForUpdate(const void *data)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
OraReferenceWriter(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &schema)
IRelationalUpdater * newUpdater()
virtual void addData(const std::string &columnName, const std::type_info &columnType)=0
IRelationalReader * newReader()