CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NamedRefStreamer.cc
Go to the documentation of this file.
3 #include "NamedRefStreamer.h"
4 #include "RelationalOperation.h"
5 #include "MappingElement.h"
6 #include "ContainerSchema.h"
7 #include "DatabaseSession.h"
8 #include "ClassUtils.h"
10 // externals
11 #include "CoralBase/Attribute.h"
13 
15  static const std::string nullLabel("ora::NamedRef::Null");
16  return nullLabel;
17 }
18 
20  MappingElement& mapping,
22  m_objectType( objectType ),
23  m_mapping( mapping ),
24  m_columnIndex( -1 ),
25  m_schema( schema ),
26  m_dataElement( 0 ),
27  m_refNameDataElement( 0 ),
28  m_ptrDataElement( 0 ),
29  m_flagDataElement( 0 ),
30  m_relationalData( 0 ){
31 }
32 
34 }
35 
36 
38  IRelationalData& relationalData){
39  m_dataElement = &dataElement;
40  //-ap m_objectType.UpdateMembers();
41  edm::MemberWithDict nameMember = m_objectType.dataMemberByName("m_name");
42  if( !nameMember ){
43  throwException("Data member \"m_name\" not found in class \""+m_objectType.name()+"\".",
44  "NamedReferenceStreamerBase::buildDataElement");
45  }
46  m_refNameDataElement = &dataElement.addChild( nameMember.offset(), 0 );
47  edm::MemberWithDict ptrMember = m_objectType.dataMemberByName("m_ptr");
48  if( !ptrMember ){
49  throwException("Data member \"m_ptr\" not found in class \""+m_objectType.name()+"\".",
50  "NamedReferenceStreamerBase::buildDataElement");
51  }
52  m_ptrDataElement = &dataElement.addChild( ptrMember.offset(), 0 );
53  edm::MemberWithDict flagMember = m_objectType.dataMemberByName("m_isPersistent");
54  if( !flagMember ){
55  throwException("Data member \"m_isPersistent\" not found in class \""+m_objectType.name()+"\".",
56  "NamedReferenceStreamerBase::buildDataElement");
57  }
58  m_flagDataElement = &dataElement.addChild( flagMember.offset(), 0 );
59  // then book the column in the data attribute...
60  const std::vector<std::string>& columns = m_mapping.columnNames();
61  if( columns.size()==0 ){
62  throwException("No columns found in the mapping element",
63  "NamedReferenceStreamerBase::buildDataElement");
64  }
65  m_columnIndex = relationalData.addData( columns[0], typeid(std::string) );
66  m_relationalData = &relationalData;
67  return true;
68 }
69 
71  if(!m_relationalData){
72  throwException("The streamer has not been built.",
73  "NamedReferenceStreamerBase::bindDataForUpdate");
74  }
75 
76  void* refNameAddress = m_refNameDataElement->address( data );
77  coral::Attribute& refNameAttr = m_relationalData->data()[ m_columnIndex ];
78  std::string name = *static_cast<std::string*>(refNameAddress);
79  if( name.empty() ) name = namedRefNullLabel();
80  refNameAttr.data<std::string>()= name;
81 }
82 
84  if(!m_relationalData){
85  throwException("The streamer has not been built.",
86  "NamedReferenceStreamerBase::bindDataForRead");
87  }
88  void* refNameAddress = m_refNameDataElement->address( data );
89  void* ptrAddress = m_ptrDataElement->address( data );
90  void* flagAddress = m_flagDataElement->address( data );
91  coral::Attribute& refNameAttr = m_relationalData->data()[ m_columnIndex ];
92  std::string name = refNameAttr.data<std::string>();
93  if( name == namedRefNullLabel() ){
94  name = std::string("");
95  }
96  if(!name.empty()){
97  edm::TypeWithDict namedRefType = m_objectType.templateArgumentAt(0);
98  boost::shared_ptr<void> ptr = m_schema.dbSession().fetchTypedObjectByName( name, namedRefType );
99  *static_cast<boost::shared_ptr<void>*>(ptrAddress) = ptr;
100  *static_cast<bool*>(flagAddress) = true;
101  }
102  *static_cast<std::string*>(refNameAddress) = name;
103 }
104 
106  MappingElement& mapping,
107  ContainerSchema& contSchema ):
108  NamedReferenceStreamerBase( objectType, mapping, contSchema ){
109 }
110 
112 }
113 
115  IRelationalData& relationalData,
116  RelationalBuffer& operationBuffer){
117  return buildDataElement( dataElement, relationalData );
118 }
119 
120 void ora::NamedRefWriter::setRecordId( const std::vector<int>& identity ){
121 }
122 
125  const void* data ){
126  bindDataForUpdate( data );
127 }
128 
130  MappingElement& mapping,
131  ContainerSchema& contSchema ):
132  NamedReferenceStreamerBase( objectType, mapping, contSchema ){
133 }
134 
136 }
137 
139  IRelationalData& relationalData,
140  RelationalBuffer& operationBuffer){
141  return buildDataElement( dataElement, relationalData );
142 }
143 
144 void ora::NamedRefUpdater::setRecordId( const std::vector<int>& identity ){
145 }
146 
149  const void* data ){
150  bindDataForUpdate( data );
151 }
152 
154  MappingElement& mapping,
155  ContainerSchema& contSchema ):
156  NamedReferenceStreamerBase( objectType, mapping, contSchema ){
157 }
158 
160 }
161 
163  IRelationalData& relationalData ){
164  return buildDataElement( dataElement, relationalData );
165 }
166 
168 }
169 
170 void ora::NamedRefReader::setRecordId( const std::vector<int>& identity ){
171 }
172 
175  bindDataForRead( data );
176 }
177 
179 }
180 
181 
183  MappingElement& mapping,
184  ContainerSchema& contSchema ):
185  m_objectType( objectType ),
186  m_mapping( mapping ),
187  m_schema( contSchema ){
188 }
189 
191 }
192 
194  return new NamedRefWriter( m_objectType, m_mapping, m_schema );
195 }
196 
198  return new NamedRefUpdater( m_objectType, m_mapping, m_schema );
199 }
200 
202  return new NamedRefReader( m_objectType, m_mapping, m_schema );
203 }
204 
void update(int oid, const void *data)
Updates a data element.
std::string namedRefNullLabel()
void read(void *destination)
Reads a data element.
NamedRefStreamer(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
void bindDataForUpdate(const void *data)
void setRecordId(const std::vector< int > &identity)
size_t offset() const
virtual int addData(const std::string &columnName, const std::type_info &columnType)=0
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
IRelationalUpdater * newUpdater()
TypeWithDict templateArgumentAt(size_t index) const
bool build(DataElement &offset, IRelationalData &relationalData)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
NamedRefUpdater(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
NamedRefWriter(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
DataElement & addChild(size_t declaringScopeOffset, size_toffset)
Definition: DataElement.cc:27
IRelationalWriter * newWriter()
void write(int oid, const void *data)
Writes a data element.
IRelationalReader * newReader()
bool buildDataElement(DataElement &dataElement, IRelationalData &relationalData)
NamedRefReader(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
void setRecordId(const std::vector< int > &identity)
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
void setRecordId(const std::vector< int > &identity)
NamedReferenceStreamerBase(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &schema)