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) {}

Member Function Documentation

◆ connect()

bool ConnectionManager::connect ( )

Definition at line 20 of file ConnectionManager.cc.

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 }

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

Referenced by o2o_db_cfgmap.DbManagerDAQ::update_hashmap().

◆ disconnect()

void ConnectionManager::disconnect ( )

Definition at line 55 of file ConnectionManager.cc.

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

References conn, and env.

◆ getStatement()

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

Definition at line 50 of file ConnectionManager.cc.

50  {
51  if (env == nullptr)
52  return nullptr;
53  return conn->createStatement(query);
54 }

References conn, and 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().

f
double f[11][100]
Definition: MuScleFitUtils.cc:78
SiStripPI::DEFAULT
Definition: SiStripPayloadInspectorHelper.h:782
alignCSCRings.s
s
Definition: alignCSCRings.py:92
ConnectionManager::env
oracle::occi::Environment * env
Definition: ConnectionManager.h:22
EcalCondDBWriter_cfi.password
password
Definition: EcalCondDBWriter_cfi.py:62
query
Definition: query.py:1
keyFile
static const std::string keyFile("/nfshome0/hcalsw/.ReadOMDSKey")
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
personalPlayback.username
username
Definition: personalPlayback.py:449
clean
static void clean(char *s)
Definition: ConnectionManager.cc:13
ConnectionManager::conn
oracle::occi::Connection * conn
Definition: ConnectionManager.h:23