CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CondCore/DBCommon/src/DbConnection.cc

Go to the documentation of this file.
00001 //local includes
00002 #include "CondCore/DBCommon/interface/DbConnection.h"
00003 #include "CondCore/DBCommon/interface/DbSession.h"
00004 #include "CondCore/DBCommon/interface/Exception.h"
00005 // coral includes
00006 //#include "CoralKernel/Context.h"
00007 //#include "CoralKernel/IHandle.h"
00008 //#include "RelationalAccess/ConnectionService.h"
00009 //#include "RelationalAccess/ISessionProxy.h"
00010 //#include "RelationalAccess/IConnectionServiceConfiguration.h"
00011 // ora includes
00012 #include "CondCore/ORA/interface/ConnectionPool.h"
00013 
00014 namespace cond {
00015   class DbConnection::ConnectionImpl {
00016     public:
00017       ConnectionImpl():
00018         m_initialized(false),
00019         m_connectionPool( new ora::ConnectionPool ),
00020         m_configuration(){
00021       }
00022 
00023       virtual ~ConnectionImpl(){
00024         close();
00025       }
00026 
00027       void close(){
00028         m_connectionPool.reset();
00029       }
00030       
00031       bool m_initialized;
00032       boost::shared_ptr<ora::ConnectionPool> m_connectionPool;
00033       DbConnectionConfiguration m_configuration;
00034   };  
00035 }
00036 
00037 cond::DbConnection::DbConnection():
00038   m_implementation(new ConnectionImpl()){
00039   configure();
00040 }
00041 
00042 cond::DbConnection::DbConnection(const DbConnection& conn):
00043   m_implementation( conn.m_implementation ){
00044 }
00045 
00046 cond::DbConnection::~DbConnection(){
00047 }
00048 
00049 cond::DbConnection& cond::DbConnection::operator=(const cond::DbConnection& conn)
00050 {
00051   if(this!=&conn) m_implementation = conn.m_implementation;
00052   return *this;
00053 }
00054 
00055 void cond::DbConnection::configure()
00056 {
00057   m_implementation->m_configuration.configure( m_implementation->m_connectionPool->configuration() );
00058   m_implementation->m_initialized = true;
00059 }
00060 
00061 void cond::DbConnection::configure( cond::DbConfigurationDefaults defaultItem ){
00062   m_implementation->m_configuration = DbConnectionConfiguration::defaultConfigurations()[ defaultItem ];
00063   configure();  
00064 }
00065 
00066 void 
00067 cond::DbConnection::configure( const edm::ParameterSet& connectionPset ){
00068   m_implementation->m_configuration.setParameters( connectionPset );
00069   configure();
00070 }
00071 
00072 cond::DbSession cond::DbConnection::createSession() const{
00073   if(!isOpen())
00074     throw cond::Exception("DbConnection::createSession: cannot create session. Connection has been closed.");
00075   return cond::DbSession( *this );
00076 }
00077 
00078 
00079 void cond::DbConnection::close()
00080 {
00081   m_implementation->close();
00082 }
00083 
00084 bool cond::DbConnection::isOpen() const
00085 {
00086   return m_implementation->m_connectionPool.get();
00087 }
00088   
00089 cond::DbConnectionConfiguration & cond::DbConnection::configuration()
00090 {
00091   return m_implementation->m_configuration;
00092 }
00093 
00094 cond::DbConnectionConfiguration const & cond::DbConnection::configuration() const
00095 {
00096   return m_implementation->m_configuration;
00097 }
00098 
00099 boost::shared_ptr<ora::ConnectionPool> cond::DbConnection::connectionPool() const {
00100   return m_implementation->m_connectionPool;
00101 }
00102 
00103 coral::IConnectionService& cond::DbConnection::connectionService() const {
00104   if(!isOpen())
00105     throw cond::Exception("DbConnection::connectionService: cannot get connection service. Connection has not been open.");
00106   return m_implementation->m_connectionPool->connectionService();
00107 }
00108 
00109 const coral::IMonitoringReporter& cond::DbConnection::monitoringReporter() const {
00110   if(!isOpen())
00111     throw cond::Exception("DbConnection::monitoringReporter: cannot get connection service. Connection has not been open.");
00112   return m_implementation->m_connectionPool->connectionService().monitoringReporter();
00113 }
00114 
00115 coral::IWebCacheControl& cond::DbConnection::webCacheControl() const{
00116   if(!isOpen())
00117     throw cond::Exception("DbConnection::webCacheControl: cannot get connection service. Connection has not been open.");
00118   return m_implementation->m_connectionPool->connectionService().webCacheControl();
00119 }
00120