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_LUT_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(
"FEConfigLUTInfo::fetchNextId(): ") + e.getMessage()));
49 this->checkConnection();
53 next_id = fetchNextId();
57 m_writeStmt = m_conn->createStatement();
58 m_writeStmt->setSQL(
"INSERT INTO " + getTable() +
59 " ( lut_conf_id, tag, version, number_of_groups) "
60 " VALUES ( :1, :2, :3 , :4) ");
62 m_writeStmt->setInt(1, next_id);
66 throw(std::runtime_error(
std::string(
"FEConfigLUTInfo::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 ==
"NUMBER_OF_GROUPS")
80 setNumberOfGroups(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->getNumberOfGroups());
94 m_writeStmt->executeUpdate();
97 throw(std::runtime_error(
std::string(
"FEConfigLUTInfo::writeDB(): ") + e.getMessage()));
100 if (!this->fetchID()) {
101 throw(std::runtime_error(
"FEConfigLUTInfo::writeDB: Failed to write"));
106 this->checkConnection();
108 if (
result->getId() == 0 && (
result->getConfigTag().empty())) {
109 throw(std::runtime_error(
"FEConfigLUTInfo::fetchData(): no Id defined for this FEConfigLUTInfo "));
115 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
" where ( lut_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->setNumberOfGroups(rset->getInt(4));
129 Date dbdate = rset->getDate(5);
133 throw(std::runtime_error(
std::string(
"FEConfigLUTInfo::fetchData(): ") + e.getMessage()));
138 this->checkConnection();
143 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
" where lut_conf_id = ( select max( lut_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->setNumberOfGroups(rset->getInt(4));
153 Date dbdate = rset->getDate(5);
157 throw(std::runtime_error(
std::string(
"FEConfigLUTInfo::fetchData(): ") + e.getMessage()));
167 this->checkConnection();
170 Statement* stmt = m_conn->createStatement();
171 stmt->setSQL(
"SELECT lut_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(
"FEConfigLUTInfo::fetchID: ") + e.getMessage()));
192 this->checkConnection();
197 Statement* stmt = m_conn->createStatement();
199 stmt->setSQL(
"SELECT * FROM fe_config_lut_info WHERE lut_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->setNumberOfGroups(rset->getInt(4));
208 Date dbdate = rset->getDate(5);
209 this->setDBTime(dh.
dateToTm(dbdate));
211 throw(std::runtime_error(
"FEConfigLUTInfo::setByID: Given config_id is not in the database"));
214 m_conn->terminateStatement(stmt);
216 throw(std::runtime_error(
std::string(
"FEConfigLUTInfo::setByID: ") + e.getMessage()));
static unsigned int getId()
void prepareWrite() noexcept(false) override
void fetchData(FEConfigLUTInfo *result) noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void fetchLastData(FEConfigLUTInfo *result) noexcept(false)
~FEConfigLUTInfo() override
oracle::occi::Statement Statement
int fetchID() noexcept(false)
int fetchNextId() noexcept(false)
oracle::occi::SQLException SQLException
void writeDB() noexcept(false)
void setByID(int id) noexcept(false)
Tm dateToTm(oracle::occi::Date &date) const