9 using namespace oracle::occi;
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(
"ODBadTTInfo::fetchNextId(): "+e.getMessage()));
59 throw(std::runtime_error)
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(
"ODBadTTInfo::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);
98 throw(std::runtime_error)
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(
"ODBadTTInfo::writeDB(): "+e.getMessage()));
116 if (!this->fetchID()) {
117 throw(std::runtime_error(
"ODBadTTInfo::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 <<
"ODBadTTInfo>>WARNING version is "<< getVersion()<< endl;
131 throw(std::runtime_error)
133 this->checkConnection();
135 if(
result->getId()==0 && (
result->getConfigTag()==
"") ){
136 throw(std::runtime_error(
"ODBadTTInfo::fetchData(): no Id defined for this ODBadTTInfo "));
143 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
144 " where rec_id = :1 ");
145 m_readStmt->setInt(1,
result->getId());
146 }
else if (
result->getConfigTag()!=
"") {
147 m_readStmt->setSQL(
"SELECT * FROM " + getTable() +
148 " where tag=:1 AND version=:2 " );
149 m_readStmt->setString(1,
result->getConfigTag());
150 m_readStmt->setInt(2,
result->getVersion());
153 throw(std::runtime_error(
"ODBadTTInfo::fetchData(): no Id defined for this record "));
157 ResultSet* rset = m_readStmt->executeQuery();
163 result->setId(rset->getInt(1));
164 result->setConfigTag(rset->getString(2));
165 result->setVersion(rset->getInt(3));
168 throw(std::runtime_error(
"ODBadTTInfo::fetchData(): "+e.getMessage()));
179 this->checkConnection();
182 Statement* stmt = m_conn->createStatement();
183 stmt->setSQL(
"SELECT rec_id FROM "+ getTable()+
184 "WHERE tag=:1 and version=:2 " );
186 stmt->setString(1, getConfigTag() );
187 stmt->setInt(2, getVersion() );
192 m_ID = rset->getInt(1);
196 m_conn->terminateStatement(stmt);
198 throw(std::runtime_error(
"ODBadTTInfo::fetchID: "+e.getMessage()));
static unsigned int getId(void)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void fetchData(ODBadTTInfo *result)
oracle::occi::Statement Statement
oracle::occi::ResultSet ResultSet
oracle::occi::SQLException SQLException