CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/CondCore/ORA/src/RelationalStreamerFactory.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Exception.h"
00002 #include "RelationalStreamerFactory.h"
00003 #include "MappingElement.h"
00004 #include "ClassUtils.h"
00005 #include "PrimitiveStreamer.h"
00006 #include "BlobStreamer.h"
00007 #include "ObjectStreamer.h"
00008 #include "STLContainerStreamer.h"
00009 #include "CArrayStreamer.h"
00010 #include "InlineCArrayStreamer.h"
00011 #include "OraReferenceStreamer.h"
00012 #include "NamedRefStreamer.h"
00013 #include "OraPtrStreamer.h"
00014 #include "PVectorStreamer.h"
00015 #include "QueryableVectorStreamer.h"
00016 #include "UniqueRefStreamer.h"
00017 //
00018 #include <memory>
00019 
00020 ora::RelationalStreamerFactory::RelationalStreamerFactory( ContainerSchema& contSchema ):
00021   m_containerSchema( contSchema ){
00022 }
00023 
00024 ora::RelationalStreamerFactory::~RelationalStreamerFactory(){
00025 }
00026 
00027 ora::IRelationalStreamer* ora::RelationalStreamerFactory::newStreamer( const Reflex::Type& type,
00028                                                                        MappingElement& mapping ){
00029   IRelationalStreamer* newStreamer = 0;
00030   if ( mapping.elementType() == MappingElement::Primitive ) { // Primitives
00031     if( ! ClassUtils::isTypePrimitive( type ) ){
00032       throwException( "Mapped variable \"" + mapping.variableName() +
00033                       "\", declared as Primitive, is associated to non-primitive type \""+type.Name()+"\"",
00034                       "RelationalStreamerFactory::newStreamer" );
00035     }
00036     newStreamer = new PrimitiveStreamer( type, mapping );
00037   } else if ( mapping.elementType() == MappingElement::Blob ){
00038     newStreamer = new BlobStreamer( type, mapping, m_containerSchema );
00039   } else if ( mapping.elementType() == MappingElement::Object ){
00040     newStreamer = new ObjectStreamer( type, mapping, m_containerSchema );
00041   } else if ( mapping.elementType() == MappingElement::Array ){
00042     if ( !ClassUtils::isTypeContainer( type ) ) {
00043       throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
00044                       mapping.variableType() +
00045                       "\", declared as Array, is associated to the non-container type \""+
00046                       type.Name()+"\".",
00047                       "RelationalStreamerFactory::newStreamer" );
00048     }
00049     newStreamer = new STLContainerStreamer( type, mapping, m_containerSchema );
00050   } else if ( mapping.elementType() == MappingElement::CArray ) { 
00051     if ( ! type.IsArray() ) {
00052       throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
00053                       mapping.variableType() +
00054                       "\", declared as C-Array, is associated to the non-array type \""+
00055                       type.Name()+"\".",
00056                       "RelationalStreamerFactory::newStreamer" );
00057     }
00058     newStreamer = new CArrayStreamer( type, mapping, m_containerSchema );
00059   } else if ( mapping.elementType() == MappingElement::InlineCArray ) { 
00060     if ( ! type.IsArray() ) {
00061       throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
00062                       mapping.variableType() +
00063                       "\", declared as Inline C-Array, is associated to the non-array type \""+
00064                       type.Name()+"\".",
00065                       "RelationalStreamerFactory::newStreamer" );
00066     }
00067     newStreamer = new InlineCArrayStreamer( type, mapping, m_containerSchema );
00068   } else if ( mapping.elementType() == MappingElement::OraArray ) {
00069     if ( ! ClassUtils::isTypeOraVector( type ) ) {
00070       throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
00071                       mapping.variableType() +
00072                       "\", declared as OraArray, is associated to the non-array type \""+
00073                       type.Name()+"\".",
00074                       "RelationalStreamerFactory::newStreamer" );
00075     }
00076     if( ClassUtils::isTypePVector( type ) )
00077       newStreamer = new PVectorStreamer( type, mapping, m_containerSchema );
00078     else if ( ClassUtils::isTypeQueryableVector( type ))
00079       newStreamer = new QueryableVectorStreamer( type, mapping, m_containerSchema );
00080   } else if ( mapping.elementType() == MappingElement::OraPointer ) { 
00081     if ( ! ClassUtils::isTypeOraPointer( type )) {
00082       throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
00083                       mapping.variableType() +
00084                       "\", declared as a OraPointer, is associated to the type \""+
00085                       type.Name()+"\".",
00086                       "RelationalStreamerFactory::newStreamer" );
00087     }
00088     newStreamer = new OraPtrStreamer( type, mapping, m_containerSchema );
00089   } else if ( mapping.elementType() == MappingElement::OraReference ) {
00090     if ( ! ClassUtils::isTypeOraReference( type )) {
00091       throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
00092                       mapping.variableType() +
00093                       "\", declared as a OraReference, is associated to the type \""+
00094                       type.Name()+"\".",
00095                       "RelationalStreamerFactory::newStreamer" );
00096     }
00097     newStreamer = new OraReferenceStreamer( type, mapping, m_containerSchema );
00098   } else if ( mapping.elementType() == MappingElement::NamedReference ) {
00099     if ( ! ClassUtils::isTypeNamedReference( type )) {
00100       throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
00101                       mapping.variableType() +
00102                       "\", declared as a NamedReference, is associated to the type \""+
00103                       type.Name()+"\".",
00104                       "RelationalStreamerFactory::newStreamer" );
00105     }
00106     newStreamer = new NamedRefStreamer( type, mapping, m_containerSchema );
00107   } else if ( mapping.elementType() == MappingElement::UniqueReference ) {
00108     if ( ! ClassUtils::isTypeUniqueReference( type )) {
00109       throwException( "Mapped variable \"" + mapping.variableName() +" of type "+
00110                       mapping.variableType() +
00111                       "\", declared as a UniqueReference, is associated to the type \""+
00112                       type.Name()+"\".",
00113                       "RelationalStreamerFactory::newStreamer" );
00114     }
00115     newStreamer = new UniqueRefStreamer( type, mapping, m_containerSchema );
00116   } else {
00117     throwException( "Cannot find a streamer suitable for mapped variable \"" + mapping.variableName() +" of type "+
00118                     mapping.variableType() +
00119                     "\".",
00120                     "RelationalStreamerFactory::newStreamer" );
00121   }
00122 
00123   return newStreamer;
00124 }
00125 
00126 
00127 
00128 ora::IRelationalWriter* ora::RelationalStreamerFactory::newWriter(const Reflex::Type& type,
00129                                                                   MappingElement& mapping ){
00130   std::auto_ptr<IRelationalStreamer> streamer( newStreamer( type, mapping ) );
00131   return streamer->newWriter();
00132 }
00133 
00134 ora::IRelationalUpdater* ora::RelationalStreamerFactory::newUpdater(const Reflex::Type& type,
00135                                                                     MappingElement& mapping ){
00136   std::auto_ptr<IRelationalStreamer> streamer( newStreamer( type, mapping ) );
00137   return streamer->newUpdater();
00138 }
00139 
00140 ora::IRelationalReader* ora::RelationalStreamerFactory::newReader(const Reflex::Type& type,
00141                                                                   MappingElement& mapping ){
00142   std::auto_ptr<IRelationalStreamer> streamer( newStreamer( type, mapping ) );
00143   return streamer->newReader();
00144 }