00001 /* 00002 * See header file for a description of this class. 00003 * 00004 * $Date: 2008/01/22 19:05:48 $ 00005 * $Revision: 1.3 $ 00006 * \author Paolo Ronchese INFN Padova 00007 * 00008 */ 00009 00010 //----------------------- 00011 // This Class' Header -- 00012 //----------------------- 00013 #include "CondTools/DT/interface/DTDBSession.h" 00014 00015 //------------------------------- 00016 // Collaborating Class Headers -- 00017 //------------------------------- 00018 00019 #include "FWCore/Catalog/interface/SiteLocalConfig.h" 00020 #include "FWCore/ServiceRegistry/interface/Service.h" 00021 #include "CondCore/DBCommon/interface/PoolTransaction.h" 00022 //#include "CondCore/DBCommon/interface/PoolStorageManager.h" 00023 //#include "CondCore/DBCommon/interface/RelationalStorageManager.h" 00024 //#include "CondCore/DBCommon/interface/ConnectMode.h" 00025 #include "CondCore/DBCommon/interface/MessageLevel.h" 00026 //#include "CondCore/DBCommon/src/ServiceLoader.h" 00027 //#include "RelationalAccess/IConnectionService.h" 00028 //#include "RelationalAccess/IWebCacheControl.h" 00029 #include <vector> 00030 00031 #include "CondCore/DBCommon/interface/SessionConfiguration.h" 00032 00033 00034 00035 //--------------- 00036 // C++ Headers -- 00037 //--------------- 00038 00039 00040 //------------------- 00041 // Initializations -- 00042 //------------------- 00043 00044 00045 //---------------- 00046 // Constructors -- 00047 //---------------- 00048 DTDBSession::DTDBSession( const std::string& dbFile, 00049 const std::string& dbCatalog, 00050 const std::string& auth_path, 00051 bool siteLocalConfig ): 00052 m_session( 0 ), 00053 m_pooldb( 0 ) { 00054 00055 std::string connect( dbFile ); 00056 std::string catconnect( dbCatalog ); 00057 // int connectionTimeOut = 600; 00058 // int connectionRetrialPeriod = 30; 00059 // int connectionRetrialTimeOut = 180; 00060 m_session = new cond::DBSession(); 00061 if ( auth_path.empty() ) { 00062 m_session->configuration().setAuthenticationMethod( cond::Env ); 00063 } 00064 else { 00065 m_session->configuration().setAuthenticationMethod( cond::XML ); 00066 m_session->configuration().setAuthenticationPath( auth_path ); 00067 } 00068 m_session->configuration().setMessageLevel( cond::Error ); 00069 /* 00070 m_session->configuration().connectionConfiguration()->enableConnectionSharing(); 00071 m_session->configuration().connectionConfiguration()->setConnectionTimeOut( 00072 connectionTimeOut ); 00073 m_session->configuration().connectionConfiguration()-> 00074 enableReadOnlySessionOnUpdateConnections(); 00075 m_session->configuration().connectionConfiguration()-> 00076 setConnectionRetrialPeriod( connectionRetrialPeriod ); 00077 m_session->configuration().connectionConfiguration()-> 00078 setConnectionRetrialTimeOut( connectionRetrialTimeOut ); 00079 */ 00080 m_session->open(); 00081 if ( siteLocalConfig ) { 00082 edm::Service<edm::SiteLocalConfig> localconfservice; 00083 if( !localconfservice.isAvailable() ){ 00084 throw cms::Exception("edm::SiteLocalConfigService is not available"); 00085 } 00086 } 00087 m_connection = new cond::Connection( connect, -1 ); 00088 // m_pooldb = new cond::PoolStorageManager( connect, catconnect, m_session ); 00089 00090 } 00091 00092 //-------------- 00093 // Destructor -- 00094 //-------------- 00095 DTDBSession::~DTDBSession() { 00096 delete m_connection; 00097 delete m_session; 00098 } 00099 00100 //-------------- 00101 // Operations -- 00102 //-------------- 00104 cond::PoolTransaction* DTDBSession::poolDB() const { 00105 //cond::PoolStorageManager* DTDBSession::poolDB() const { 00106 return m_pooldb; 00107 } 00108 00109 00111 void DTDBSession::connect( bool readOnly ) { 00112 m_connection->connect( m_session ); 00113 m_pooldb = &( m_connection->poolTransaction() ); 00114 m_pooldb->start( readOnly ); 00115 // m_pooldb->connect(); 00116 // m_pooldb->startTransaction( readOnly ); 00117 return; 00118 } 00119 00120 00122 void DTDBSession::disconnect() { 00123 m_pooldb->commit(); 00124 m_connection->disconnect(); 00125 // m_pooldb->commit(); 00126 // m_pooldb->disconnect(); 00127 return; 00128 }