Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:52

0001 #ifndef ECALDBCONNECTION_HH
0002 #define ECALDBCONNECTION_HH
0003 
0004 #include "OnlineDB/Oracle/interface/Oracle.h"
0005 #include <string>
0006 #include <stdexcept>
0007 #include <iostream>
0008 
0009 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
0010 
0011 /**
0012  *  A wrapper class for the oracle Connection and Environment classes
0013  *  along with any OCCI-dependent methods that are useful for any database
0014  */
0015 class EcalDBConnection {
0016 public:
0017   /******************\
0018   -  public methods  -
0019   \******************/
0020 
0021   /**
0022    *  Constructor
0023    *  Makes a connection to an oracle database without TNS_ADMIN
0024    */
0025   EcalDBConnection(std::string host, std::string sid, std::string user, std::string pass, int port = 1521) noexcept(
0026       false);
0027 
0028   /**
0029    *  Constructor
0030    *  Makes a connection to an oracle database using TNS_ADMIN
0031    */
0032   EcalDBConnection(std::string sid, std::string user, std::string pass) noexcept(false);
0033 
0034   /**
0035    *  Destructor
0036    */
0037   virtual ~EcalDBConnection() noexcept(false);
0038 
0039   /**
0040    *  Get a new Statement
0041    */
0042   inline oracle::occi::Statement* createStatement() {
0043     std::cout << "Creating statement" << std::endl;
0044     return conn->createStatement();
0045   }
0046 
0047   inline void terminateStatement(oracle::occi::Statement* stmt) {
0048     std::cout << "Creating statement" << std::endl;
0049     conn->terminateStatement(stmt);
0050   }
0051 
0052   /** 
0053    *  Tranaction manaagement
0054    */
0055   inline void commit() { conn->commit(); }
0056   inline void rollback() { conn->rollback(); }
0057 
0058   /**
0059    *  Get a new clob locator
0060    */
0061   inline oracle::occi::Clob getClobLocator() { return oracle::occi::Clob(conn); }
0062 
0063   oracle::occi::Environment* getEnv() const { return env; };
0064   oracle::occi::Connection* getConn() const { return conn; };
0065 
0066 protected:
0067   /***********************\
0068   -  protected variables  -
0069   \***********************/
0070 
0071   oracle::occi::Environment* env;
0072   oracle::occi::Connection* conn;
0073   oracle::occi::Statement* stmt;
0074 
0075   std::string host;
0076   int port;
0077   std::string sid;
0078   std::string user;
0079   std::string pass;
0080 };
0081 
0082 #endif