CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConnectionPool.cc
Go to the documentation of this file.
3 // externals
4 #include "RelationalAccess/ISessionProxy.h"
5 
7  m_proxy(){
8 }
9 
10 ora::SharedSession::SharedSession(boost::shared_ptr<coral::ISessionProxy>& coralSession):
11  m_proxy(coralSession){
12 }
13 
15  m_proxy( rhs.m_proxy ){
16 }
17 
19 }
20 
22  m_proxy = rhs.m_proxy;
23  return *this;
24 }
25 
26 coral::ISessionProxy&
28  if(!m_proxy.get()){
29  throwException("Coral Database Session is not available.",
30  "SharedSession::proxy");
31  }
32  return *m_proxy;
33 }
34 
35 boost::shared_ptr<coral::ISessionProxy>
37  return m_proxy;
38 }
39 
41  return m_proxy.get();
42 }
43 
45  m_proxy.reset();
46 }
47 
48 ora::ConnectionPool::ConnectionPool():m_connectionService(),m_sessions(){
49 }
50 
52 }
53 
54 coral::IConnectionService& ora::ConnectionPool::connectionService(){
55  return m_connectionService;
56 }
57 coral::IConnectionServiceConfiguration& ora::ConnectionPool::configuration(){
58  return m_connectionService.configuration();
59 }
60 
62  coral::AccessMode accessMode ){
63  bool valid = false;
64  boost::shared_ptr<coral::ISessionProxy> session;
65  std::map<std::string,boost::weak_ptr<coral::ISessionProxy> >::iterator iS = m_sessions.find( lookupString( connectionString, accessMode ) );
66  if( iS != m_sessions.end() ){
67  if( !iS->second.expired() ){
68  session = iS->second.lock();
69  valid = true;
70  }
71  } else {
72  iS = m_sessions.insert(std::make_pair( lookupString( connectionString, accessMode ),boost::weak_ptr<coral::ISessionProxy>())).first;
73  }
74  if(!valid){
75  session.reset(m_connectionService.connect( connectionString, accessMode ));
76  boost::weak_ptr<coral::ISessionProxy> tmp(session);
77  iS->second.swap( tmp );
78  }
79  return SharedSession( session );
80 }
81 
83  const std::string& asRole,
84  coral::AccessMode accessMode ){
85  bool valid = false;
86  boost::shared_ptr<coral::ISessionProxy> session;
87  std::map<std::string,boost::weak_ptr<coral::ISessionProxy> >::iterator iS = m_sessions.find( lookupString( connectionString, asRole, accessMode ) );
88  if( iS != m_sessions.end() ){
89  if( !iS->second.expired() ){
90  session = iS->second.lock();
91  valid = true;
92  }
93  } else {
94  iS = m_sessions.insert(std::make_pair( lookupString( connectionString, asRole, accessMode ),boost::weak_ptr<coral::ISessionProxy>())).first;
95  }
96  if(!valid){
97  session.reset(m_connectionService.connect( connectionString, asRole, accessMode ));
98  boost::weak_ptr<coral::ISessionProxy> tmp(session);
99  iS->second.swap( tmp );
100  }
101  return SharedSession( session );
102 }
103 
104 
106  coral::AccessMode accessMode ){
107  std::stringstream lookupString;
108  lookupString << "["<<connectionString << "]_";
109  if(accessMode == coral::ReadOnly){
110  lookupString << "R";
111  } else {
112  lookupString << "W";
113  }
114  return lookupString.str();
115 }
116 
118  const std::string& role,
119  coral::AccessMode accessMode ){
120  std::string rolePrefix(role);
121  return rolePrefix+lookupString( connectionString, accessMode );
122 }
coral::ISessionProxy & get()
static std::string lookupString(const std::string &connectionString, coral::AccessMode accessMode)
coral::IConnectionServiceConfiguration & configuration()
coral::IConnectionService & connectionService()
SharedSession & operator=(const SharedSession &rhs)
boost::shared_ptr< coral::ISessionProxy > share()
boost::shared_ptr< coral::ISessionProxy > m_proxy
string connectionString
Definition: autoCondHLT.py:4
SharedSession connect(const std::string &connectionString, coral::AccessMode accessMode)
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
session
Definition: models.py:201