CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CondCore/ORA/src/BlobStreamer.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Exception.h"
00002 #include "CondCore/ORA/interface/IBlobStreamingService.h"
00003 #include "DatabaseSession.h"
00004 #include "IDatabaseSchema.h"
00005 #include "BlobStreamer.h"
00006 #include "DataElement.h"
00007 #include "MappingElement.h"
00008 #include "RelationalOperation.h"
00009 #include "RelationalBuffer.h"
00010 #include "ContainerSchema.h"
00011 #include "ClassUtils.h"
00012 // externals
00013 #include "CoralBase/Attribute.h"
00014 #include "CoralBase/Blob.h"
00015 
00016 ora::BlobWriterBase::BlobWriterBase( const Reflex::Type& objectType,
00017                                      MappingElement& mapping,
00018                                      ContainerSchema& contSchema ):
00019   m_objectType( objectType ),
00020   m_mapping( mapping ),
00021   m_columnIndex(-1),
00022   m_schema( contSchema ),
00023   m_dataElement( 0 ),
00024   m_relationalData( 0 ),
00025   m_relationalBuffer( 0 ),
00026   m_blobWriter( 0 ),
00027   m_useCompression( true ){
00028 }
00029 
00030 ora::BlobWriterBase::~BlobWriterBase(){
00031 }
00032 
00033 bool ora::BlobWriterBase::buildDataElement(DataElement& dataElement,
00034                                            IRelationalData& relationalData,
00035                                            RelationalBuffer& operationBuffer){
00036   if( m_mapping.columnNames().size() == 0 ){
00037     throwException( "The mapping element does not contain columns.",
00038                     "BlobWriterBase::build");
00039   }
00040 
00041   m_dataElement = &dataElement;
00042   std::string columnName = m_mapping.columnNames()[0];
00043   m_columnIndex = relationalData.addBlobData( columnName );
00044   m_relationalData = &relationalData;
00045   m_relationalBuffer = &operationBuffer;
00046   m_blobWriter = m_schema.blobStreamingService();
00047   if(!m_blobWriter){
00048     throwException("Blob Streaming Service is not installed.",
00049                    "BlobWriterBase::::build");
00050   }
00051   if( m_schema.dbSession().schema().mainTable().schemaVersion()==poolSchemaVersion() ) m_useCompression = false;
00052   return true;
00053 }
00054 
00055 void ora::BlobWriterBase::bindData( const void* data ){
00056   if( ! m_dataElement ){
00057     throwException( "The streamer has not been built.",
00058                     "BlobWriterBase::bindData");
00059   }
00060   void* dataElementAddress = m_dataElement->address( data );
00061   coral::Attribute& relDataElement = m_relationalData->data()[ m_columnIndex ];
00062   boost::shared_ptr<coral::Blob> blobData = m_blobWriter->write( dataElementAddress, m_objectType, m_useCompression );
00063   m_relationalBuffer->storeBlob( blobData );
00064   relDataElement.bind<coral::Blob>( *blobData );
00065 }
00066 
00067 ora::BlobWriter::BlobWriter( const Reflex::Type& objectType,
00068                              MappingElement& mapping,
00069                              ContainerSchema& contSchema ):
00070   BlobWriterBase( objectType, mapping, contSchema ){
00071 }
00072 
00073 ora::BlobWriter::~BlobWriter(){
00074 }
00075 
00076 bool ora::BlobWriter::build(DataElement& dataElement,
00077                             IRelationalData& relationalData,
00078                             RelationalBuffer& relationalBuffer ){
00079   return buildDataElement( dataElement, relationalData, relationalBuffer );
00080 }
00081 
00082 void ora::BlobWriter::setRecordId( const std::vector<int>& ){
00083 }
00084 
00085 void ora::BlobWriter::write( int,
00086                              const void* data ){
00087   bindData( data );  
00088 }
00089 
00090 ora::BlobUpdater::BlobUpdater( const Reflex::Type& objectType,
00091                                MappingElement& mapping,
00092                                ContainerSchema& contSchema ):
00093   BlobWriterBase( objectType, mapping, contSchema ){
00094 }
00095 
00096 ora::BlobUpdater::~BlobUpdater(){
00097 }
00098 
00099 bool ora::BlobUpdater::build(DataElement& dataElement,
00100                              IRelationalData& relationalData,
00101                              RelationalBuffer& relationalBuffer){
00102   return buildDataElement( dataElement, relationalData, relationalBuffer );  
00103 }
00104 
00105 void ora::BlobUpdater::setRecordId( const std::vector<int>& ){
00106 }
00107 
00108 void ora::BlobUpdater::update( int,
00109                                const void* data ){
00110   bindData( data );  
00111 }
00112 
00113 
00114 ora::BlobReader::BlobReader( const Reflex::Type& objectType,
00115                              MappingElement& mapping,
00116                              ContainerSchema& contSchema ):
00117   m_objectType( objectType ),
00118   m_mapping( mapping ),
00119   m_columnIndex( -1 ),
00120   m_schema( contSchema ),
00121   m_dataElement( 0 ),
00122   m_relationalData( 0 ),
00123   m_blobReader( 0 ){
00124 }
00125 
00126 ora::BlobReader::~BlobReader(){
00127 }
00128 
00129 bool ora::BlobReader::build(DataElement& dataElement,
00130                             IRelationalData& relationalData){
00131   
00132   if( m_mapping.columnNames().size() == 0 ){
00133     throwException( "The mapping element does not contain columns.",
00134                     "BlobReader::build");
00135   }
00136 
00137   m_dataElement = &dataElement;
00138   std::string columnName = m_mapping.columnNames()[0];
00139   m_columnIndex = relationalData.addBlobData( columnName );
00140   m_relationalData = &relationalData;
00141   m_blobReader = m_schema.blobStreamingService();
00142   if(!m_blobReader){
00143     throwException("Blob Streaming Service is not installed.",
00144                    "BlobReader::build");
00145   }
00146   return true;
00147 }
00148 
00149 void ora::BlobReader::select( int ){
00150 }
00151 
00152 void ora::BlobReader::setRecordId( const std::vector<int>& ){
00153 }
00154 
00155 void ora::BlobReader::read( void* data ){
00156   if( ! m_dataElement ){
00157     throwException( "The streamer has not been built.",
00158                     "BlobReader::read");
00159   }
00160   void* dataElementAddress = m_dataElement->address( data );
00161   coral::Attribute& relDataElement = m_relationalData->data()[ m_columnIndex ];
00162   m_blobReader->read(relDataElement.data<coral::Blob>(), dataElementAddress, m_objectType );
00163 }
00164 
00165 void ora::BlobReader::clear(){
00166 }
00167 
00168 ora::BlobStreamer::BlobStreamer( const Reflex::Type& objectType,
00169                                  MappingElement& mapping,
00170                                  ContainerSchema& contSchema ):
00171   m_objectType( objectType ),
00172   m_mapping( mapping ),
00173   m_schema( contSchema ){
00174 }
00175 
00176 ora::BlobStreamer::~BlobStreamer(){
00177 }
00178 
00179 ora::IRelationalWriter* ora::BlobStreamer::newWriter(){
00180   return new BlobWriter( m_objectType, m_mapping, m_schema );
00181 }
00182 
00183 ora::IRelationalUpdater* ora::BlobStreamer::newUpdater(){
00184   return new BlobUpdater( m_objectType, m_mapping, m_schema );
00185 }
00186 
00187 ora::IRelationalReader* ora::BlobStreamer::newReader(){
00188   return new BlobReader( m_objectType, m_mapping, m_schema );
00189 }