16 m_writeStmt =
nullptr;
31 this->checkConnection();
33 m_readStmt = m_conn->createStatement();
34 m_readStmt->setSQL(
"select FE_CONFIG_SPI_SQ.NextVal from DUAL ");
35 ResultSet* rset = m_readStmt->executeQuery();
36 while (rset->next()) {
40 m_conn->terminateStatement(m_readStmt);
44 throw(std::runtime_error(
std::string(
"FEConfigSpikeInfo::fetchNextId(): ") +
e.getMessage()));
49 this->checkConnection();
53 next_id = fetchNextId();
57 m_writeStmt = m_conn->createStatement();
58 m_writeStmt->setSQL(
"INSERT INTO " + getTable() +
59 " ( spi_conf_id, tag, version ) " 60 " VALUES ( :1, :2, :3 ) ");
62 m_writeStmt->setInt(1, next_id);
66 throw(std::runtime_error(
std::string(
"FEConfigSpikeInfo::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);
83 this->checkConnection();
88 m_writeStmt->setString(2, this->getConfigTag());
89 m_writeStmt->setInt(3, this->getVersion());
91 m_writeStmt->executeUpdate();
94 throw(std::runtime_error(
std::string(
"FEConfigSpikeInfo::writeDB(): ") +
e.getMessage()));
97 if (!this->fetchID()) {
98 throw(std::runtime_error(
"FEConfigSpikeInfo::writeDB: Failed to write"));
103 this->checkConnection();
105 if (
result->getId() == 0 && (
result->getConfigTag().empty())) {
106 throw(std::runtime_error(
"FEConfigSpikeInfo::fetchData(): no Id defined for this FEConfigSpikeInfo "));
112 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
" where ( spi_conf_id= :1 or (tag=:2 AND version=:3 ) )");
113 m_readStmt->setInt(1,
result->getId());
114 m_readStmt->setString(2,
result->getConfigTag());
115 m_readStmt->setInt(3,
result->getVersion());
116 ResultSet* rset = m_readStmt->executeQuery();
122 result->setId(rset->getInt(1));
123 result->setConfigTag(rset->getString(2));
124 result->setVersion(rset->getInt(3));
125 Date dbdate = rset->getDate(4);
126 result->setDBTime(
dh.dateToTm(dbdate));
129 throw(std::runtime_error(
std::string(
"FEConfigSpikeInfo::fetchData(): ") +
e.getMessage()));
134 this->checkConnection();
139 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
" where spi_conf_id = ( select max( spi_conf_id) from " +
141 ResultSet* rset = m_readStmt->executeQuery();
145 result->setId(rset->getInt(1));
146 result->setConfigTag(rset->getString(2));
147 result->setVersion(rset->getInt(3));
148 Date dbdate = rset->getDate(4);
149 result->setDBTime(
dh.dateToTm(dbdate));
152 throw(std::runtime_error(
std::string(
"FEConfigSpikeInfo::fetchData(): ") +
e.getMessage()));
162 this->checkConnection();
165 Statement* stmt = m_conn->createStatement();
166 stmt->setSQL(
"SELECT spi_conf_id FROM " + getTable() +
" WHERE tag=:1 and version=:2 ");
168 stmt->setString(1, getConfigTag());
169 stmt->setInt(2, getVersion());
171 ResultSet* rset = stmt->executeQuery();
174 m_ID = rset->getInt(1);
178 m_conn->terminateStatement(stmt);
180 throw(std::runtime_error(
std::string(
"FEConfigSpikeInfo::fetchID: ") +
e.getMessage()));
187 this->checkConnection();
192 Statement* stmt = m_conn->createStatement();
194 stmt->setSQL(
"SELECT * FROM " + getTable() +
" WHERE spi_conf_id = :1");
197 ResultSet* rset = stmt->executeQuery();
199 this->setId(rset->getInt(1));
200 this->setConfigTag(rset->getString(2));
201 this->setVersion(rset->getInt(3));
202 Date dbdate = rset->getDate(4);
203 this->setDBTime(
dh.dateToTm(dbdate));
205 throw(std::runtime_error(
"FEConfigSpikeInfo::setByID: Given spi_conf_id is not in the database"));
208 m_conn->terminateStatement(stmt);
210 throw(std::runtime_error(
std::string(
"FEConfigSpikeInfo::setByID: ") +
e.getMessage()));
int fetchNextId() noexcept(false)
void fetchData(FEConfigSpikeInfo *result) noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void prepareWrite() noexcept(false) override
~FEConfigSpikeInfo() override
oracle::occi::Statement Statement
static unsigned int getId()
oracle::occi::SQLException SQLException
void fetchLastData(FEConfigSpikeInfo *result) noexcept(false)
void setByID(int id) noexcept(false)
void writeDB() noexcept(false)
int fetchID() noexcept(false)