9 using namespace oracle::occi;
14 m_writeStmt =
nullptr;
36 this->checkConnection();
38 m_readStmt = m_conn->createStatement();
39 m_readStmt->setSQL(
"select ecal_tcc_config_sq.NextVal from dual");
40 ResultSet* rset = m_readStmt->executeQuery();
41 while (rset->next()) {
42 result = rset->getInt(1);
44 m_conn->terminateStatement(m_readStmt);
48 throw(std::runtime_error(
std::string(
"ODTCCConfig::fetchNextId(): ") + e.getMessage()));
56 for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
57 if (ci->first ==
"TCC_CONFIGURATION_ID")
58 setConfigTag(ci->second);
59 if (ci->first ==
"N_TESTPATTERNS_TO_LOAD")
60 setNTestPatternsToLoad(atoi(ci->second.c_str()));
61 if (ci->first ==
"LUT_CONFIGURATION_FILE")
62 setLUTConfigurationFile(ci->second);
63 if (ci->first ==
"CONFIGURATION_FILE")
64 setTCCConfigurationFile(ci->second);
65 if (ci->first ==
"SLB_CONFIGURATION_FILE")
66 setSLBConfigurationFile(ci->second);
67 if (ci->first ==
"TESTPATTERNFILE_URL")
68 setTestPatternFileUrl(ci->second);
73 this->checkConnection();
75 int next_id = fetchNextId();
78 m_writeStmt = m_conn->createStatement();
80 "INSERT INTO ECAL_TCC_CONFIGURATION (tcc_configuration_id, tcc_tag, "
81 "Configuration_file, LUT_CONFIGURATION_FILE, SLB_CONFIGURATION_FILE, "
82 "TESTPATTERNFILE_URL , N_TESTPATTERNS_TO_LOAD, "
83 "tcc_configuration, lut_configuration, slb_configuration ) "
84 "VALUES (:1, :2, :3, :4, :5, :6, :7, :8 , :9, :10)");
85 m_writeStmt->setInt(1, next_id);
86 m_writeStmt->setString(2, getConfigTag());
87 m_writeStmt->setString(3, getTCCConfigurationFile());
88 m_writeStmt->setString(4, getLUTConfigurationFile());
89 m_writeStmt->setString(5, getSLBConfigurationFile());
90 m_writeStmt->setString(6, getTestPatternFileUrl());
91 m_writeStmt->setInt(7, getNTestPatternsToLoad());
93 oracle::occi::Clob clob1(m_conn);
95 m_writeStmt->setClob(8, clob1);
97 oracle::occi::Clob clob2(m_conn);
99 m_writeStmt->setClob(9, clob2);
101 oracle::occi::Clob clob3(m_conn);
103 m_writeStmt->setClob(10, clob3);
105 m_writeStmt->executeUpdate();
108 m_conn->terminateStatement(m_writeStmt);
109 std::cout <<
"TCC 3 empty Clobs inserted into CONFIGURATION with id=" << next_id << std::endl;
112 m_writeStmt = m_conn->createStatement();
114 "SELECT tcc_configuration, lut_configuration, slb_configuration FROM ECAL_TCC_CONFIGURATION WHERE"
115 " tcc_configuration_id=:1 FOR UPDATE");
117 std::cout <<
"updating the clobs 0" << std::endl;
120 throw(std::runtime_error(
std::string(
"ODTCCConfig::prepareWrite(): ") + e.getMessage()));
123 std::cout <<
"updating the clob 1 " << std::endl;
127 std::cout <<
"updating the clob 2" << std::endl;
130 m_writeStmt->setInt(1, m_ID);
131 ResultSet* rset = m_writeStmt->executeQuery();
133 while (rset->next()) {
134 oracle::occi::Clob clob1 = rset->getClob(1);
135 oracle::occi::Clob clob2 = rset->getClob(2);
136 oracle::occi::Clob clob3 = rset->getClob(3);
137 cout <<
"Opening the clob in read write mode" << endl;
138 cout <<
"Populating the clobs" << endl;
139 populateClob(clob1, getTCCConfigurationFile(), m_size);
140 populateClob(clob2, getLUTConfigurationFile(), m_size);
141 populateClob(clob3, getSLBConfigurationFile(), m_size);
144 m_writeStmt->executeUpdate();
145 m_writeStmt->closeResultSet(rset);
148 throw(std::runtime_error(
std::string(
"ODTCCConfig::writeDB(): ") + e.getMessage()));
151 if (!this->fetchID()) {
152 throw(std::runtime_error(
"ODTCCConfig::writeDB: Failed to write"));
157 this->checkConnection();
159 if (
result->getId() == 0 && (
result->getConfigTag().empty())) {
160 throw(std::runtime_error(
"ODTCCConfig::fetchData(): no Id defined for this ODTCCConfig "));
166 "FROM ECAL_TCC_CONFIGURATION d "
167 " where (tcc_configuration_id = :1 or tcc_tag=:2 )");
168 m_readStmt->setInt(1,
result->getId());
169 m_readStmt->setString(2,
result->getConfigTag());
170 ResultSet* rset = m_readStmt->executeQuery();
174 result->setId(rset->getInt(1));
175 result->setConfigTag(rset->getString(2));
177 result->setTCCConfigurationFile(rset->getString(3));
178 result->setLUTConfigurationFile(rset->getString(4));
179 result->setSLBConfigurationFile(rset->getString(5));
180 result->setTestPatternFileUrl(rset->getString(6));
181 result->setNTestPatternsToLoad(rset->getInt(7));
184 Clob clob1 = rset->getClob(8);
185 cout <<
"Opening the clob in Read only mode" << endl;
186 clob1.open(OCCI_LOB_READONLY);
187 int clobLength = clob1.length();
188 cout <<
"Length of the clob1 is: " << clobLength << endl;
189 unsigned char*
buffer = readClob(clob1, clobLength);
191 cout <<
"the clob buffer is:" << endl;
192 for (
int i = 0;
i < clobLength; ++
i)
193 cout << (
char)buffer[
i];
195 result->setTCCClob(buffer);
197 Clob clob2 = rset->getClob(9);
198 cout <<
"Opening the clob in Read only mode" << endl;
199 clob2.open(OCCI_LOB_READONLY);
200 clobLength = clob2.length();
201 cout <<
"Length of the clob2 is: " << clobLength << endl;
202 unsigned char* buffer2 = readClob(clob2, clobLength);
204 cout <<
"the clob buffer is:" << endl;
205 for (
int i = 0;
i < clobLength; ++
i)
206 cout << (
char)buffer2[
i];
208 result->setLUTClob(buffer2);
210 Clob clob3 = rset->getClob(10);
211 cout <<
"Opening the clob in Read only mode" << endl;
212 clob3.open(OCCI_LOB_READONLY);
213 clobLength = clob3.length();
214 cout <<
"Length of the clob3 is: " << clobLength << endl;
215 unsigned char* buffer3 = readClob(clob3, clobLength);
217 cout <<
"the clob buffer is:" << endl;
218 for (
int i = 0;
i < clobLength; ++
i)
219 cout << (
char)buffer3[
i];
221 result->setSLBClob(buffer3);
224 throw(std::runtime_error(
std::string(
"ODTCCConfig::fetchData(): ") + e.getMessage()));
233 this->checkConnection();
236 Statement* stmt = m_conn->createStatement();
238 "SELECT tcc_configuration_id FROM ecal_tcc_configuration "
239 "WHERE tcc_tag=:tcc_tag ");
241 stmt->setString(1, getConfigTag());
243 ResultSet* rset = stmt->executeQuery();
246 m_ID = rset->getInt(1);
250 m_conn->terminateStatement(stmt);
252 throw(std::runtime_error(
std::string(
"ODTCCConfig::fetchID: ") + e.getMessage()));
void writeDB() noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
int fetchNextId() noexcept(false)
void fetchData(ODTCCConfig *result) noexcept(false)
oracle::occi::Statement Statement
void prepareWrite() noexcept(false) override
oracle::occi::SQLException SQLException
int fetchID() noexcept(false)