17 m_writeStmt =
nullptr;
38 this->checkConnection();
40 m_readStmt = m_conn->createStatement();
41 m_readStmt->setSQL(
"select ecal_ltc_config_sq.NextVal from dual");
42 ResultSet* rset = m_readStmt->executeQuery();
43 while (rset->next ()){
44 result= rset->getInt(1);
46 m_conn->terminateStatement(m_readStmt);
50 throw(std::runtime_error(
std::string(
"ODLTCConfig::fetchNextId(): ")+getOraMessage(&e)));
61 this->checkConnection();
63 int next_id=fetchNextId();
66 m_writeStmt = m_conn->createStatement();
67 m_writeStmt->setSQL(
"INSERT INTO ECAL_LTC_CONFIGURATION (ltc_configuration_id, ltc_tag, " 68 " LTC_CONFIGURATION_file, " 70 "VALUES (:1, :2, :3, :4 )");
71 m_writeStmt->setInt(1, next_id);
72 m_writeStmt->setString(2, this->getConfigTag());
73 m_writeStmt->setString(3, getLTCConfigurationFile());
77 oracle::occi::Clob clob(m_conn);
79 m_writeStmt->setClob(4,clob);
80 m_writeStmt->executeUpdate ();
83 m_conn->terminateStatement(m_writeStmt);
84 std::cout<<
"LTC Clob inserted into CONFIGURATION with id="<<next_id<<std::endl;
87 m_writeStmt = m_conn->createStatement();
88 m_writeStmt->setSQL (
"SELECT Configuration FROM ECAL_LTC_CONFIGURATION WHERE" 89 " ltc_configuration_id=:1 FOR UPDATE");
91 std::cout<<
"updating the clob 0"<<std::endl;
95 throw(std::runtime_error(
std::string(
"ODLTCConfig::prepareWrite(): ")+getOraMessage(&e)));
98 std::cout<<
"updating the clob 1 "<<std::endl;
107 for( std::map<std::string, std::string >::const_iterator ci=
108 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
110 if(ci->first==
"LTC_CONFIGURATION_ID") setConfigTag(ci->second);
111 if(ci->first==
"Configuration") {
116 pos = fname.find(
"=");
118 str3 = fname.substr (pos+1, pose-pos-2);
120 cout <<
"fname="<<fname<<
" and reduced is: "<<str3 << endl;
121 setLTCConfigurationFile(str3 );
125 std::cout <<
"Going to read LTC file: " << fname << endl;
128 inpFile.open(str3.c_str());
133 bufsize = inpFile.tellg();
134 std::cout <<
" bufsize ="<<bufsize<< std::endl;
136 inpFile.seekg( 0,ios::beg );
152 std::cout<<
"updating the clob "<<std::endl;
159 m_writeStmt->setInt(1, m_ID);
160 ResultSet* rset = m_writeStmt->executeQuery();
163 oracle::occi::Clob clob = rset->getClob (1);
165 cout <<
"Opening the clob in read write mode" << endl;
167 std::cout <<
"Populating the clob" << endl;
169 populateClob (clob, getLTCConfigurationFile(), m_size);
170 int clobLength=clob.length ();
171 cout <<
"Length of the clob is: " << clobLength << endl;
174 m_writeStmt->executeUpdate();
176 m_writeStmt->closeResultSet (rset);
179 throw(std::runtime_error(
std::string(
"ODLTCConfig::writeDB(): ")+getOraMessage(&e)));
182 if (!this->fetchID()) {
183 throw(std::runtime_error(
"ODLTCConfig::writeDB: Failed to write"));
202 this->checkConnection();
204 if(
result->getId()==0 &&
result->getConfigTag().empty()){
205 throw(std::runtime_error(
"ODLTCConfig::fetchData(): no Id defined for this ODLTCConfig "));
210 m_readStmt->setSQL(
"SELECT * " 211 "FROM ECAL_LTC_CONFIGURATION " 212 " where (ltc_configuration_id = :1 or LTC_tag=:2 )" );
213 m_readStmt->setInt(1,
result->getId());
214 m_readStmt->setString(2,
result->getConfigTag());
215 ResultSet* rset = m_readStmt->executeQuery();
220 result->setId(rset->getInt(1));
221 result->setConfigTag(getOraString(rset,2));
222 result->setLTCConfigurationFile(getOraString(rset,3));
225 Clob clob = rset->getClob (4);
226 cout <<
"Opening the clob in Read only mode" << endl;
227 clob.open (OCCI_LOB_READONLY);
228 int clobLength=clob.length ();
229 cout <<
"Length of the clob is: " << clobLength << endl;
231 unsigned char*
buffer = readClob (clob, clobLength);
233 cout<<
"the clob buffer is:"<<endl;
234 for (
int i = 0;
i < clobLength; ++
i)
235 cout << (
char) buffer[
i];
239 result->setLTCClob(buffer );
242 throw(std::runtime_error(
std::string(
"ODLTCConfig::fetchData(): ")+getOraMessage(&e)));
254 this->checkConnection();
257 Statement* stmt = m_conn->createStatement();
258 stmt->setSQL(
"SELECT ltc_configuration_id FROM ecal_ltc_configuration " 259 "WHERE ltc_tag=:ltc_tag " 262 stmt->setString(1, getConfigTag() );
264 ResultSet* rset = stmt->executeQuery();
267 m_ID = rset->getInt(1);
271 m_conn->terminateStatement(stmt);
273 throw(std::runtime_error(
std::string(
"ODLTCConfig::fetchID: ")+getOraMessage(&e)));
void prepareWrite() noexcept(false) override
void writeDB() noexcept(false)
void fetchData(ODLTCConfig *result) noexcept(false)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
int fetchID() noexcept(false)
oracle::occi::Statement Statement
oracle::occi::SQLException SQLException
int fetchNextId() noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)