CMS 3D CMS Logo

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