10 using namespace oracle::occi;
38 this->checkConnection();
39 std::cout<<
"going to fetch new id for TTCF 1"<<endl;
40 m_readStmt = m_conn->createStatement();
41 m_readStmt->setSQL(
"select ecal_ttcf_config_sq.NextVal from dual");
42 ResultSet* rset = m_readStmt->executeQuery();
43 while (rset->next ()){
44 result= rset->getInt(1);
48 m_conn->terminateStatement(m_readStmt);
52 throw(std::runtime_error(
"ODTTCFConfig::fetchNextId(): "+e.getMessage()));
61 throw(std::runtime_error)
63 this->checkConnection();
64 int next_id=fetchNextId();
67 m_writeStmt = m_conn->createStatement();
68 m_writeStmt->setSQL(
"INSERT INTO ECAL_TTCF_CONFIGURATION (ttcf_configuration_id, ttcf_tag, "
69 " rxbc0_delay, reg_30 , ttcf_configuration_file , ttcf_configuration ) "
70 "VALUES (:1, :2, :3 , :4, :5, :6)");
71 m_writeStmt->setInt(1, next_id);
72 m_writeStmt->setString(2, getConfigTag());
74 m_writeStmt->setInt( 3, getRxBC0Delay() );
75 m_writeStmt->setInt( 4, getReg30() );
77 m_writeStmt->setString(5, getTTCFConfigurationFile());
79 oracle::occi::Clob clob(m_conn);
81 m_writeStmt->setClob(6,clob);
82 m_writeStmt->executeUpdate ();
85 m_conn->terminateStatement(m_writeStmt);
86 std::cout<<
"inserted into CONFIGURATION with id="<<next_id<<std::endl;
89 m_writeStmt = m_conn->createStatement();
90 m_writeStmt->setSQL (
"SELECT ttcf_configuration FROM ECAL_TTCF_CONFIGURATION WHERE"
91 " ttcf_configuration_id=:1 FOR UPDATE");
93 std::cout<<
"updating the clob 0"<<std::endl;
97 throw(std::runtime_error(
"ODTTCFConfig::prepareWrite(): "+e.getMessage()));
100 std::cout<<
"updating the clob 1 "<<std::endl;
105 throw(std::runtime_error)
108 std::cout<<
"updating the clob 2"<<std::endl;
111 m_writeStmt->setInt(1, m_ID);
112 ResultSet* rset = m_writeStmt->executeQuery();
116 oracle::occi::Clob clob = rset->getClob (1);
117 cout <<
"Opening the clob in read write mode" << endl;
118 populateClob (clob, getTTCFConfigurationFile(), m_size);
119 int clobLength=clob.length ();
120 cout <<
"Length of the clob is: " << clobLength << endl;
122 m_writeStmt->executeUpdate();
123 m_writeStmt->closeResultSet (rset);
126 throw(std::runtime_error(
"ODTTCFConfig::writeDB(): "+e.getMessage()));
129 if (!this->fetchID()) {
130 throw(std::runtime_error(
"ODTTCFConfig::writeDB: Failed to write"));
140 throw(std::runtime_error)
142 this->checkConnection();
145 if(
result->getId()==0 && (
result->getConfigTag()==
"") ){
146 throw(std::runtime_error(
"ODTTCFConfig::fetchData(): no Id defined for this ODTTCFConfig "));
151 m_readStmt->setSQL(
"SELECT * "
152 "FROM ECAL_TTCF_CONFIGURATION "
153 " where (ttcf_configuration_id = :1 or ttcf_tag= :2) " );
154 m_readStmt->setInt(1,
result->getId());
155 m_readStmt->setString(2,
result->getConfigTag());
156 ResultSet* rset = m_readStmt->executeQuery();
160 result->setId(rset->getInt(1));
161 result->setConfigTag(rset->getString(2));
162 result->setTTCFConfigurationFile(rset->getString(3));
163 Clob clob = rset->getClob (4);
164 cout <<
"Opening the clob in Read only mode" << endl;
165 clob.open (OCCI_LOB_READONLY);
166 int clobLength=clob.length ();
167 cout <<
"Length of the clob is: " << clobLength << endl;
169 unsigned char* buffer = readClob (clob, m_size);
171 result->setTTCFClob((
unsigned char*) buffer );
174 throw(std::runtime_error(
"ODTTCFConfig::fetchData(): "+e.getMessage()));
186 this->checkConnection();
189 Statement* stmt = m_conn->createStatement();
190 stmt->setSQL(
"SELECT ttcf_configuration_id FROM ecal_ttcf_configuration "
191 "WHERE ttcf_tag=:ttcf_tag "
194 stmt->setString(1, getConfigTag() );
199 m_ID = rset->getInt(1);
203 m_conn->terminateStatement(stmt);
205 throw(std::runtime_error(
"ODTTCFConfig::fetchID: "+e.getMessage()));
216 for( std::map<std::string, std::string >::const_iterator ci=
217 my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
219 if(ci->first==
"TTCF_CONFIGURATION_ID") setConfigTag(ci->second);
220 if(ci->first==
"Configuration") {
225 pos = fname.find(
"=");
227 str3 = fname.substr (pos+1, pose-pos-2);
229 cout <<
"fname="<<fname<<
" and reduced is: "<<str3 << endl;
230 setTTCFConfigurationFile(str3 );
234 std::cout <<
"Going to read file: " << str3 << endl;
237 inpFile.open(str3.c_str());
242 bufsize = inpFile.tellg();
243 std::cout <<
" bufsize ="<<bufsize<< std::endl;
245 inpFile.seekg( 0,ios::beg );
250 }
else if ( ci->first ==
"RXBC0_DELAY" ) {
251 setRxBC0Delay( atoi( ci->second.c_str() ) );
252 }
else if ( ci->first ==
"REG_30" ) {
253 setReg30( atoi( ci->second.c_str() ) );
void fetchData(ODTTCFConfig *result)
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
oracle::occi::Statement Statement
void setParameters(const std::map< std::string, std::string > &my_keys_map)
oracle::occi::ResultSet ResultSet
oracle::occi::SQLException SQLException