Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:15

0001 #include "CondTools/RPC/interface/RPCDBCom.h"
0002 #include "RelationalAccess/IRelationalDomain.h"
0003 #include "RelationalAccess/IConnection.h"
0004 #include "RelationalAccess/ISession.h"
0005 #include "RelationalAccess/RelationalServiceException.h"
0006 #include "CoralKernel/Context.h"
0007 
0008 RPCDBCom::RPCDBCom() : m_connection(nullptr) {
0009   coral::Context& context = coral::Context::instance();
0010   context.loadComponent("CORAL/RelationalPlugins/oracle");
0011   coral::IHandle<coral::IRelationalDomain> domain =
0012       context.query<coral::IRelationalDomain>("CORAL/RelationalPlugins/oracle");
0013   if (!domain.isValid())
0014     throw std::runtime_error("Could not load the OracleAccess plugin");
0015 }
0016 
0017 RPCDBCom::~RPCDBCom() {
0018   if (m_connection)
0019     delete m_connection;
0020 }
0021 
0022 coral::ISession* RPCDBCom::connect(const std::string& connectionString,
0023                                    const std::string& userName,
0024                                    const std::string& password) {
0025   coral::Context& ctx = coral::Context::instance();
0026   ctx.loadComponent("CORAL/RelationalPlugins/oracle");
0027   coral::IHandle<coral::IRelationalDomain> iHandle =
0028       ctx.query<coral::IRelationalDomain>("CORAL/RelationalPlugins/oracle");
0029   if (!iHandle.isValid()) {
0030     throw std::runtime_error("Could not load the OracleAccess plugin");
0031   }
0032   std::pair<std::string, std::string> connectionAndSchema = iHandle->decodeUserConnectionString(connectionString);
0033 
0034   if (!m_connection)
0035     m_connection = iHandle->newConnection(connectionAndSchema.first);
0036 
0037   if (!m_connection->isConnected())
0038     m_connection->connect();
0039 
0040   coral::ISession* session = m_connection->newSession(connectionAndSchema.second);
0041 
0042   if (session) {
0043     session->startUserSession(userName, password);
0044   }
0045   //memory leaking
0046   return session;
0047 }
0048 
0049 void RPCDBCom::setVerbosityLevel(coral::MsgLevel level) { coral::MessageStream::setMsgVerbosity(level); }