18 m_writeStmt =
nullptr;
32 this->checkConnection();
34 m_readStmt = m_conn->createStatement();
35 m_readStmt->setSQL(
"select ecal_dcc_config_sq.NextVal from dual");
36 ResultSet *rset = m_readStmt->executeQuery();
37 while (rset->next()) {
40 m_conn->terminateStatement(m_readStmt);
44 throw(std::runtime_error(
std::string(
"ODDCCConfig::fetchNextId(): ") +
e.getMessage()));
49 this->checkConnection();
51 int next_id = fetchNextId();
54 m_writeStmt = m_conn->createStatement();
56 "INSERT INTO ECAL_DCC_CONFIGURATION (dcc_configuration_id, dcc_tag, " 57 " DCC_CONFIGURATION_URL, TESTPATTERN_FILE_URL, " 58 " N_TESTPATTERNS_TO_LOAD , SM_HALF, weightsmode, " 59 " dcc_configuration) " 60 "VALUES (:1, :2, :3, :4, :5, :6 , :7 ,:8 )");
61 m_writeStmt->setInt(1, next_id);
62 m_writeStmt->setString(2, getConfigTag());
63 m_writeStmt->setString(3, getDCCConfigurationUrl());
64 m_writeStmt->setString(4, getTestPatternFileUrl());
65 m_writeStmt->setInt(5, getNTestPatternsToLoad());
66 m_writeStmt->setInt(6, getSMHalf());
67 m_writeStmt->setString(7, getDCCWeightsMode());
70 oracle::occi::Clob clob(m_conn);
72 m_writeStmt->setClob(8, clob);
73 m_writeStmt->executeUpdate();
76 m_conn->terminateStatement(m_writeStmt);
77 std::cout <<
"DCC Clob inserted into CONFIGURATION with id=" << next_id << std::endl;
80 m_writeStmt = m_conn->createStatement();
82 "SELECT dcc_configuration FROM ECAL_DCC_CONFIGURATION WHERE" 83 " dcc_configuration_id=:1 FOR UPDATE");
85 std::cout <<
"updating the clob 0" << std::endl;
88 throw(std::runtime_error(
std::string(
"ODDCCConfig::prepareWrite(): ") +
e.getMessage()));
91 std::cout <<
"updating the clob 1 " << std::endl;
98 for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
99 if (ci->first ==
"DCC_CONFIGURATION_ID")
100 setConfigTag(ci->second);
101 if (ci->first ==
"TESTPATTERN_FILE_URL")
102 setTestPatternFileUrl(ci->second);
103 if (ci->first ==
"N_TESTPATTERNS_TO_LOAD")
104 setNTestPatternsToLoad(atoi(ci->second.c_str()));
105 if (ci->first ==
"SM_HALF")
106 setSMHalf(atoi(ci->second.c_str()));
107 if (ci->first ==
"WEIGHTSMODE")
108 setDCCWeightsMode(ci->second);
109 if (ci->first ==
"DCC_CONFIGURATION_URL") {
111 setDCCConfigurationUrl(
fname);
117 inpFile.open(
fname.c_str());
122 bufsize = inpFile.tellg();
123 std::cout <<
" bufsize =" << bufsize << std::endl;
125 inpFile.seekg(0, ios::beg);
135 std::cout <<
"updating the clob " << std::endl;
138 m_writeStmt->setInt(1, m_ID);
139 ResultSet *rset = m_writeStmt->executeQuery();
142 oracle::occi::Clob clob = rset->getClob(1);
144 cout <<
"Opening the clob in read write mode" << endl;
146 std::cout <<
"Populating the clob" << endl;
148 populateClob(clob, getDCCConfigurationUrl(), m_size);
149 int clobLength = clob.length();
150 cout <<
"Length of the clob is: " << clobLength << endl;
152 m_writeStmt->executeUpdate();
154 m_writeStmt->closeResultSet(rset);
157 throw(std::runtime_error(
std::string(
"ODDCCConfig::writeDB(): ") +
e.getMessage()));
160 if (!this->fetchID()) {
161 throw(std::runtime_error(
"ODDCCConfig::writeDB: Failed to write"));
174 this->checkConnection();
176 if (
result->getId() == 0 && (
result->getConfigTag().empty())) {
184 "FROM ECAL_DCC_CONFIGURATION " 185 " where dcc_configuration_id = :1 or dcc_tag=:2 ");
186 m_readStmt->setInt(1,
result->getId());
187 m_readStmt->setString(2,
result->getConfigTag());
188 ResultSet *rset = m_readStmt->executeQuery();
194 result->setId(rset->getInt(1));
195 result->setConfigTag(rset->getString(2));
196 result->setDCCConfigurationUrl(rset->getString(3));
197 result->setTestPatternFileUrl(rset->getString(4));
198 result->setNTestPatternsToLoad(rset->getInt(5));
199 result->setSMHalf(rset->getInt(6));
201 Clob clob = rset->getClob(7);
202 m_size = clob.length();
203 Stream *instream = clob.getStream(1, 0);
204 unsigned char *
buffer =
new unsigned char[m_size];
205 memset(
buffer, 0, m_size);
206 instream->readBuffer((
char *)
buffer, m_size);
223 result->setDCCWeightsMode(rset->getString(8));
226 throw(std::runtime_error(
std::string(
"ODDCCConfig::fetchData(): ") +
e.getMessage()));
235 this->checkConnection();
238 Statement *stmt = m_conn->createStatement();
240 "SELECT DCC_configuration_id FROM ecal_dcc_configuration " 241 "WHERE dcc_tag=:dcc_tag ");
243 stmt->setString(1, getConfigTag());
245 ResultSet *rset = stmt->executeQuery();
248 m_ID = rset->getInt(1);
252 m_conn->terminateStatement(stmt);
254 throw(std::runtime_error(
std::string(
"ODDCCConfig::fetchID: ") +
e.getMessage()));
oracle::occi::Stream Stream
void fetchData(ODDCCConfig *result) noexcept(false)
void prepareWrite() noexcept(false) override
int fetchNextId() noexcept(false)
oracle::occi::Statement Statement
oracle::occi::SQLException SQLException
void clear(HadCaloObj &c)
int fetchID() noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void writeDB() noexcept(false)