Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:58

0001 #include <iostream>
0002 #include <string>
0003 #include <sstream>
0004 #include <cstdlib>
0005 #include <cstdlib>
0006 #include <stdexcept>
0007 #include "OnlineDB/Oracle/interface/Oracle.h"
0008 
0009 using namespace std;
0010 using namespace oracle::occi;
0011 
0012 #include "OnlineDB/EcalCondDB/interface/EcalDBConnection.h"
0013 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
0014 
0015 EcalDBConnection::EcalDBConnection(string host, string sid, string user, string pass, int port) noexcept(false) {
0016   stringstream ss;
0017   try {
0018     ss << "//" << host << ":" << port << "/" << sid;
0019 
0020     env = Environment::createEnvironment(Environment::OBJECT);
0021     conn = env->createConnection(user, pass, ss.str());
0022     stmt = conn->createStatement();
0023   } catch (SQLException &e) {
0024     cout << ss.str() << endl;
0025     throw(std::runtime_error("ERROR:  Connection Failed:  " + e.getMessage()));
0026   }
0027 
0028   this->host = host;
0029   this->sid = sid;
0030   this->user = user;
0031   this->pass = pass;
0032   this->port = port;
0033 }
0034 
0035 EcalDBConnection::EcalDBConnection(string sid, string user, string pass) noexcept(false) {
0036   try {
0037     env = Environment::createEnvironment(Environment::OBJECT);
0038     conn = env->createConnection(user, pass, sid);
0039     stmt = conn->createStatement();
0040   } catch (SQLException &e) {
0041     throw(std::runtime_error("ERROR:  Connection Failed:  " + e.getMessage()));
0042   }
0043 
0044   this->host = "";
0045   this->sid = sid;
0046   this->user = user;
0047   this->pass = pass;
0048 }
0049 
0050 EcalDBConnection::~EcalDBConnection() noexcept(false) {
0051   //Close database conection and terminate environment
0052   try {
0053     conn->terminateStatement(stmt);
0054     env->terminateConnection(conn);
0055     Environment::terminateEnvironment(env);
0056   } catch (SQLException &e) {
0057     throw(std::runtime_error("ERROR:  Destructor Failed:  " + e.getMessage()));
0058   }
0059 }