CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CondTools/RPC/src/RPCDBCom.cc

Go to the documentation of this file.
00001 #include "CondTools/RPC/interface/RPCDBCom.h"
00002 #include "RelationalAccess/IRelationalDomain.h"
00003 #include "RelationalAccess/IConnection.h"
00004 #include "RelationalAccess/ISession.h"
00005 #include "RelationalAccess/RelationalServiceException.h"
00006 #include "CoralKernel/Context.h"
00007 
00008 RPCDBCom::RPCDBCom():
00009   m_connection( 0 )
00010 {
00011   coral::Context& context = coral::Context::instance();
00012   context.loadComponent( "CORAL/RelationalPlugins/oracle" );
00013   coral::IHandle<coral::IRelationalDomain> domain = context.query<coral::IRelationalDomain>(
00014 "CORAL/RelationalPlugins/oracle" );
00015   if ( ! domain.isValid() )
00016     throw std::runtime_error( "Could not load the OracleAccess plugin" );
00017 }
00018 
00019 
00020 RPCDBCom::~RPCDBCom()
00021 {
00022   if ( m_connection ) delete m_connection;
00023 }
00024 
00025 
00026 coral::ISession*
00027 RPCDBCom::connect( const std::string& connectionString,
00028                    const std::string& userName,
00029                    const std::string& password )
00030 {
00031   coral::Context& ctx = coral::Context::instance();
00032   ctx.loadComponent("CORAL/RelationalPlugins/oracle");
00033   coral::IHandle<coral::IRelationalDomain> iHandle=ctx.query<coral::IRelationalDomain>("CORAL/RelationalPlugins/oracle");
00034   if ( ! iHandle.isValid() ) {
00035     throw std::runtime_error( "Could not load the OracleAccess plugin" );
00036   }
00037   std::pair<std::string, std::string> connectionAndSchema = iHandle->decodeUserConnectionString( connectionString );
00038 
00039   if ( ! m_connection )
00040     m_connection = iHandle->newConnection( connectionAndSchema.first );
00041 
00042   if ( ! m_connection->isConnected() )
00043     m_connection->connect();
00044   
00045   coral::ISession* session = m_connection->newSession( connectionAndSchema.second );
00046   
00047   if ( session ) {
00048     session->startUserSession( userName, password );
00049   }
00050   //memory leaking
00051   return session;
00052 }
00053 
00054 
00055 void
00056 RPCDBCom::setVerbosityLevel( coral::MsgLevel level )
00057 {
00058   coral::MessageStream::setMsgVerbosity(level);
00059 }
00060 
00061 
00062