CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/CondCore/ORA/src/PrimitiveStreamer.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Exception.h"
00002 #include "PrimitiveStreamer.h"
00003 #include "DataElement.h"
00004 #include "MappingElement.h"
00005 #include "RelationalOperation.h"
00006 #include "ClassUtils.h"
00007 // externals
00008 #include "CoralBase/Attribute.h"
00009 
00010 
00011 ora::PrimitiveStreamerBase::PrimitiveStreamerBase( const Reflex::Type& objectType,
00012                                                    MappingElement& mapping ):
00013   m_objectType( objectType ),
00014   m_mapping(mapping),
00015   m_columnIndex(-1),
00016   m_dataElement( 0 ),
00017   m_relationalData( 0 ){  
00018 }
00019 
00020 ora::PrimitiveStreamerBase::~PrimitiveStreamerBase(){
00021 }
00022 
00023 bool ora::PrimitiveStreamerBase::buildDataElement(DataElement& dataElement,
00024                                                   IRelationalData& relationalData){
00025   if( m_mapping.columnNames().size()==0 ){
00026     throwException( "The mapping element does not contain columns.",
00027                     "PrimitiveStreamerBase::buildDataElement");
00028   }
00029 
00030   const std::type_info* attrType = &m_objectType.TypeInfo();
00031   if(m_objectType.IsEnum()) attrType = &typeid(int);
00032   if(ClassUtils::isTypeString( m_objectType )) attrType = &typeid(std::string);
00033   std::string columnName = m_mapping.columnNames()[0];
00034   m_columnIndex = relationalData.addData( columnName, *attrType );
00035   m_dataElement = &dataElement;
00036   m_relationalData = &relationalData;
00037   return true;
00038 }
00039 
00040 void ora::PrimitiveStreamerBase::bindDataForUpdate( const void* data ){
00041   if( ! m_dataElement ){
00042     throwException( "The streamer has not been built.",
00043                     "PrimitiveStreamerBase::bindDataForUpdate");
00044   }
00045   void* dataElementAddress = m_dataElement->address( data );
00046   coral::Attribute& relDataElement = m_relationalData->data()[ m_columnIndex ];
00047   relDataElement.setValueFromAddress( dataElementAddress );
00048   if(!relDataElement.isValidData()){
00049     throwException("Data provided for column \""+
00050                    relDataElement.specification().name()+
00051                    "\" is not valid for RDBMS storage.",
00052                    "PrimitiveStreamerBase::bindDataForUpdate");
00053   }  
00054 }
00055 
00056 void ora::PrimitiveStreamerBase::bindDataForRead( void* data ){
00057   if( ! m_dataElement ){
00058     throwException( "The streamer has not been built.",
00059                     "PrimitiveStreamerBase::bindDataForRead");
00060   }
00061   void* dataElementAddress = m_dataElement->address( data );
00062   coral::Attribute& relDataElement = m_relationalData->data()[ m_columnIndex ];
00063   relDataElement.copyValueToAddress( dataElementAddress );
00064 }
00065 
00066 
00067 ora::PrimitiveWriter::PrimitiveWriter( const Reflex::Type& objectType,
00068                                        MappingElement& mapping ):
00069   PrimitiveStreamerBase( objectType, mapping ){
00070 }
00071 
00072 ora::PrimitiveWriter::~PrimitiveWriter(){
00073 }
00074 
00075 bool ora::PrimitiveWriter::build(DataElement& dataElement,
00076                                  IRelationalData& relationalData,
00077                                  RelationalBuffer&){
00078   return buildDataElement( dataElement, relationalData );
00079 }
00080 
00081 void ora::PrimitiveWriter::setRecordId( const std::vector<int>& ){
00082 }
00083 
00084 void ora::PrimitiveWriter::write( int, const void* data ){
00085   bindDataForUpdate( data );  
00086 }
00087 
00088 ora::PrimitiveUpdater::PrimitiveUpdater( const Reflex::Type& objectType,
00089                                          MappingElement& mapping ):
00090   PrimitiveStreamerBase( objectType, mapping ){
00091 }
00092 
00093 ora::PrimitiveUpdater::~PrimitiveUpdater(){
00094 }
00095 
00096 bool ora::PrimitiveUpdater::build(DataElement& dataElement,
00097                                   IRelationalData& relationalData,
00098                                   RelationalBuffer&){
00099   return buildDataElement( dataElement, relationalData );  
00100 }
00101 
00102 void ora::PrimitiveUpdater::setRecordId( const std::vector<int>& ){
00103 }
00104 
00105 void ora::PrimitiveUpdater::update( int,
00106                                     const void* data ){
00107   bindDataForUpdate( data );  
00108 }
00109 
00110 ora::PrimitiveReader::PrimitiveReader( const Reflex::Type& objectType,
00111                                        MappingElement& mapping ):
00112   PrimitiveStreamerBase( objectType, mapping ){
00113 }
00114 
00115 ora::PrimitiveReader::~PrimitiveReader(){
00116 }
00117 
00118 bool ora::PrimitiveReader::build(DataElement& dataElement,
00119                                  IRelationalData& relationalData){
00120   return buildDataElement( dataElement, relationalData );  
00121 }
00122 
00123 void ora::PrimitiveReader::select( int ){
00124 }
00125 
00126 void ora::PrimitiveReader::setRecordId( const std::vector<int>& ){
00127 }
00128 
00129 void ora::PrimitiveReader::read( void* data ){
00130   bindDataForRead( data );
00131 }
00132 
00133 void ora::PrimitiveReader::clear(){
00134 }
00135 
00136 
00137 ora::PrimitiveStreamer::PrimitiveStreamer( const Reflex::Type& objectType,
00138                                            MappingElement& mapping ):
00139   m_objectType( objectType ),
00140   m_mapping( mapping ){
00141 }
00142 
00143 ora::PrimitiveStreamer::~PrimitiveStreamer(){
00144 }
00145 
00146 ora::IRelationalWriter* ora::PrimitiveStreamer::newWriter(){
00147   return new PrimitiveWriter( m_objectType, m_mapping );
00148 }
00149 
00150 ora::IRelationalUpdater* ora::PrimitiveStreamer::newUpdater(){
00151   return new PrimitiveUpdater( m_objectType, m_mapping );
00152 }
00153 
00154 ora::IRelationalReader* ora::PrimitiveStreamer::newReader(){
00155   return new PrimitiveReader( m_objectType, m_mapping );
00156 }