CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
ConnectionManager Class Reference

#include <ConnectionManager.h>

Public Member Functions

bool connect ()
 
 ConnectionManager ()
 
void disconnect ()
 
oracle::occi::Statement * getStatement (const std::string &query)
 

Private Attributes

oracle::occi::Connection * conn
 
oracle::occi::Environment * env
 

Detailed Description

Definition at line 14 of file ConnectionManager.h.

Constructor & Destructor Documentation

◆ ConnectionManager()

ConnectionManager::ConnectionManager ( )

Definition at line 9 of file ConnectionManager.cc.

9 : env(nullptr), conn(nullptr) {}
oracle::occi::Connection * conn
oracle::occi::Environment * env

Member Function Documentation

◆ connect()

bool ConnectionManager::connect ( )

Definition at line 20 of file ConnectionManager.cc.

References clean(), conn, SiStripPI::DEFAULT, env, f, keyFile(), EcalCondDBWriter_cfi::password, alignCSCRings::s, AlCaHLTBitMon_QueryRunRegistry::string, and crabTemplate::username.

Referenced by o2o_db_cfgmap.DbManagerDAQ::update_hashmap().

20  {
21  if (env != nullptr)
22  return true;
23  std::string username, password, database;
24 
25  char s[100];
26  FILE* f = fopen(keyFile.c_str(), "r");
27  s[0] = 0;
28  fgets(s, 100, f);
29  clean(s);
30  username = s;
31  s[0] = 0;
32  fgets(s, 100, f);
33  clean(s);
34  password = s;
35  s[0] = 0;
36  fgets(s, 100, f);
37  clean(s);
38  database = s;
39  fclose(f);
40 
41  // printf("'%s' '%s' '%s'\n",username.c_str(),password.c_str(),database.c_str());
42  try {
43  env = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::DEFAULT);
44  conn = env->createConnection(username, password, database);
45  } catch (...) {
46  return false;
47  }
48  return true;
49 }
oracle::occi::Connection * conn
static void clean(char *s)
double f[11][100]
static const std::string keyFile("/nfshome0/hcalsw/.ReadOMDSKey")
oracle::occi::Environment * env

◆ disconnect()

void ConnectionManager::disconnect ( )

Definition at line 55 of file ConnectionManager.cc.

References conn, and env.

55  {
56  if (env == nullptr)
57  return;
58  env->terminateConnection(conn);
59  oracle::occi::Environment::terminateEnvironment(env);
60  env = nullptr;
61  conn = nullptr;
62 }
oracle::occi::Connection * conn
oracle::occi::Environment * env

◆ getStatement()

oracle::occi::Statement * ConnectionManager::getStatement ( const std::string &  query)

Definition at line 50 of file ConnectionManager.cc.

References conn, and env.

50  {
51  if (env == nullptr)
52  return nullptr;
53  return conn->createStatement(query);
54 }
oracle::occi::Connection * conn
Definition: query.py:1
oracle::occi::Environment * env

Member Data Documentation

◆ conn

oracle::occi::Connection* ConnectionManager::conn
private

Definition at line 23 of file ConnectionManager.h.

Referenced by connect(), disconnect(), and getStatement().

◆ env

oracle::occi::Environment* ConnectionManager::env
private

Definition at line 22 of file ConnectionManager.h.

Referenced by connect(), disconnect(), and getStatement().