CMS 3D CMS Logo

ODFEDelaysInfo.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <cstdlib>
3 #include <string>
4 #include <cstring>
6 
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
13  m_env = nullptr;
14  m_conn = nullptr;
15  m_writeStmt = nullptr;
16  m_readStmt = nullptr;
17  m_config_tag = "";
18  m_version = 0;
19  m_ID = 0;
20  clear();
21 }
22 
24 
26 
28  int result = 0;
29  try {
30  this->checkConnection();
31 
32  m_readStmt = m_conn->createStatement();
33  m_readStmt->setSQL("select COND2CONF_INFO_SQ.NextVal from DUAL ");
34  ResultSet* rset = m_readStmt->executeQuery();
35  while (rset->next()) {
36  result = rset->getInt(1);
37  }
38  result++;
39  m_conn->terminateStatement(m_readStmt);
40  std::cout << " the id is going to be : " << result << endl;
41  return result;
42 
43  } catch (SQLException& e) {
44  throw(std::runtime_error(std::string("ODFEDelaysInfo::fetchNextId(): ") + e.getMessage()));
45  }
46 }
47 
49  this->checkConnection();
50 
51  int next_id = 0;
52  if (getId() == 0) {
53  next_id = fetchNextId();
54  }
55 
56  try {
57  m_writeStmt = m_conn->createStatement();
58  m_writeStmt->setSQL("INSERT INTO " + getTable() +
59  " ( rec_id, tag, version) "
60  " VALUES ( :1, :2, :3 ) ");
61 
62  m_writeStmt->setInt(1, next_id);
63  m_ID = next_id;
64 
65  } catch (SQLException& e) {
66  throw(std::runtime_error(std::string("ODFEDelaysInfo::prepareWrite(): ") + e.getMessage()));
67  }
68 }
69 
70 void ODFEDelaysInfo::setParameters(const std::map<string, string>& my_keys_map) {
71  // parses the result of the XML parser that is a map of
72  // string string with variable name variable value
73 
74  for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
75  if (ci->first == "VERSION")
76  setVersion(atoi(ci->second.c_str()));
77  if (ci->first == "TAG")
78  setConfigTag(ci->second);
79  }
80 }
81 
82 void ODFEDelaysInfo::writeDB() noexcept(false) {
83  this->checkConnection();
84  this->checkPrepare();
85 
86  try {
87  // number 1 is the id
88  m_writeStmt->setString(2, this->getConfigTag());
89  m_writeStmt->setInt(3, this->getVersion());
90 
91  m_writeStmt->executeUpdate();
92 
93  } catch (SQLException& e) {
94  throw(std::runtime_error(std::string("ODFEDelaysInfo::writeDB(): ") + e.getMessage()));
95  }
96 
97  // Now get the ID
98  if (!this->fetchID()) {
99  throw(std::runtime_error("ODFEDelaysInfo::writeDB: Failed to write"));
100  } else {
101  int old_version = this->getVersion();
102  m_readStmt = m_conn->createStatement();
103  this->fetchData(this);
104  m_conn->terminateStatement(m_readStmt);
105  if (this->getVersion() != old_version)
106  std::cout << "ODFEDelaysInfo>>WARNING version is " << getVersion() << endl;
107  }
108 }
109 
111  this->checkConnection();
112 
113  result->clear();
114  if (result->getId() == 0 && (result->getConfigTag().empty())) {
115  throw(std::runtime_error("ODFEDelaysInfo::fetchData(): no Id defined for this ODFEDelaysInfo "));
116  }
117 
118  try {
119  if (result->getId() != 0) {
120  m_readStmt->setSQL("SELECT * FROM " + getTable() + " where rec_id = :1 ");
121  m_readStmt->setInt(1, result->getId());
122  } else if (!result->getConfigTag().empty()) {
123  m_readStmt->setSQL("SELECT * FROM " + getTable() + " where tag=:1 AND version=:2 ");
124  m_readStmt->setString(1, result->getConfigTag());
125  m_readStmt->setInt(2, result->getVersion());
126  } else {
127  // we should never pass here
128  throw(std::runtime_error("ODFEDelaysInfo::fetchData(): no Id defined for this ODFEDelaysInfo "));
129  }
130 
131  ResultSet* rset = m_readStmt->executeQuery();
132  rset->next();
133 
134  // 1 is the id and 2 is the config tag and 3 is the version
135 
136  result->setId(rset->getInt(1));
137  result->setConfigTag(rset->getString(2));
138  result->setVersion(rset->getInt(3));
139 
140  } catch (SQLException& e) {
141  throw(std::runtime_error(std::string("ODFEDelaysInfo::fetchData(): ") + e.getMessage()));
142  }
143 }
144 
146  // Return from memory if available
147  if (m_ID != 0) {
148  return m_ID;
149  }
150 
151  this->checkConnection();
152 
153  try {
154  Statement* stmt = m_conn->createStatement();
155  stmt->setSQL("SELECT rec_id FROM " + getTable() + "WHERE tag=:1 and version=:2 ");
156 
157  stmt->setString(1, getConfigTag());
158  stmt->setInt(2, getVersion());
159 
160  ResultSet* rset = stmt->executeQuery();
161 
162  if (rset->next()) {
163  m_ID = rset->getInt(1);
164  } else {
165  m_ID = 0;
166  }
167  m_conn->terminateStatement(stmt);
168  } catch (SQLException& e) {
169  throw(std::runtime_error(std::string("ODFEDelaysInfo::fetchID: ") + e.getMessage()));
170  }
171 
172  return m_ID;
173 }
ODFEDelaysInfo::ODFEDelaysInfo
ODFEDelaysInfo()
Definition: ODFEDelaysInfo.cc:12
ODFEDelaysInfo::clear
void clear()
Definition: ODFEDelaysInfo.cc:23
funct::false
false
Definition: Factorize.h:34
ODFEDelaysInfo::fetchData
void fetchData(ODFEDelaysInfo *result) noexcept(false)
Definition: ODFEDelaysInfo.cc:110
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
gather_cfg.cout
cout
Definition: gather_cfg.py:144
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
ODFEDelaysInfo
Definition: ODFEDelaysInfo.h:9
ODFEDelaysInfo::~ODFEDelaysInfo
~ODFEDelaysInfo() override
Definition: ODFEDelaysInfo.cc:25
oracle::occi
Definition: ConnectionManager.h:7
ODFEDelaysInfo::writeDB
void writeDB() noexcept(false)
Definition: ODFEDelaysInfo.cc:82
ODFEDelaysInfo::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODFEDelaysInfo.cc:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
clear
void clear(HadCaloObj &c)
Definition: data.h:124
ODFEDelaysInfo::fetchID
int fetchID() noexcept(false)
Definition: ODFEDelaysInfo.cc:145
ODFEDelaysInfo::fetchNextId
int fetchNextId() noexcept(false)
Definition: ODFEDelaysInfo.cc:27
std
Definition: JetResolutionObject.h:76
ODFEDelaysInfo.h
ODFEDelaysInfo::setParameters
void setParameters(const std::map< std::string, std::string > &my_keys_map)
Definition: ODFEDelaysInfo.cc:70
Oracle.h
mps_fire.result
result
Definition: mps_fire.py:303
getId
static unsigned int getId()
Definition: DQMStoreStats.h:129
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37