9 using namespace oracle::occi;
42 this->checkConnection();
44 m_readStmt = m_conn->createStatement();
45 m_readStmt->setSQL(
"select ecal_tcc_config_sq.NextVal from dual");
46 ResultSet* rset = m_readStmt->executeQuery();
47 while (rset->next ()){
48 result= rset->getInt(1);
50 m_conn->terminateStatement(m_readStmt);
54 throw(std::runtime_error(
"ODTCCConfig::fetchNextId(): "+e.getMessage()));
65 for( std::map<std::string, std::string >::iterator ci=
66 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
68 if(ci->first==
"TCC_CONFIGURATION_ID") setConfigTag(ci->second);
69 if(ci->first==
"N_TESTPATTERNS_TO_LOAD") setNTestPatternsToLoad(atoi(ci->second.c_str()));
70 if(ci->first==
"LUT_CONFIGURATION_FILE") setLUTConfigurationFile(ci->second );
71 if(ci->first==
"CONFIGURATION_FILE") setTCCConfigurationFile(ci->second );
72 if(ci->first==
"SLB_CONFIGURATION_FILE") setSLBConfigurationFile(ci->second );
73 if(ci->first==
"TESTPATTERNFILE_URL") setTestPatternFileUrl(ci->second );
82 throw(std::runtime_error)
84 this->checkConnection();
86 int next_id=fetchNextId();
89 m_writeStmt = m_conn->createStatement();
90 m_writeStmt->setSQL(
"INSERT INTO ECAL_TCC_CONFIGURATION (tcc_configuration_id, tcc_tag, "
91 "Configuration_file, LUT_CONFIGURATION_FILE, SLB_CONFIGURATION_FILE, "
92 "TESTPATTERNFILE_URL , N_TESTPATTERNS_TO_LOAD, "
93 "tcc_configuration, lut_configuration, slb_configuration ) "
94 "VALUES (:1, :2, :3, :4, :5, :6, :7, :8 , :9, :10)");
95 m_writeStmt->setInt(1, next_id);
96 m_writeStmt->setString(2, getConfigTag());
97 m_writeStmt->setString(3, getTCCConfigurationFile());
98 m_writeStmt->setString(4, getLUTConfigurationFile());
99 m_writeStmt->setString(5, getSLBConfigurationFile());
100 m_writeStmt->setString(6, getTestPatternFileUrl());
101 m_writeStmt->setInt(7, getNTestPatternsToLoad());
103 oracle::occi::Clob clob1(m_conn);
105 m_writeStmt->setClob(8,clob1);
107 oracle::occi::Clob clob2(m_conn);
109 m_writeStmt->setClob(9,clob2);
111 oracle::occi::Clob clob3(m_conn);
113 m_writeStmt->setClob(10,clob3);
115 m_writeStmt->executeUpdate ();
118 m_conn->terminateStatement(m_writeStmt);
119 std::cout<<
"TCC 3 empty Clobs inserted into CONFIGURATION with id="<<next_id<<std::endl;
122 m_writeStmt = m_conn->createStatement();
123 m_writeStmt->setSQL (
"SELECT tcc_configuration, lut_configuration, slb_configuration FROM ECAL_TCC_CONFIGURATION WHERE"
124 " tcc_configuration_id=:1 FOR UPDATE");
126 std::cout<<
"updating the clobs 0"<<std::endl;
130 throw(std::runtime_error(
"ODTCCConfig::prepareWrite(): "+e.getMessage()));
133 std::cout<<
"updating the clob 1 "<<std::endl;
138 throw(std::runtime_error)
141 std::cout<<
"updating the clob 2"<<std::endl;
145 m_writeStmt->setInt(1, m_ID);
146 ResultSet* rset = m_writeStmt->executeQuery();
148 while (rset->next ())
150 oracle::occi::Clob clob1 = rset->getClob (1);
151 oracle::occi::Clob clob2 = rset->getClob (2);
152 oracle::occi::Clob clob3 = rset->getClob (3);
153 cout <<
"Opening the clob in read write mode" << endl;
154 cout <<
"Populating the clobs" << endl;
155 populateClob (clob1, getTCCConfigurationFile(), m_size);
156 populateClob (clob2, getLUTConfigurationFile(), m_size);
157 populateClob (clob3, getSLBConfigurationFile(), m_size);
161 m_writeStmt->executeUpdate();
162 m_writeStmt->closeResultSet (rset);
165 throw(std::runtime_error(
"ODTCCConfig::writeDB(): "+e.getMessage()));
168 if (!this->fetchID()) {
169 throw(std::runtime_error(
"ODTCCConfig::writeDB: Failed to write"));
181 throw(std::runtime_error)
183 this->checkConnection();
185 if(
result->getId()==0 && (
result->getConfigTag()==
"") ){
186 throw(std::runtime_error(
"ODTCCConfig::fetchData(): no Id defined for this ODTCCConfig "));
191 m_readStmt->setSQL(
"SELECT * "
192 "FROM ECAL_TCC_CONFIGURATION d "
193 " where (tcc_configuration_id = :1 or tcc_tag=:2 )" );
194 m_readStmt->setInt(1,
result->getId());
195 m_readStmt->setString(2,
result->getConfigTag());
196 ResultSet* rset = m_readStmt->executeQuery();
200 result->setId(rset->getInt(1));
201 result->setConfigTag(rset->getString(2));
203 result->setTCCConfigurationFile(rset->getString(3));
204 result->setLUTConfigurationFile(rset->getString(4));
205 result->setSLBConfigurationFile(rset->getString(5));
206 result->setTestPatternFileUrl(rset->getString(6));
207 result->setNTestPatternsToLoad(rset->getInt(7));
210 Clob clob1 = rset->getClob (8);
211 cout <<
"Opening the clob in Read only mode" << endl;
212 clob1.open (OCCI_LOB_READONLY);
213 int clobLength=clob1.length ();
214 cout <<
"Length of the clob1 is: " << clobLength << endl;
215 unsigned char* buffer = readClob (clob1, clobLength);
217 cout<<
"the clob buffer is:"<<endl;
218 for (
int i = 0;
i < clobLength; ++
i)
219 cout << (
char) buffer[
i];
221 result->setTCCClob(buffer );
223 Clob clob2 = rset->getClob (9);
224 cout <<
"Opening the clob in Read only mode" << endl;
225 clob2.open (OCCI_LOB_READONLY);
226 clobLength=clob2.length ();
227 cout <<
"Length of the clob2 is: " << clobLength << endl;
228 unsigned char* buffer2 = readClob (clob2, clobLength);
230 cout<<
"the clob buffer is:"<<endl;
231 for (
int i = 0;
i < clobLength; ++
i)
232 cout << (
char) buffer2[
i];
234 result->setLUTClob(buffer2 );
236 Clob clob3 = rset->getClob (10);
237 cout <<
"Opening the clob in Read only mode" << endl;
238 clob3.open (OCCI_LOB_READONLY);
239 clobLength=clob3.length ();
240 cout <<
"Length of the clob3 is: " << clobLength << endl;
241 unsigned char* buffer3 = readClob (clob3, clobLength);
243 cout<<
"the clob buffer is:"<<endl;
244 for (
int i = 0;
i < clobLength; ++
i)
245 cout << (
char) buffer3[
i];
247 result->setSLBClob(buffer3 );
250 throw(std::runtime_error(
"ODTCCConfig::fetchData(): "+e.getMessage()));
262 this->checkConnection();
265 Statement* stmt = m_conn->createStatement();
266 stmt->setSQL(
"SELECT tcc_configuration_id FROM ecal_tcc_configuration "
267 "WHERE tcc_tag=:tcc_tag "
270 stmt->setString(1, getConfigTag() );
275 m_ID = rset->getInt(1);
279 m_conn->terminateStatement(stmt);
281 throw(std::runtime_error(
"ODTCCConfig::fetchID: "+e.getMessage()));
void fetchData(ODTCCConfig *result)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
oracle::occi::Statement Statement
oracle::occi::ResultSet ResultSet
void setParameters(std::map< std::string, std::string > my_keys_map)
oracle::occi::SQLException SQLException