CMS 3D CMS Logo

ODJBH4Cycle.cc
Go to the documentation of this file.
1 #include <stdexcept>
3 
5 
6 using namespace std;
7 using namespace oracle::occi;
8 
10 {
11  m_env = nullptr;
12  m_conn = nullptr;
13  m_writeStmt = nullptr;
14  m_readStmt = nullptr;
15  //
16  m_ID = 0;
17  m_jbh4_config_id = 0;
18 }
19 
20 
22 {
23 }
24 
25 
28 {
29  this->checkConnection();
30 
31  try {
32  m_writeStmt = m_conn->createStatement();
33  m_writeStmt->setSQL("INSERT INTO ECAL_JBH4_Cycle (cycle_id, jbh4_configuration_id ) "
34  "VALUES (:1, :2 )");
35  } catch (SQLException &e) {
36  throw(std::runtime_error("ODJBH4Cycle::prepareWrite(): "+e.getMessage()));
37  }
38 }
39 
40 
42 {
43  this->checkConnection();
44  this->checkPrepare();
45 
46  try {
47 
48  m_writeStmt->setInt(1, this->getId());
49  m_writeStmt->setInt(2, this->getJBH4ConfigurationID());
50 
51  m_writeStmt->executeUpdate();
52 
53 
54  } catch (SQLException &e) {
55  throw(std::runtime_error("ODJBH4Cycle::writeDB: "+e.getMessage()));
56  }
57 
58  // Now get the ID
59  if (!this->fetchID()) {
60  throw(std::runtime_error("ODJBH4Cycle::writeDB: Failed to write"));
61  }
62 
63 
64 }
65 
67  m_jbh4_config_id=0;
68 }
69 
70 
73 {
74  // Return from memory if available
75  if (m_ID) {
76  return m_ID;
77  }
78 
79  this->checkConnection();
80 
81  try {
82  Statement* stmt = m_conn->createStatement();
83  stmt->setSQL("SELECT cycle_id, jbh4_configuration_id FROM ecal_jbh4_cycle "
84  "WHERE cycle_id = :1 ");
85  stmt->setInt(1, m_ID);
86  ResultSet* rset = stmt->executeQuery();
87 
88  if (rset->next()) {
89  m_ID = rset->getInt(1);
90  m_jbh4_config_id = rset->getInt(2);
91  } else {
92  m_ID = 0;
93  }
94  m_conn->terminateStatement(stmt);
95  } catch (SQLException &e) {
96  throw(std::runtime_error("ODJBH4Cycle::fetchID: "+e.getMessage()));
97  }
98 
99  return m_ID;
100 }
101 
102 
103 
104 void ODJBH4Cycle::setByID(int id)
105  noexcept(false)
106 {
107  this->checkConnection();
108 
109 
110  try {
111  Statement* stmt = m_conn->createStatement();
112  stmt->setSQL("SELECT cycle_id, jbh4_configuration_id FROM ecal_jbh4_cycle "
113  "WHERE cycle_id = :1 ");
114  stmt->setInt(1, id);
115  ResultSet* rset = stmt->executeQuery();
116 
117  if (rset->next()) {
118  m_ID = rset->getInt(1);
119  m_jbh4_config_id = rset->getInt(2);
120  } else {
121  m_ID = 0;
122  }
123  m_conn->terminateStatement(stmt);
124  } catch (SQLException &e) {
125  throw(std::runtime_error("ODJBH4Cycle::fetchID: "+e.getMessage()));
126  }
127 }
128 
129 
130 
132  noexcept(false)
133 {
134  this->checkConnection();
135  result->clear();
136 
137  if(result->getId()==0){
138  throw(std::runtime_error("ODJBH4Config::fetchData(): no Id defined for this ODJBH4Config "));
139  }
140 
141  try {
142 
143  m_readStmt->setSQL("SELECT jbh4_configuration_id FROM ecal_jbh4_cycle "
144  "WHERE cycle_id = :1 ");
145 
146  m_readStmt->setInt(1, result->getId());
147  ResultSet* rset = m_readStmt->executeQuery();
148 
149  rset->next();
150 
151  result->setJBH4ConfigurationID( rset->getInt(1) );
152 
153  } catch (SQLException &e) {
154  throw(std::runtime_error("ODJBH4Cycle::fetchData(): "+e.getMessage()));
155  }
156 }
157 
159  noexcept(false)
160 {
161  try {
162 
163  prepareWrite();
164  writeDB();
165  m_conn->commit();
166  terminateWriteStatement();
167  } catch (std::runtime_error &e) {
168  m_conn->rollback();
169  throw(e);
170  } catch (...) {
171  m_conn->rollback();
172  throw(std::runtime_error("EcalCondDBInterface::insertDataSet: Unknown exception caught"));
173  }
174 }
175 
static unsigned int getId()
int fetchID() noexcept(false)
Definition: ODJBH4Cycle.cc:71
void clear()
Definition: ODJBH4Cycle.cc:66
void writeDB() noexcept(false)
Definition: ODJBH4Cycle.cc:41
void setByID(int id) noexcept(false)
Definition: ODJBH4Cycle.cc:104
void insertConfig() noexcept(false)
Definition: ODJBH4Cycle.cc:158
~ODJBH4Cycle() override
Definition: ODJBH4Cycle.cc:21
#define noexcept
oracle::occi::Statement Statement
Definition: IODConfig.h:23
void prepareWrite() noexcept(false) override
Definition: ODJBH4Cycle.cc:26
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
void fetchData(ODJBH4Cycle *result) noexcept(false)
Definition: ODJBH4Cycle.cc:131