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::UniqueRefWriter Class Reference

#include <UniqueRefStreamer.h>

Inheritance diagram for ora::UniqueRefWriter:
ora::IRelationalWriter

Public Member Functions

bool build (DataElement &dataElement, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
 
void setRecordId (const std::vector< int > &identity)
 
 UniqueRefWriter (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
 
void write (int oid, const void *data)
 Writes a data element. More...
 
virtual ~UniqueRefWriter ()
 
- Public Member Functions inherited from ora::IRelationalWriter
virtual ~IRelationalWriter ()
 Destructor. More...
 

Private Attributes

int m_columnIndexes [2]
 
DataElementm_dataElement
 
MappingElementm_mappingElement
 
Reflex::Type m_objectType
 
RelationalBufferm_operationBuffer
 
IRelationalDatam_relationalData
 
ContainerSchemam_schema
 

Detailed Description

Definition at line 23 of file UniqueRefStreamer.h.

Constructor & Destructor Documentation

ora::UniqueRefWriter::UniqueRefWriter ( const Reflex::Type &  objectType,
MappingElement mapping,
ContainerSchema contSchema 
)

Definition at line 171 of file UniqueRefStreamer.cc.

References m_columnIndexes.

173  :
174  m_objectType( objectType ),
175  m_mappingElement( mapping ),
176  m_schema( contSchema ),
177  m_dataElement( 0 ),
178  m_relationalData( 0 ),
179  m_operationBuffer( 0 ){
180  m_columnIndexes[0]=-1;
181  m_columnIndexes[1]=-1;
182 }
RelationalBuffer * m_operationBuffer
DataElement * m_dataElement
IRelationalData * m_relationalData
ContainerSchema & m_schema
MappingElement & m_mappingElement
ora::UniqueRefWriter::~UniqueRefWriter ( )
virtual

Definition at line 189 of file UniqueRefStreamer.cc.

189  {
190 }

Member Function Documentation

bool ora::UniqueRefWriter::build ( DataElement dataElement,
IRelationalData relationalData,
RelationalBuffer operationBuffer 
)
virtual

Implements ora::IRelationalWriter.

Definition at line 192 of file UniqueRefStreamer.cc.

References ora::IRelationalData::addData(), and ora::throwException().

194  {
195  m_dataElement = &dataElement;
196 
197  const std::vector<std::string>& columns = m_mappingElement.columnNames();
198  if( columns.size() < 2 ){
199  throwException("Expected column names have not been found in the mapping.",
200  "UniqueRefWriter::build");
201  }
202  // booking for ref metadata
203  m_columnIndexes[0] = relationalData.addData( columns[0],typeid(std::string) );
204  // booking for ref id
205  m_columnIndexes[1] = relationalData.addData( columns[1],typeid(int) );
206  m_relationalData = &relationalData;
207  m_operationBuffer = &buffer;
208  return true;
209 }
RelationalBuffer * m_operationBuffer
DataElement * m_dataElement
IRelationalData * m_relationalData
const std::vector< std::string > & columnNames() const
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
MappingElement & m_mappingElement
void ora::UniqueRefWriter::setRecordId ( const std::vector< int > &  identity)
virtual

Implements ora::IRelationalWriter.

Definition at line 211 of file UniqueRefStreamer.cc.

211  {
212 }
void ora::UniqueRefWriter::write ( int  oid,
const void *  data 
)
virtual

Writes a data element.

Implements ora::IRelationalWriter.

Definition at line 215 of file UniqueRefStreamer.cc.

References ora::DependentClassWriter::build(), className(), ora::ClassUtils::lookupDictionary(), ora::MappingRules::sequenceNameForDependentClass(), ora::throwException(), ora::uniqueRefNullLabel(), and ora::DependentClassWriter::write().

216  {
217 
218  if(!m_dataElement){
219  throwException("The streamer has not been built.",
220  "UniqueRefWriter::write");
221  }
222 
223  void* refAddress = m_dataElement->address( data );
224 
225  Reflex::Object refObj( m_objectType, const_cast<void*>(refAddress));
226 
227  bool isNull;
228  refObj.Invoke("operator!",isNull);
229 
230  int refId = 0;
231  std::string className = uniqueRefNullLabel();
232 
233  if(!isNull){
234  // resolving the ref type
235  std::type_info* refTypeInfo = 0;
236  refObj.Invoke("typeInfo",refTypeInfo);
237  Reflex::Type refType = ClassUtils::lookupDictionary(*refTypeInfo);
238  className = refType.Name(Reflex::SCOPED);
239 
240  // building the dependent buffer
241  MappingElement& depMapping = m_schema.mappingForDependentClass( refType, true );
242 
243  // getting a new valid ref id
245 
246  DependentClassWriter writer;
247  writer.build( refType, depMapping, m_schema, m_operationBuffer->addVolatileBuffer() );
248  void* refData;
249  refObj.Invoke("operator*",refData);
250  writer.write( oid, refId, refData );
251 
252  }
253  // writing in the parent table
254  coral::AttributeList& parentData = m_relationalData->data();
255  parentData[m_columnIndexes[0]].data<std::string>()=className;
256  parentData[m_columnIndexes[1]].data<int>()=refId;
257 }
Sequences & containerSequences()
RelationalBuffer * m_operationBuffer
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:48
DataElement * m_dataElement
RelationalBuffer & addVolatileBuffer()
MappingElement & mappingForDependentClass(const Reflex::Type &dependentClass, bool writeEnabled=false)
IRelationalData * m_relationalData
ContainerSchema & m_schema
virtual coral::AttributeList & data()=0
int getNextId(const std::string &sequenceName, bool sinchronize=false)
Definition: Sequences.cc:22
const std::string & containerName()
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
static std::string sequenceNameForDependentClass(const std::string &containerName, const std::string &className)
Definition: MappingRules.cc:20
Reflex::Type lookupDictionary(const std::type_info &typeInfo, bool throwFlag=true)
Definition: ClassUtils.cc:93
std::string className(const T &t)
Definition: ClassName.h:30
std::string uniqueRefNullLabel()

Member Data Documentation

int ora::UniqueRefWriter::m_columnIndexes[2]
private

Definition at line 42 of file UniqueRefStreamer.h.

Referenced by UniqueRefWriter().

DataElement* ora::UniqueRefWriter::m_dataElement
private

Definition at line 44 of file UniqueRefStreamer.h.

MappingElement& ora::UniqueRefWriter::m_mappingElement
private

Definition at line 41 of file UniqueRefStreamer.h.

Reflex::Type ora::UniqueRefWriter::m_objectType
private

Definition at line 40 of file UniqueRefStreamer.h.

RelationalBuffer* ora::UniqueRefWriter::m_operationBuffer
private

Definition at line 46 of file UniqueRefStreamer.h.

IRelationalData* ora::UniqueRefWriter::m_relationalData
private

Definition at line 45 of file UniqueRefStreamer.h.

ContainerSchema& ora::UniqueRefWriter::m_schema
private

Definition at line 43 of file UniqueRefStreamer.h.