15 m_writeStmt =
nullptr;
40 this->checkConnection();
42 m_readStmt = m_conn->createStatement();
43 m_readStmt->setSQL(
"select COND2CONF_INFO_SQ.NextVal from DUAL ");
44 ResultSet* rset = m_readStmt->executeQuery();
45 while (rset->next ()){
46 result= rset->getInt(1);
49 m_conn->terminateStatement(m_readStmt);
53 throw(std::runtime_error(
std::string(
"ODGolBiasCurrentInfo::fetchNextId(): ")+e.getMessage()));
61 this->checkConnection();
65 next_id=fetchNextId();
69 m_writeStmt = m_conn->createStatement();
70 m_writeStmt->setSQL(
"INSERT INTO "+getTable()+
" ( rec_id, tag, version) " 71 " VALUES ( :1, :2, :3 ) " );
73 m_writeStmt->setInt(1, next_id);
77 throw(std::runtime_error(
std::string(
"ODGolBiasCurrentInfo::prepareWrite(): ")+e.getMessage()));
87 for( std::map<std::string, std::string >::const_iterator ci=
88 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
90 if(ci->first==
"VERSION") setVersion(atoi(ci->second.c_str()) );
91 if(ci->first==
"TAG") setConfigTag(ci->second);
100 this->checkConnection();
101 this->checkPrepare();
106 m_writeStmt->setString(2, this->getConfigTag());
107 m_writeStmt->setInt(3, this->getVersion());
109 m_writeStmt->executeUpdate();
113 throw(std::runtime_error(
std::string(
"ODGolBiasCurrentInfo::writeDB(): ")+e.getMessage()));
116 if (!this->fetchID()) {
117 throw(std::runtime_error(
"ODGolBiasCurrentInfo::writeDB: Failed to write"));
119 int old_version=this->getVersion();
120 m_readStmt = m_conn->createStatement();
121 this->fetchData (
this);
122 m_conn->terminateStatement(m_readStmt);
123 if(this->getVersion()!=old_version)
std::cout <<
"ODGolBiasCurrentInfo>>WARNING version is "<< getVersion()<< endl;
133 this->checkConnection();
135 if(
result->getId()==0 && (
result->getConfigTag().empty()) ){
136 throw(std::runtime_error(
"ODGolBiasCurrentInfo::fetchData(): no Id defined for this ODGolBiasCurrentInfo "));
143 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
144 " where rec_id = :1 ");
145 m_readStmt->setInt(1,
result->getId());
146 }
else if (!
result->getConfigTag().empty()) {
148 if(
result->getVersion() !=0){
149 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
151 " and version = :version " );
152 m_readStmt->setString(1,
result->getConfigTag());
153 m_readStmt->setInt(2,
result->getVersion());
156 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
157 " WHERE tag = :1 and version= (select max(version) from "+getTable() +
" where tag=:2) " );
158 m_readStmt->setString(1,
result->getConfigTag());
159 m_readStmt->setString(2,
result->getConfigTag());
164 throw(std::runtime_error(
"ODGolBiasCurrentInfo::fetchData(): no Id defined for this record "));
168 ResultSet* rset = m_readStmt->executeQuery();
174 result->setId(rset->getInt(1));
175 result->setConfigTag(rset->getString(2));
176 result->setVersion(rset->getInt(3));
179 throw(std::runtime_error(
std::string(
"ODGolBiasCurrentInfo::fetchData(): ")+e.getMessage()));
190 this->checkConnection();
193 Statement* stmt = m_conn->createStatement();
194 stmt->setSQL(
"SELECT rec_id FROM "+ getTable()+
195 " WHERE tag=:1 and version=:2 " );
197 stmt->setString(1, getConfigTag() );
198 stmt->setInt(2, getVersion() );
200 ResultSet* rset = stmt->executeQuery();
203 m_ID = rset->getInt(1);
207 m_conn->terminateStatement(stmt);
209 throw(std::runtime_error(
std::string(
"ODGolBiasCurrentInfo::fetchID: ")+e.getMessage()));
static unsigned int getId()
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void fetchData(ODGolBiasCurrentInfo *result) noexcept(false)
int fetchNextId() noexcept(false)
void writeDB() noexcept(false)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
void prepareWrite() noexcept(false) override
oracle::occi::Statement Statement
int fetchID() noexcept(false)
~ODGolBiasCurrentInfo() override
oracle::occi::SQLException SQLException