CMS 3D CMS Logo

DBSession.cc

Go to the documentation of this file.
00001 //
00002 // Package:    CondCore/DBCommon
00003 // Class:      DBSession
00004 //
00005 // Author:      Zhen Xie
00006 //
00007 //seal includes
00008 #include "PluginManager/PluginManager.h"
00009 #include "SealKernel/IMessageService.h"
00010 #include "SealKernel/Property.h"
00011 #include "SealKernel/PropertyManager.h"
00012 //coral includes
00013 #include "RelationalAccess/IAuthenticationService.h"
00014 #include "RelationalAccess/IRelationalService.h"
00015 #include "RelationalAccess/IConnectionService.h"
00016 #include "RelationalAccess/IConnectionServiceConfiguration.h"
00017 //pool includes
00018 #include "POOLCore/POOLContext.h"
00019 #include "RelationalStorageService/IBlobStreamingService.h"
00020 //local includes
00021 #include "CondCore/DBCommon/interface/DBSession.h"
00022 #include "CondCore/DBCommon/interface/SessionConfiguration.h"
00023 #include "CondCore/DBCommon/interface/ConnectionConfiguration.h"
00024 #include "CondCore/DBCommon/interface/Exception.h"
00025 // pool includes
00026 #include <boost/filesystem/operations.hpp>
00027 //#include <iostream>
00028 cond::DBSession::DBSession(){ 
00029   seal::PluginManager* pm = seal::PluginManager::get();
00030   if ( ! pm ) {
00031     throw cond::Exception( "Could not get the plugin manager instance" );
00032   }
00033   pm->initialise();
00034   m_context=pool::POOLContext::context();
00035   m_loader = new seal::ComponentLoader( m_context.get() );
00036   m_sessionConfig = new cond::SessionConfiguration;
00037 }
00038 cond::DBSession::~DBSession(){
00039   delete m_sessionConfig;
00040 }
00041 void cond::DBSession::open(){
00042   m_loader->load("SEAL/Services/MessageService");
00043   std::vector< seal::IHandle<seal::IMessageService> > v_msgSvc;
00044   m_context->query( v_msgSvc );
00045   if ( v_msgSvc.empty() ) {
00046     throw cond::Exception( "could not locate the seal message service" );
00047   }
00048   switch ( m_sessionConfig->messageLevel() ) {
00049   case cond::Error :
00050     v_msgSvc.front()->setOutputLevel( seal::Msg::Error );
00051     break;
00052   case cond::Warning :
00053     v_msgSvc.front()->setOutputLevel( seal::Msg::Warning );
00054     break;
00055   case cond::Debug :
00056     v_msgSvc.front()->setOutputLevel( seal::Msg::Debug );
00057     break;
00058   case cond::Info :
00059     v_msgSvc.front()->setOutputLevel( seal::Msg::Info );
00060     break;
00061   default:
00062     v_msgSvc.front()->setOutputLevel( seal::Msg::Error );
00063   } 
00064   //load authentication service
00065   std::vector< seal::IHandle<coral::IAuthenticationService> > v_authsvc;
00066   if( m_sessionConfig->authenticationMethod()== cond::XML ) {
00067     m_loader->load( "COND/Services/XMLAuthenticationService" );
00068     boost::filesystem::path authPath( m_sessionConfig->authName() );
00069     if(boost::filesystem::is_directory(m_sessionConfig->authName())){
00070       authPath /= boost::filesystem::path("authentication.xml");
00071     }
00072     std::string authName=authPath.string();
00073     size_t nchildren=m_loader->context()->children();
00074     for( size_t i=0; i<nchildren; ++i ){
00075       seal::Handle<seal::PropertyManager> pmgr=m_loader->context()->child(i)->component<seal::PropertyManager>();
00076       std::string scopeName=pmgr->scopeName();
00077       //std::cout << "Scope: \"" << scopeName << "\"" << std::endl;
00078       if( scopeName=="COND/Services/XMLAuthenticationService" ){
00079         pmgr->property("AuthenticationFile")->set(authName);
00080       }
00081     }
00082   }else{
00083     m_loader->load( "CORAL/Services/EnvironmentAuthenticationService" );
00084   }
00085   //if( m_sessionConfig->authenticationMethod()==cond::XML ){
00086   //  }
00087   m_context->query(v_authsvc);
00088   if ( v_authsvc.empty() ) {
00089     throw cond::Exception( "Could not locate authentication service" );
00090   }
00091   //load relational service
00092   //m_loader->load( "CORAL/Services/RelationalService" );
00093   //load connection service
00094   m_loader->load( "CORAL/Services/ConnectionService" );
00095   
00096   m_con=m_context->query<coral::IConnectionService>( "CORAL/Services/ConnectionService" ).get();
00097   if (! m_con ) {
00098     throw cond::Exception( "could not locate the coral connection service" );
00099   }
00100   coral::IConnectionServiceConfiguration& conserviceConfig = connectionService().configuration();
00101   cond::ConnectionConfiguration* conConfig=m_sessionConfig->connectionConfiguration();
00102   if(m_sessionConfig->isSQLMonitoringOn()){
00103     m_loader->load( "COND/Services/SQLMonitoringService");
00104     conConfig->setMonitorLevel(coral::monitor::Trace);
00105   }
00106   if( conConfig ){
00107     if( conConfig->isConnectionSharingEnabled() ){
00108       conserviceConfig.enableConnectionSharing();
00109     }
00110     if( conConfig->isPoolAutomaticCleanUpEnabled() ){
00111       conserviceConfig.enablePoolAutomaticCleanUp();
00112     }else{
00113       conserviceConfig.disablePoolAutomaticCleanUp();
00114     }
00115     conserviceConfig.setConnectionRetrialPeriod( conConfig->connectionRetrialPeriod() );
00116     conserviceConfig.setConnectionRetrialTimeOut( conConfig->connectionRetrialTimeOut() );
00117     conserviceConfig.setConnectionTimeOut( conConfig->connectionTimeOut() );
00118     conserviceConfig.setMonitoringLevel( conConfig->monitorLevel() ); 
00119     if( m_sessionConfig->hasBlobStreamService() ){
00120       std::string streamerName=m_sessionConfig->blobStreamerName();
00121       if(streamerName.empty()){
00122         m_loader->load( "COND/Services/DefaultBlobStreamingService" );
00123       }else{
00124         m_loader->load(streamerName);
00125       }
00126       std::vector< seal::IHandle<pool::IBlobStreamingService> > v_blobsvc;
00127       m_context->query( v_blobsvc );
00128       if ( v_blobsvc.empty() ) {
00129         throw cond::Exception( "could not locate the BlobStreamingService" );
00130       }
00131     }
00132   }
00133 }
00134 coral::IConnectionService& 
00135 cond::DBSession::connectionService(){
00136   return *m_con;
00137 }
00138 coral::IRelationalService& 
00139 cond::DBSession::relationalService(){
00140   std::vector< seal::IHandle<coral::IRelationalService> > v_svc;
00141   m_context->query( v_svc );
00142   if ( v_svc.empty() ) {
00143     throw cond::Exception( "Could not locate the relational service" );
00144   }
00145   return *(v_svc.front().get());
00146 }
00147 coral::IAuthenticationService& 
00148 cond::DBSession::authenticationService() const{
00149    std::vector< seal::IHandle<coral::IAuthenticationService> > v_svc;
00150    m_context->query( v_svc );
00151    if ( v_svc.empty() ) {
00152      throw cond::Exception( "Could not locate the authentication service" );
00153    }
00154    return *(v_svc.front().get());
00155 }
00156 const coral::IMonitoringReporter& 
00157 cond::DBSession::monitoringReporter() const{
00158   return m_con->monitoringReporter();
00159 }
00160 coral::IWebCacheControl& 
00161 cond::DBSession::webCacheControl(){
00162   return m_con->webCacheControl();
00163 }
00164 pool::IBlobStreamingService& 
00165 cond::DBSession::blobStreamingService(){
00166   std::vector< seal::IHandle<pool::IBlobStreamingService> > v_svc;
00167   m_context->query( v_svc );
00168   if ( v_svc.empty() ) {
00169     throw cond::Exception( "Could not locate the BlobStreamingService" );
00170   }
00171   return *(v_svc.front().get());
00172 }
00173 cond::SessionConfiguration& 
00174 cond::DBSession::configuration(){
00175   return *m_sessionConfig;
00176 }

Generated on Tue Jun 9 17:26:06 2009 for CMSSW by  doxygen 1.5.4