13 #define SET_INT(statement, paramNum, paramVal) \ 14 if (paramVal != MY_NULL) { \ 15 statement->setInt(paramNum, paramVal); \ 17 statement->setNull(paramNum, OCCINUMBER); \ 19 #define SET_STRING(statement, paramNum, paramVal) \ 20 if (!paramVal.empty()) { \ 21 statement->setString(paramNum, paramVal); \ 23 statement->setNull(paramNum, OCCICHAR); \ 26 int getInt(ResultSet* rset,
int ipar) {
return rset->isNull(ipar) ?
MY_NULL : rset->getInt(ipar); }
31 m_writeStmt =
nullptr;
57 this->checkConnection();
59 m_readStmt = m_conn->createStatement();
60 m_readStmt->setSQL(
"select fe_daq_conDfig_sq.nextVal from dual");
61 ResultSet* rset = m_readStmt->executeQuery();
62 while (rset->next()) {
65 m_conn->terminateStatement(m_readStmt);
69 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::fetchNextId(): ") +
e.getMessage()));
74 this->checkConnection();
75 int next_id = fetchNextId();
78 m_writeStmt = m_conn->createStatement();
80 "INSERT INTO FE_DAQ_CONFIG ( config_id, tag, version, ped_id, " 81 " del_id, wei_id,bxt_id, btt_id, tr_bxt_id, tr_btt_id, user_comment ) " 82 "VALUES ( :1, :2, :3, :4, :5, :6, :7 ,:8, :9, :10, :11 )");
84 m_writeStmt->setInt(1, next_id);
88 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::prepareWrite(): ") +
e.getMessage()));
96 for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
97 if (ci->first ==
"VERSION")
98 setVersion(atoi(ci->second.c_str()));
99 if (ci->first ==
"PED_ID")
100 setPedestalId(atoi(ci->second.c_str()));
101 if (ci->first ==
"DEL_ID")
102 setDelayId(atoi(ci->second.c_str()));
103 if (ci->first ==
"WEI_ID")
104 setWeightId(atoi(ci->second.c_str()));
106 if (ci->first ==
"BXT_ID")
107 setBadXtId(atoi(ci->second.c_str()));
108 if (ci->first ==
"BTT_ID")
109 setBadTTId(atoi(ci->second.c_str()));
110 if (ci->first ==
"TRIG_BXT_ID")
111 setTriggerBadXtId(atoi(ci->second.c_str()));
112 if (ci->first ==
"TRIG_BTT_ID")
113 setTriggerBadTTId(atoi(ci->second.c_str()));
115 if (ci->first ==
"COMMENT" || ci->first ==
"USER_COMMENT")
116 setComment(ci->second);
121 this->checkConnection();
122 this->checkPrepare();
126 m_writeStmt->setString(2, this->getConfigTag());
127 m_writeStmt->setInt(3, this->getVersion());
128 SET_INT(m_writeStmt, 4, this->getPedestalId());
129 SET_INT(m_writeStmt, 5, this->getDelayId());
130 SET_INT(m_writeStmt, 6, this->getWeightId());
131 SET_INT(m_writeStmt, 7, this->getBadXtId());
132 SET_INT(m_writeStmt, 8, this->getBadTTId());
133 SET_INT(m_writeStmt, 9, this->getTriggerBadXtId());
134 SET_INT(m_writeStmt, 10, this->getTriggerBadTTId());
136 m_writeStmt->setString(11, this->getComment());
138 m_writeStmt->executeUpdate();
141 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::writeDB(): ") +
e.getMessage()));
144 if (!this->fetchID()) {
145 throw(std::runtime_error(
"ODFEDAQConfig::writeDB: Failed to write"));
150 this->checkConnection();
152 if (
result->getId() == 0 && (
result->getConfigTag().empty())) {
153 throw(std::runtime_error(
"ODFEDAQConfig::fetchData(): no Id defined for this ODFEDAQConfig "));
156 m_readStmt = m_conn->createStatement();
157 if (!
result->getConfigTag().empty() &&
result->getVersion() == 0) {
159 std::cout <<
"using new method : retrieving last version for this tag " << endl;
161 this->checkConnection();
163 m_readStmt->setSQL(
"select max(version) from " + getTable() +
" where tag=:tag ");
164 m_readStmt->setString(1,
result->getConfigTag());
165 std::cout <<
"Getting last ver" << std::endl << std::flush;
166 ResultSet* rset = m_readStmt->executeQuery();
167 while (rset->next()) {
168 new_version = rset->getInt(1);
170 m_conn->terminateStatement(m_readStmt);
174 result->setVersion(new_version);
177 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::fetchData(): ") +
e.getMessage()));
182 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
" where ( config_id = :1 or (tag=:2 AND version=:3 ) )");
183 m_readStmt->setInt(1,
result->getId());
184 m_readStmt->setString(2,
result->getConfigTag());
185 m_readStmt->setInt(3,
result->getVersion());
186 ResultSet* rset = m_readStmt->executeQuery();
192 result->setId(rset->getInt(1));
193 result->setConfigTag(rset->getString(2));
194 result->setVersion(rset->getInt(3));
203 result->setComment(rset->getString(11));
206 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::fetchData(): ") +
e.getMessage()));
216 this->checkConnection();
219 Statement* stmt = m_conn->createStatement();
220 stmt->setSQL(
"SELECT config_id FROM " + getTable() +
"WHERE tag=:1 and version=:2 ");
222 stmt->setString(1, getConfigTag());
223 stmt->setInt(2, getVersion());
225 ResultSet* rset = stmt->executeQuery();
228 m_ID = rset->getInt(1);
232 m_conn->terminateStatement(stmt);
234 throw(std::runtime_error(
std::string(
"ODFEDAQConfig::fetchID: ") +
e.getMessage()));
int fetchNextId() noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void prepareWrite() noexcept(false) override
int getInt(ResultSet *rset, int ipar)
~ODFEDAQConfig() override
int fetchID() noexcept(false)
#define SET_INT(statement, paramNum, paramVal)
oracle::occi::Statement Statement
void fetchData(ODFEDAQConfig *result) noexcept(false)
oracle::occi::SQLException SQLException
void clear(HadCaloObj &c)
void writeDB() noexcept(false)