16 m_writeStmt =
nullptr;
40 this->checkConnection();
42 m_readStmt = m_conn->createStatement();
43 m_readStmt->setSQL(
"select ecal_srp_config_sq.NextVal from dual");
44 ResultSet *rset = m_readStmt->executeQuery();
45 while (rset->next()) {
48 m_conn->terminateStatement(m_readStmt);
52 throw(std::runtime_error(
std::string(
"ODSRPConfig::fetchNextId(): ") +
e.getMessage()));
60 for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
64 if (
name ==
"SRP_CONFIGURATION_ID")
65 setConfigTag(ci->second);
66 if (
name ==
"DEBUGMODE")
67 setDebugMode(atoi(ci->second.c_str()));
68 if (
name ==
"DUMMYMODE")
69 setDummyMode(atoi(ci->second.c_str()));
70 if (
name ==
"PATTERNDIRECTORY")
71 setPatternDirectory(ci->second);
72 if (
name ==
"PATTERN_DIRECTORY")
73 setPatternDirectory(ci->second);
74 if (
name ==
"AUTOMATICMASKS")
75 setAutomaticMasks(atoi(ci->second.c_str()));
76 if (
name ==
"AUTOMATIC_MASKS")
77 setAutomaticMasks(atoi(ci->second.c_str()));
78 if (
name ==
"AUTOMATICSRPSELECT")
79 setAutomaticSrpSelect(atoi(ci->second.c_str()));
80 if (
name ==
"SRP0BUNCHADJUSTPOSITION")
81 setSRP0BunchAdjustPosition(atoi(ci->second.c_str()));
82 if (
name ==
"SRP_CONFIG_FILE") {
92 inpFile.open(
fname.c_str());
97 bufsize = inpFile.tellg();
98 std::cout <<
" bufsize =" << bufsize << std::endl;
100 inpFile.seekg(0, ios::beg);
110 this->checkConnection();
112 int next_id = fetchNextId();
115 m_writeStmt = m_conn->createStatement();
117 "INSERT INTO ECAL_SRP_CONFIGURATION (srp_configuration_id, srp_tag, " 118 " DEBUGMODE, DUMMYMODE, PATTERN_DIRECTORY, AUTOMATIC_MASKS," 119 " SRP0BUNCHADJUSTPOSITION, SRP_CONFIG_FILE, SRP_CONFIGURATION, AUTOMATICSRPSELECT ) " 120 "VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10 )");
121 m_writeStmt->setInt(1, next_id);
122 m_writeStmt->setString(2, getConfigTag());
123 m_writeStmt->setInt(3, getDebugMode());
124 m_writeStmt->setInt(4, getDummyMode());
125 m_writeStmt->setString(5, getPatternDirectory());
126 m_writeStmt->setInt(6, getAutomaticMasks());
127 m_writeStmt->setInt(10, getAutomaticSrpSelect());
128 m_writeStmt->setInt(7, getSRP0BunchAdjustPosition());
129 m_writeStmt->setString(8, getConfigFile());
132 oracle::occi::Clob clob(m_conn);
134 m_writeStmt->setClob(9, clob);
135 m_writeStmt->executeUpdate();
138 m_conn->terminateStatement(m_writeStmt);
139 std::cout <<
"SRP Clob inserted into CONFIGURATION with id=" << next_id << std::endl;
142 m_writeStmt = m_conn->createStatement();
144 "SELECT srp_configuration FROM ECAL_SRP_CONFIGURATION WHERE" 145 " srp_configuration_id=:1 FOR UPDATE");
147 std::cout <<
"updating the clob 0" << std::endl;
150 throw(std::runtime_error(
std::string(
"ODSRPConfig::prepareWrite(): ") +
e.getMessage()));
153 std::cout <<
"updating the clob 1 " << std::endl;
157 std::cout <<
"updating the clob 2" << std::endl;
160 m_writeStmt->setInt(1, m_ID);
161 ResultSet *rset = m_writeStmt->executeQuery();
163 while (rset->next()) {
164 oracle::occi::Clob clob = rset->getClob(1);
165 cout <<
"Opening the clob in read write mode" << endl;
166 cout <<
"Populating the clob" << endl;
167 populateClob(clob, getConfigFile(), m_size);
168 int clobLength = clob.length();
169 cout <<
"Length of the clob after writing is: " << clobLength << endl;
172 m_writeStmt->executeUpdate();
174 m_writeStmt->closeResultSet(rset);
177 throw(std::runtime_error(
std::string(
"ODSRPConfig::writeDB(): ") +
e.getMessage()));
180 if (!this->fetchID()) {
181 throw(std::runtime_error(
"ODSRPConfig::writeDB: Failed to write"));
186 this->checkConnection();
188 if (
result->getId() == 0 && (
result->getConfigTag().empty())) {
196 " FROM ECAL_SRP_CONFIGURATION " 197 " where (srp_configuration_id = :1 or srp_tag=:2 )");
198 m_readStmt->setInt(1,
result->getId());
199 m_readStmt->setString(2,
result->getConfigTag());
200 ResultSet *rset = m_readStmt->executeQuery();
205 result->setId(rset->getInt(1));
206 result->setConfigTag(rset->getString(2));
208 result->setDebugMode(rset->getInt(3));
209 result->setDummyMode(rset->getInt(4));
210 result->setPatternDirectory(rset->getString(5));
211 result->setAutomaticMasks(rset->getInt(6));
212 result->setSRP0BunchAdjustPosition(rset->getInt(7));
213 result->setConfigFile(rset->getString(8));
215 Clob clob = rset->getClob(9);
216 m_size = clob.length();
217 Stream *instream = clob.getStream(1, 0);
218 unsigned char *
buffer =
new unsigned char[m_size];
219 memset(
buffer, 0, m_size);
220 instream->readBuffer((
char *)
buffer, m_size);
236 result->setAutomaticSrpSelect(rset->getInt(10));
239 throw(std::runtime_error(
std::string(
"ODSRPConfig::fetchData(): ") +
e.getMessage()));
249 this->checkConnection();
252 Statement *stmt = m_conn->createStatement();
254 "SELECT srp_configuration_id FROM ecal_srp_configuration " 255 "WHERE srp_tag=:srp_tag ");
257 stmt->setString(1, getConfigTag());
259 ResultSet *rset = stmt->executeQuery();
262 m_ID = rset->getInt(1);
266 m_conn->terminateStatement(stmt);
268 throw(std::runtime_error(
std::string(
"ODSRPConfig::fetchID: ") +
e.getMessage()));
int fetchNextId() noexcept(false)
oracle::occi::Stream Stream
int fetchID() noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
void fetchData(ODSRPConfig *result) noexcept(false)
void prepareWrite() noexcept(false) override
oracle::occi::Statement Statement
oracle::occi::SQLException SQLException
void writeDB() noexcept(false)