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"
13 
15  MappingElement& mapping,
17  m_objectType( objectType ),
18  m_mapping( mapping ),
19  m_schema( schema ),
20  m_dataElement( 0 ),
21  m_dataElemOId0( 0 ),
22  m_dataElemOId1( 0 ),
23  m_relationalData( 0 ){
24  m_columnIndexes[0] = -1;
25  m_columnIndexes[1] = -1;
26 }
27 
29 }
30 
31 
33  IRelationalData& relationalData){
34  m_dataElement = &dataElement;
35  // first resolve the oid0 and oid2 data elements...
36  edm::TypeWithDict refType( typeid(Reference) );
37  //edm::TypeWithDict oidType = edm::TypeWithDict::ByTypeInfo( typeid(OId) );
38  size_t baseOffsetFunc = 0;
39  if( m_objectType != refType ){
40  bool foundRef = ClassUtils::findBaseType( m_objectType, refType, baseOffsetFunc );
41  if(!foundRef){
42  throwException("Type \""+m_objectType.cppName()+"\" is not an Ora Reference.",
43  "OraReferenceStreamerBase::buildDataElement");
44  }
45  }
46  edm::MemberWithDict contIdMember = refType.dataMemberByName("m_containerId");
47  edm::MemberWithDict itemIdMember = refType.dataMemberByName("m_itemId");
48  if( !contIdMember || !itemIdMember ){
49  throwException("Data members for class OId not found.",
50  "OraReferenceStreamerBase::buildDataElement");
51  }
52  m_dataElemOId0 = &dataElement.addChild( contIdMember.offset(), baseOffsetFunc );
53  m_dataElemOId1 = &dataElement.addChild( itemIdMember.offset(), baseOffsetFunc);
54  // then book the columns in the data attribute...
55  const std::vector<std::string>& columns = m_mapping.columnNames();
56  if( columns.size() < 2 ){
57  throwException("Expected column names have not been found in the mapping.",
58  "OraReferenceStreamerBase::buildDataElement");
59  }
60  const std::type_info& attrType = typeid(int);
61  for( size_t i=0; i<2; i++ ){
62  m_columnIndexes[i] = relationalData.addData( columns[i],attrType );
63  }
64  m_relationalData = &relationalData;
65  return true;
66 }
67 
68 
70  if(!m_relationalData){
71  throwException("The streamer has not been built.",
72  "OraReferenceStreamerBase::bindDataForUpdate");
73  }
74 
75  void* oid0Address = m_dataElemOId0->address( data );
76  coral::Attribute& oid0Attr = m_relationalData->data()[ m_columnIndexes[0] ];
77  oid0Attr.data<int>()= *static_cast<int*>(oid0Address);
78  void* oid1Address = m_dataElemOId1->address( data );
79  coral::Attribute& oid1Attr = m_relationalData->data()[ m_columnIndexes[1] ];
80  oid1Attr.data<int>()= *static_cast<int*>(oid1Address) ;
81  IReferenceHandler* refHandler = m_schema.referenceHandler();
82  void* refPtr = m_dataElement->address( data );
83  if(refHandler) refHandler->onSave( *static_cast<Reference*>( refPtr ) );
84 }
85 
87  if(!m_relationalData){
88  throwException("The streamer has not been built.",
89  "OraReferenceStreamerBase::bindDataForRead");
90  }
91 
92  void* oid0Address = m_dataElemOId0->address( data );
93  coral::Attribute& oid0Attr = m_relationalData->data()[ m_columnIndexes[0] ];
94  *static_cast<int*>(oid0Address) = oid0Attr.data<int>();
95  void* oid1Address = m_dataElemOId1->address( data );
96  coral::Attribute& oid1Attr = m_relationalData->data()[ m_columnIndexes[1] ];
97  *static_cast<int*>( oid1Address ) = oid1Attr.data<int>();
98  IReferenceHandler* refHandler = m_schema.referenceHandler();
99  void* refPtr = m_dataElement->address( data );
100  if(refHandler) refHandler->onLoad( *static_cast<Reference*>( refPtr ) );
101 }
102 
104  MappingElement& mapping,
106  OraReferenceStreamerBase( objectType, mapping, schema ){
107 }
108 
110 }
111 
113  IRelationalData& relationalData,
115  return buildDataElement( dataElement, relationalData );
116 }
117 
118 void ora::OraReferenceWriter::setRecordId( const std::vector<int>& ){
119 }
120 
122  const void* data ){
123  bindDataForUpdate( data );
124 }
125 
127  MappingElement& mapping,
129  OraReferenceStreamerBase( objectType, mapping, schema ){
130 }
131 
133 }
134 
136  IRelationalData& relationalData,
138  return buildDataElement( dataElement, relationalData );
139 }
140 
141 void ora::OraReferenceUpdater::setRecordId( const std::vector<int>& ){
142 }
143 
145  const void* data ){
146  bindDataForUpdate( data );
147 }
148 
150  MappingElement& mapping,
152  OraReferenceStreamerBase( objectType, mapping, schema ){
153 }
154 
156 }
157 
159  IRelationalData& relationalData){
160  return buildDataElement( dataElement, relationalData );
161 }
162 
164 }
165 
166 void ora::OraReferenceReader::setRecordId( const std::vector<int>& ){
167 }
168 
170  bindDataForRead( data );
171 }
172 
174 }
175 
176 
178  MappingElement& mapping,
180  m_objectType( objectType ),
181  m_mapping( mapping ),
182  m_schema( schema ){
183 }
184 
186 }
187 
189  return new OraReferenceWriter( m_objectType, m_mapping, m_schema );
190 }
191 
193  return new OraReferenceUpdater( m_objectType, m_mapping, m_schema );
194 }
195 
197  return new OraReferenceReader( m_objectType, m_mapping, m_schema );
198 }
int i
Definition: DBlmapReader.cc:9
bool build(DataElement &dataElement, IRelationalData &relationalData)
void write(int oid, const void *data)
Writes a data element.
OraReferenceWriter(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &schema)
tuple schema
Definition: dataDML.py:2334
OraReferenceUpdater(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &schema)
virtual bool onLoad(ora::Reference &ref)=0
size_t offset() const
virtual int addData(const std::string &columnName, const std::type_info &columnType)=0
IRelationalWriter * newWriter()
OraReferenceStreamer(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &schema)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
MemberWithDict dataMemberByName(std::string const &) const
void setRecordId(const std::vector< int > &identity)
OraReferenceStreamerBase(const edm::TypeWithDict &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.
DataElement & addChild(size_t declaringScopeOffset, size_toffset)
Definition: DataElement.cc:27
OraReferenceReader(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &schema)
void setRecordId(const std::vector< int > &identity)
bool findBaseType(edm::TypeWithDict &type, edm::TypeWithDict &baseType, size_t &func)
Definition: ClassUtils.cc:136
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
tuple columns
Definition: mps_check.py:210
void bindDataForUpdate(const void *data)
IRelationalUpdater * newUpdater()
IRelationalReader * newReader()