19 m_writeStmt =
nullptr;
22 m_configuration_script=
"";
23 m_configuration_script_params=
"";
30 std::cout <<
"entering clear" << std::endl;
32 m_configuration_script=
"";
33 m_configuration_script_params=
"";
47 this->checkConnection();
49 m_readStmt = m_conn->createStatement();
50 m_readStmt->setSQL(
"select ecal_ttcci_config_sq.NextVal from dual");
51 ResultSet* rset = m_readStmt->executeQuery();
52 while (rset->next ()){
53 result= rset->getInt(1);
55 m_conn->terminateStatement(m_readStmt);
59 throw(std::runtime_error(
std::string(
"ODTTCciConfig::fetchNextId(): ")+e.getMessage()));
70 this->checkConnection();
72 int next_id=fetchNextId();
75 m_writeStmt = m_conn->createStatement();
76 m_writeStmt->setSQL(
"INSERT INTO ECAL_TTCci_CONFIGURATION (ttcci_configuration_id, ttcci_tag, " 77 " TTCCI_configuration_file, TRG_MODE, TRG_SLEEP, Configuration, configuration_script, configuration_script_params ) " 78 "VALUES (:1, :2, :3, :4, :5, :6, :7, :8 )");
79 m_writeStmt->setInt(1, next_id);
80 m_writeStmt->setString(2, getConfigTag());
81 m_writeStmt->setString(3, getTTCciConfigurationFile());
82 m_writeStmt->setString(4, getTrgMode());
83 m_writeStmt->setInt(5, getTrgSleep());
84 m_writeStmt->setString(7, getConfigurationScript());
85 m_writeStmt->setString(8, getConfigurationScriptParams());
88 oracle::occi::Clob clob(m_conn);
90 m_writeStmt->setClob(6,clob);
91 m_writeStmt->executeUpdate ();
94 m_conn->terminateStatement(m_writeStmt);
95 std::cout<<
"TTCci Clob inserted into CONFIGURATION with id="<<next_id<<std::endl;
98 m_writeStmt = m_conn->createStatement();
99 m_writeStmt->setSQL (
"SELECT Configuration FROM ECAL_TTCci_CONFIGURATION WHERE" 100 " ttcci_configuration_id=:1 FOR UPDATE");
102 std::cout<<
"updating the clob 0"<<std::endl;
106 throw(std::runtime_error(
std::string(
"ODTTCciConfig::prepareWrite(): ")+e.getMessage()));
109 std::cout<<
"updating the clob 1 "<<std::endl;
118 for( std::map<std::string, std::string >::const_iterator ci=
119 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
121 if(ci->first==
"TRG_MODE") setTrgMode(ci->second);
122 if(ci->first==
"TRG_SLEEP") setTrgSleep(atoi(ci->second.c_str()));
123 if(ci->first==
"TTCci_CONFIGURATION_ID") setConfigTag(ci->second);
124 if(ci->first==
"CONFIGURATION_SCRIPT" ) setConfigurationScript(ci->second);
125 if(ci->first==
"CONFIGURATION_SCRIPT_PARAMS" ) setConfigurationScriptParams(ci->second);
126 if(ci->first==
"CONFIGURATION_SCRIPT_PARAMETERS" ) setConfigurationScriptParams(ci->second);
127 if(ci->first==
"Configuration") {
132 pos = fname.find(
"=");
134 str3 = fname.substr (pos+1, pose-pos-2);
136 cout <<
"fname="<<fname<<
" and reduced is: "<<str3 << endl;
137 setTTCciConfigurationFile(str3 );
141 std::cout <<
"Going to read file: " << str3 << endl;
144 inpFile.open(str3.c_str());
149 bufsize = inpFile.tellg();
150 std::cout <<
" bufsize ="<<bufsize<< std::endl;
152 inpFile.seekg( 0,ios::beg );
168 std::cout<<
"updating the clob 2"<<std::endl;
174 m_writeStmt->setInt(1, m_ID);
175 ResultSet* rset = m_writeStmt->executeQuery();
177 while (rset->next ())
179 oracle::occi::Clob clob = rset->getClob (1);
180 cout <<
"Opening the clob in read write mode" << endl;
181 cout <<
"Populating the clob" << endl;
182 populateClob (clob, getTTCciConfigurationFile(), m_size);
183 int clobLength=clob.length ();
184 cout <<
"Length of the clob is: " << clobLength << endl;
188 m_writeStmt->executeUpdate();
190 m_writeStmt->closeResultSet (rset);
193 throw(std::runtime_error(
std::string(
"ODTTCciConfig::writeDB(): ")+e.getMessage()));
196 if (!this->fetchID()) {
197 throw(std::runtime_error(
"ODTTCciConfig::writeDB: Failed to write"));
210 this->checkConnection();
212 if(
result->getId()==0 && (
result->getConfigTag().empty()) ){
213 throw(std::runtime_error(
"ODTTCciConfig::fetchData(): no Id defined for this ODTTCciConfig "));
218 m_readStmt->setSQL(
"SELECT * " 219 "FROM ECAL_TTCci_CONFIGURATION " 220 " where ( ttcci_configuration_id = :1 or ttcci_tag=:2 )" );
221 m_readStmt->setInt(1,
result->getId());
222 m_readStmt->setString(2,
result->getConfigTag());
223 ResultSet* rset = m_readStmt->executeQuery();
228 result->setId(rset->getInt(1));
229 result->setConfigTag(rset->getString(2));
232 result->setTTCciConfigurationFile(rset->getString(3));
233 result->setTrgMode(rset->getString(4));
234 result->setTrgSleep(rset->getInt(5));
236 result->setConfigurationScript(rset->getString(7));
237 result->setConfigurationScriptParams(rset->getString(8));
239 Clob clob = rset->getClob (6);
240 cout <<
"Opening the clob in Read only mode" << endl;
241 clob.open (OCCI_LOB_READONLY);
242 int clobLength=clob.length ();
243 cout <<
"Length of the clob is: " << clobLength << endl;
245 unsigned char*
buffer = readClob (clob, m_size);
247 cout<<
"the clob buffer is:"<<endl;
248 for (
int i = 0;
i < clobLength; ++
i)
249 cout << (
char) buffer[
i];
253 result->setTTCciClob(buffer );
256 throw(std::runtime_error(
std::string(
"ODTTCciConfig::fetchData(): ")+e.getMessage()));
268 this->checkConnection();
271 Statement* stmt = m_conn->createStatement();
272 stmt->setSQL(
"SELECT ttcci_configuration_id FROM ecal_ttcci_configuration " 273 "WHERE ttcci_tag=:ttcci_tag " 276 stmt->setString(1, getConfigTag() );
278 ResultSet* rset = stmt->executeQuery();
281 m_ID = rset->getInt(1);
285 m_conn->terminateStatement(stmt);
287 throw(std::runtime_error(
std::string(
"ODTTCciConfig::fetchID: ")+e.getMessage()));
~ODTTCciConfig() override
void fetchData(ODTTCciConfig *result) noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void writeDB() noexcept(false)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
int fetchID() noexcept(false)
void prepareWrite() noexcept(false) override
oracle::occi::Statement Statement
int fetchNextId() noexcept(false)
oracle::occi::SQLException SQLException