CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrimitiveStreamer.cc
Go to the documentation of this file.
2 #include "PrimitiveStreamer.h"
3 #include "DataElement.h"
4 #include "MappingElement.h"
5 #include "RelationalOperation.h"
6 #include "ClassUtils.h"
7 // externals
8 #include "CoralBase/Attribute.h"
9 
10 
12  MappingElement& mapping ):
13  m_objectType( objectType ),
14  m_mapping(mapping),
15  m_columnIndex(-1),
16  m_dataElement( 0 ),
17  m_relationalData( 0 ){
18 }
19 
21 }
22 
24  IRelationalData& relationalData){
25  if( m_mapping.columnNames().size()==0 ){
26  throwException( "The mapping element does not contain columns.",
27  "PrimitiveStreamerBase::buildDataElement");
28  }
29 
30  const std::type_info* attrType = &m_objectType.TypeInfo();
31  if(m_objectType.IsEnum()) attrType = &typeid(int);
32  if(ClassUtils::isTypeString( m_objectType )) attrType = &typeid(std::string);
33  std::string columnName = m_mapping.columnNames()[0];
34  m_columnIndex = relationalData.addData( columnName, *attrType );
35  m_dataElement = &dataElement;
36  m_relationalData = &relationalData;
37  return true;
38 }
39 
41  if( ! m_dataElement ){
42  throwException( "The streamer has not been built.",
43  "PrimitiveStreamerBase::bindDataForUpdate");
44  }
45  void* dataElementAddress = m_dataElement->address( data );
46  coral::Attribute& relDataElement = m_relationalData->data()[ m_columnIndex ];
47  relDataElement.setValueFromAddress( dataElementAddress );
48  if(!relDataElement.isValidData()){
49  throwException("Data provided for column \""+
50  relDataElement.specification().name()+
51  "\" is not valid for RDBMS storage.",
52  "PrimitiveStreamerBase::bindDataForUpdate");
53  }
54 }
55 
57  if( ! m_dataElement ){
58  throwException( "The streamer has not been built.",
59  "PrimitiveStreamerBase::bindDataForRead");
60  }
61  void* dataElementAddress = m_dataElement->address( data );
62  coral::Attribute& relDataElement = m_relationalData->data()[ m_columnIndex ];
63  relDataElement.copyValueToAddress( dataElementAddress );
64 }
65 
66 
68  MappingElement& mapping ):
69  PrimitiveStreamerBase( objectType, mapping ){
70 }
71 
73 }
74 
76  IRelationalData& relationalData,
78  return buildDataElement( dataElement, relationalData );
79 }
80 
81 void ora::PrimitiveWriter::setRecordId( const std::vector<int>& ){
82 }
83 
84 void ora::PrimitiveWriter::write( int, const void* data ){
85  bindDataForUpdate( data );
86 }
87 
89  MappingElement& mapping ):
90  PrimitiveStreamerBase( objectType, mapping ){
91 }
92 
94 }
95 
97  IRelationalData& relationalData,
99  return buildDataElement( dataElement, relationalData );
100 }
101 
102 void ora::PrimitiveUpdater::setRecordId( const std::vector<int>& ){
103 }
104 
106  const void* data ){
107  bindDataForUpdate( data );
108 }
109 
111  MappingElement& mapping ):
112  PrimitiveStreamerBase( objectType, mapping ){
113 }
114 
116 }
117 
119  IRelationalData& relationalData){
120  return buildDataElement( dataElement, relationalData );
121 }
122 
124 }
125 
126 void ora::PrimitiveReader::setRecordId( const std::vector<int>& ){
127 }
128 
130  bindDataForRead( data );
131 }
132 
134 }
135 
136 
138  MappingElement& mapping ):
139  m_objectType( objectType ),
140  m_mapping( mapping ){
141 }
142 
144 }
145 
147  return new PrimitiveWriter( m_objectType, m_mapping );
148 }
149 
151  return new PrimitiveUpdater( m_objectType, m_mapping );
152 }
153 
155  return new PrimitiveReader( m_objectType, m_mapping );
156 }
IRelationalUpdater * newUpdater()
bool isTypeString(const Reflex::Type &typ)
Definition: ClassUtils.cc:137
IRelationalWriter * newWriter()
virtual int addData(const std::string &columnName, const std::type_info &columnType)=0
bool buildDataElement(DataElement &dataElement, IRelationalData &relationalData)
PrimitiveUpdater(const Reflex::Type &objectType, MappingElement &mapping)
void setRecordId(const std::vector< int > &identity)
void write(int oid, const void *data)
Writes a data element.
PrimitiveStreamerBase(const Reflex::Type &objectType, MappingElement &mapping)
PrimitiveWriter(const Reflex::Type &objectType, MappingElement &mapping)
void read(void *data)
Reads a data element.
void update(int oid, const void *data)
Updates a data element.
PrimitiveStreamer(const Reflex::Type &objectType, MappingElement &mapping)
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
void bindDataForRead(void *data)
PrimitiveReader(const Reflex::Type &objectType, MappingElement &mapping)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void setRecordId(const std::vector< int > &identity)
void bindDataForUpdate(const void *data)
bool build(DataElement &dataElement, IRelationalData &relationalData)
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
IRelationalReader * newReader()
bool build(DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
void setRecordId(const std::vector< int > &identity)