11 using namespace oracle::occi;
16 m_writeStmt =
nullptr;
31 this->checkConnection();
33 m_readStmt = m_conn->createStatement();
34 m_readStmt->setSQL(
"select FE_CONFIG_LIN_SQ.NextVal from DUAL ");
35 ResultSet* rset = m_readStmt->executeQuery();
36 while (rset->next()) {
37 result = rset->getInt(1);
40 m_conn->terminateStatement(m_readStmt);
44 throw(std::runtime_error(
std::string(
"FEConfigLinInfo::fetchNextId(): ") + e.getMessage()));
49 this->checkConnection();
53 next_id = fetchNextId();
57 m_writeStmt = m_conn->createStatement();
58 m_writeStmt->setSQL(
"INSERT INTO " + getTable() +
59 " ( lin_conf_id, tag, version, iov_id) "
60 " VALUES ( :1, :2, :3 , :4) ");
62 m_writeStmt->setInt(1, next_id);
66 throw(std::runtime_error(
std::string(
"FEConfigLinInfo::prepareWrite(): ") + e.getMessage()));
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 if (ci->first ==
"IOV_ID")
80 setIOVId(atoi(ci->second.c_str()));
85 this->checkConnection();
90 m_writeStmt->setString(2, this->getConfigTag());
91 m_writeStmt->setInt(3, this->getVersion());
92 m_writeStmt->setInt(4, this->getIOVId());
94 m_writeStmt->executeUpdate();
97 throw(std::runtime_error(
std::string(
"FEConfigLinInfo::writeDB(): ") + e.getMessage()));
100 if (!this->fetchID()) {
101 throw(std::runtime_error(
"FEConfigLinInfo::writeDB: Failed to write"));
106 this->checkConnection();
108 if (
result->getId() == 0 && (
result->getConfigTag().empty())) {
109 throw(std::runtime_error(
"FEConfigLinInfo::fetchData(): no Id defined for this FEConfigLinInfo "));
115 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
" where ( lin_conf_id= :1 or (tag=:2 AND version=:3 ) )");
116 m_readStmt->setInt(1,
result->getId());
117 m_readStmt->setString(2,
result->getConfigTag());
118 m_readStmt->setInt(3,
result->getVersion());
119 ResultSet* rset = m_readStmt->executeQuery();
125 result->setId(rset->getInt(1));
126 result->setConfigTag(rset->getString(2));
127 result->setVersion(rset->getInt(3));
128 result->setIOVId(rset->getInt(4));
129 Date dbdate = rset->getDate(5);
133 throw(std::runtime_error(
std::string(
"FEConfigLinInfo::fetchData(): ") + e.getMessage()));
138 this->checkConnection();
143 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
" where lin_conf_id = ( select max( lin_conf_id) from " +
145 ResultSet* rset = m_readStmt->executeQuery();
149 result->setId(rset->getInt(1));
150 result->setConfigTag(rset->getString(2));
151 result->setVersion(rset->getInt(3));
152 result->setIOVId(rset->getInt(4));
153 Date dbdate = rset->getDate(5);
157 throw(std::runtime_error(
std::string(
"FEConfigLinInfo::fetchData(): ") + e.getMessage()));
167 this->checkConnection();
170 Statement* stmt = m_conn->createStatement();
171 stmt->setSQL(
"SELECT lin_conf_id FROM " + getTable() +
" WHERE tag=:1 and version=:2 ");
173 stmt->setString(1, getConfigTag());
174 stmt->setInt(2, getVersion());
176 ResultSet* rset = stmt->executeQuery();
179 m_ID = rset->getInt(1);
183 m_conn->terminateStatement(stmt);
185 throw(std::runtime_error(
std::string(
"FEConfigLinInfo::fetchID: ") + e.getMessage()));
192 this->checkConnection();
197 Statement* stmt = m_conn->createStatement();
199 stmt->setSQL(
"SELECT * FROM fe_config_lin_info WHERE lin_conf_id = :1");
202 ResultSet* rset = stmt->executeQuery();
204 this->setId(rset->getInt(1));
205 this->setConfigTag(rset->getString(2));
206 this->setVersion(rset->getInt(3));
207 this->setIOVId(rset->getInt(4));
208 Date dbdate = rset->getDate(5);
209 this->setDBTime(dh.
dateToTm(dbdate));
211 throw(std::runtime_error(
"FEConfigLinInfo::setByID: Given config_id is not in the database"));
214 m_conn->terminateStatement(stmt);
216 throw(std::runtime_error(
std::string(
"FEConfigLinInfo::setByID: ") + e.getMessage()));
static unsigned int getId()
void prepareWrite() noexcept(false) override
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void fetchData(FEConfigLinInfo *result) noexcept(false)
int fetchNextId() noexcept(false)
oracle::occi::Statement Statement
void fetchLastData(FEConfigLinInfo *result) noexcept(false)
void setByID(int id) noexcept(false)
int fetchID() noexcept(false)
oracle::occi::SQLException SQLException
~FEConfigLinInfo() override
void writeDB() noexcept(false)
Tm dateToTm(oracle::occi::Date &date) const