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 
36  return m_proxy.get();
37 }
38 
40  m_proxy.reset();
41 }
42 
43 ora::ConnectionPool::ConnectionPool():m_connectionService(),m_sessions(){
44 }
45 
47 }
48 
49 coral::IConnectionService& ora::ConnectionPool::connectionService(){
50  return m_connectionService;
51 }
52 coral::IConnectionServiceConfiguration& ora::ConnectionPool::configuration(){
53  return m_connectionService.configuration();
54 }
55 
57  coral::AccessMode accessMode ){
58  bool valid = false;
59  boost::shared_ptr<coral::ISessionProxy> session;
60  std::map<std::string,boost::weak_ptr<coral::ISessionProxy> >::iterator iS = m_sessions.find( lookupString( connectionString, accessMode ) );
61  if( iS != m_sessions.end() ){
62  if( !iS->second.expired() ){
63  session = iS->second.lock();
64  valid = true;
65  }
66  } else {
67  iS = m_sessions.insert(std::make_pair( lookupString( connectionString, accessMode ),boost::weak_ptr<coral::ISessionProxy>())).first;
68  }
69  if(!valid){
70  session.reset(m_connectionService.connect( connectionString, accessMode ));
71  boost::weak_ptr<coral::ISessionProxy> tmp(session);
72  iS->second.swap( tmp );
73  }
74  return SharedSession( session );
75 }
76 
78  const std::string& asRole,
79  coral::AccessMode accessMode ){
80  bool valid = false;
81  boost::shared_ptr<coral::ISessionProxy> session;
82  std::map<std::string,boost::weak_ptr<coral::ISessionProxy> >::iterator iS = m_sessions.find( lookupString( connectionString, asRole, accessMode ) );
83  if( iS != m_sessions.end() ){
84  if( !iS->second.expired() ){
85  session = iS->second.lock();
86  valid = true;
87  }
88  } else {
89  iS = m_sessions.insert(std::make_pair( lookupString( connectionString, asRole, accessMode ),boost::weak_ptr<coral::ISessionProxy>())).first;
90  }
91  if(!valid){
92  session.reset(m_connectionService.connect( connectionString, asRole, accessMode ));
93  boost::weak_ptr<coral::ISessionProxy> tmp(session);
94  iS->second.swap( tmp );
95  }
96  return SharedSession( session );
97 }
98 
99 
101  coral::AccessMode accessMode ){
102  std::stringstream lookupString;
103  lookupString << "["<<connectionString << "]_";
104  if(accessMode == coral::ReadOnly){
105  lookupString << "R";
106  } else {
107  lookupString << "W";
108  }
109  return lookupString.str();
110 }
111 
113  const std::string& role,
114  coral::AccessMode accessMode ){
115  std::string rolePrefix(role);
116  return rolePrefix+lookupString( connectionString, accessMode );
117 }
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 > m_proxy
SharedSession connect(const std::string &connectionString, coral::AccessMode accessMode)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10