test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
ODBadXTInfo Class Reference

#include <ODBadXTInfo.h>

Inheritance diagram for ODBadXTInfo:
IODConfig IDBObject

Public Member Functions

int fetchID () throw (std::runtime_error)
 
int fetchNextId () throw (std::runtime_error)
 
int getId () const
 
std::string getTable ()
 
int getVersion () const
 
 ODBadXTInfo ()
 
void setId (int id)
 
void setParameters (const std::map< std::string, std::string > &my_keys_map)
 
void setVersion (int id)
 
 ~ODBadXTInfo ()
 
- Public Member Functions inherited from IODConfig
std::string getConfigTag ()
 
void setConfigTag (std::string x)
 
- Public Member Functions inherited from IDBObject
oracle::occi::Connection * getConn () const
 
oracle::occi::Environment * getEnv () const
 
void setConnection (oracle::occi::Environment *env, oracle::occi::Connection *conn)
 
virtual ~IDBObject ()
 

Private Member Functions

void clear ()
 
void fetchData (ODBadXTInfo *result) throw (std::runtime_error)
 
void prepareWrite () throw (std::runtime_error)
 
void writeDB () throw (std::runtime_error)
 

Private Attributes

int m_ID
 
int m_version
 

Friends

class EcalCondDBInterface
 

Additional Inherited Members

- Public Types inherited from IODConfig
typedef oracle::occi::Clob Clob
 
typedef oracle::occi::SQLException SQLException
 
typedef oracle::occi::Statement Statement
 
typedef oracle::occi::Stream Stream
 
- Public Attributes inherited from IODConfig
std::string m_config_tag
 
- Static Public Attributes inherited from IDBObject
static int const ECALDB_NROWS =1024
 
- Protected Member Functions inherited from IODConfig
void checkPrepare () throw (std::runtime_error)
 
void createReadStatement () throw (std::runtime_error)
 
void populateClob (Clob &clob, std::string fname, unsigned int bufsize) throw (std::runtime_error)
 
unsigned char * readClob (Clob &clob, int size) throw (std::runtime_error)
 
void setPrefetchRowCount (int ncount) throw (std::runtime_error)
 
void terminateReadStatement () throw (std::runtime_error)
 
void terminateWriteStatement () throw (std::runtime_error)
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const throw (std::runtime_error)
 
- Protected Attributes inherited from IODConfig
Statementm_readStmt
 
Statementm_writeStmt
 
- Protected Attributes inherited from IDBObject
oracle::occi::Connection * m_conn
 
oracle::occi::Environment * m_env
 

Detailed Description

Definition at line 9 of file ODBadXTInfo.h.

Constructor & Destructor Documentation

ODBadXTInfo::ODBadXTInfo ( )

Definition at line 11 of file ODBadXTInfo.cc.

References hitfit::clear(), and NULL.

12 {
13  m_env = NULL;
14  m_conn = NULL;
15  m_writeStmt = NULL;
16  m_readStmt = NULL;
17  m_config_tag="";
18  m_ID=0;
19  m_version=0;
20  clear();
21 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
#define NULL
Definition: scimark2.h:8
std::string m_config_tag
Definition: IODConfig.h:27
Statement * m_readStmt
Definition: IODConfig.h:37
void clear()
Definition: ODBadXTInfo.cc:24
ODBadXTInfo::~ODBadXTInfo ( )

Definition at line 30 of file ODBadXTInfo.cc.

31 {
32 }

Member Function Documentation

void ODBadXTInfo::clear ( void  )
private

Definition at line 24 of file ODBadXTInfo.cc.

24  {
25 
26 }
void ODBadXTInfo::fetchData ( ODBadXTInfo result)
throw (std::runtime_error
)
private

Definition at line 130 of file ODBadXTInfo.cc.

References alignCSCRings::e, and mps_fire::result.

132 {
133  this->checkConnection();
134  result->clear();
135  if(result->getId()==0 && (result->getConfigTag()=="") ){
136  throw(std::runtime_error("ODBadXTInfo::fetchData(): no Id defined for this ODBadXTInfo "));
137  }
138 
139 
140 
141  try {
142  if(result->getId()!=0) {
143  m_readStmt->setSQL("SELECT * FROM " + getTable() +
144  " where rec_id = :1 ");
145  m_readStmt->setInt(1, result->getId());
146  } else if (result->getConfigTag()!="") {
147  m_readStmt->setSQL("SELECT * FROM " + getTable() +
148  " where tag=:1 AND version=:2 " );
149  m_readStmt->setString(1, result->getConfigTag());
150  m_readStmt->setInt(2, result->getVersion());
151  } else {
152  // we should never pass here
153  throw(std::runtime_error("ODBadXTInfo::fetchData(): no Id defined for this record "));
154  }
155 
156 
157  ResultSet* rset = m_readStmt->executeQuery();
158 
159  rset->next();
160 
161  // 1 is the id and 2 is the config tag and 3 is the version
162 
163  result->setId(rset->getInt(1));
164  result->setConfigTag(rset->getString(2));
165  result->setVersion(rset->getInt(3));
166 
167  } catch (SQLException &e) {
168  throw(std::runtime_error("ODBadXTInfo::fetchData(): "+e.getMessage()));
169  }
170 }
void setId(int id)
Definition: ODBadXTInfo.h:18
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
int getVersion() const
Definition: ODBadXTInfo.h:24
int getId() const
Definition: ODBadXTInfo.h:19
std::string getTable()
Definition: ODBadXTInfo.h:16
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setConfigTag(std::string x)
Definition: IODConfig.h:31
Statement * m_readStmt
Definition: IODConfig.h:37
std::string getConfigTag()
Definition: IODConfig.h:32
void setVersion(int id)
Definition: ODBadXTInfo.h:23
void checkConnection() const
Definition: IDBObject.h:41
void clear()
Definition: ODBadXTInfo.cc:24
int ODBadXTInfo::fetchID ( )
throw (std::runtime_error
)

Definition at line 172 of file ODBadXTInfo.cc.

References alignCSCRings::e.

173 {
174  // Return from memory if available
175  if (m_ID!=0) {
176  return m_ID;
177  }
178 
179  this->checkConnection();
180 
181  try {
182  Statement* stmt = m_conn->createStatement();
183  stmt->setSQL("SELECT rec_id FROM "+ getTable()+
184  "WHERE tag=:1 and version=:2 " );
185 
186  stmt->setString(1, getConfigTag() );
187  stmt->setInt(2, getVersion() );
188 
189  ResultSet* rset = stmt->executeQuery();
190 
191  if (rset->next()) {
192  m_ID = rset->getInt(1);
193  } else {
194  m_ID = 0;
195  }
196  m_conn->terminateStatement(stmt);
197  } catch (SQLException &e) {
198  throw(std::runtime_error("ODBadXTInfo::fetchID: "+e.getMessage()));
199  }
200 
201  return m_ID;
202 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
int getVersion() const
Definition: ODBadXTInfo.h:24
std::string getTable()
Definition: ODBadXTInfo.h:16
oracle::occi::Statement Statement
Definition: IODConfig.h:23
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
std::string getConfigTag()
Definition: IODConfig.h:32
void checkConnection() const
Definition: IDBObject.h:41
int ODBadXTInfo::fetchNextId ( )
throw (std::runtime_error
)

Definition at line 36 of file ODBadXTInfo.cc.

References alignCSCRings::e, and mps_fire::result.

36  {
37 
38  int result=0;
39  try {
40  this->checkConnection();
41 
42  m_readStmt = m_conn->createStatement();
43  m_readStmt->setSQL("select COND2CONF_INFO_SQ.NextVal from DUAL ");
44  ResultSet* rset = m_readStmt->executeQuery();
45  while (rset->next ()){
46  result= rset->getInt(1);
47  }
48  result++;
49  m_conn->terminateStatement(m_readStmt);
50  return result;
51 
52  } catch (SQLException &e) {
53  throw(std::runtime_error("ODBadXTInfo::fetchNextId(): "+e.getMessage()));
54  }
55 
56 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
tuple result
Definition: mps_fire.py:84
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
Statement * m_readStmt
Definition: IODConfig.h:37
void checkConnection() const
Definition: IDBObject.h:41
int ODBadXTInfo::getId ( ) const
inline

Definition at line 19 of file ODBadXTInfo.h.

References m_ID.

19 { return m_ID; }
std::string ODBadXTInfo::getTable ( )
inlinevirtual

Implements IODConfig.

Definition at line 16 of file ODBadXTInfo.h.

16 { return "BAD_CRYSTALS_INFO"; }
int ODBadXTInfo::getVersion ( ) const
inline

Definition at line 24 of file ODBadXTInfo.h.

References m_version.

24 { return m_version; }
void ODBadXTInfo::prepareWrite ( )
throw (std::runtime_error
)
privatevirtual

Implements IODConfig.

Definition at line 58 of file ODBadXTInfo.cc.

References alignCSCRings::e, and getId().

60 {
61  this->checkConnection();
62 
63  int next_id=0;
64  if(getId()==0){
65  next_id=fetchNextId();
66  }
67 
68  try {
69  m_writeStmt = m_conn->createStatement();
70  m_writeStmt->setSQL("INSERT INTO "+getTable()+" ( rec_id, tag, version) "
71  " VALUES ( :1, :2, :3 ) " );
72 
73  m_writeStmt->setInt(1, next_id);
74  m_ID=next_id;
75 
76  } catch (SQLException &e) {
77  throw(std::runtime_error("ODBadXTInfo::prepareWrite(): "+e.getMessage()));
78  }
79 
80 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
int fetchNextId()
Definition: ODBadXTInfo.cc:36
int getId() const
Definition: ODBadXTInfo.h:19
std::string getTable()
Definition: ODBadXTInfo.h:16
void checkConnection() const
Definition: IDBObject.h:41
void ODBadXTInfo::setId ( int  id)
inline

Definition at line 18 of file ODBadXTInfo.h.

References m_ID.

18 { m_ID = id; }
void ODBadXTInfo::setParameters ( const std::map< std::string, std::string > &  my_keys_map)

Definition at line 82 of file ODBadXTInfo.cc.

82  {
83 
84  // parses the result of the XML parser that is a map of
85  // string string with variable name variable value
86 
87  for( std::map<std::string, std::string >::const_iterator ci=
88  my_keys_map.begin(); ci!=my_keys_map.end(); ci++ ) {
89 
90  if(ci->first== "VERSION") setVersion(atoi(ci->second.c_str()) );
91  if(ci->first== "TAG") setConfigTag(ci->second);
92 
93  }
94 
95 }
void setConfigTag(std::string x)
Definition: IODConfig.h:31
void setVersion(int id)
Definition: ODBadXTInfo.h:23
void ODBadXTInfo::setVersion ( int  id)
inline

Definition at line 23 of file ODBadXTInfo.h.

References m_version.

23 { m_version = id; }
void ODBadXTInfo::writeDB ( )
throw (std::runtime_error
)
private

Definition at line 97 of file ODBadXTInfo.cc.

References gather_cfg::cout, and alignCSCRings::e.

99 {
100  this->checkConnection();
101  this->checkPrepare();
102 
103  try {
104 
105  // number 1 is the id
106  m_writeStmt->setString(2, this->getConfigTag());
107  m_writeStmt->setInt(3, this->getVersion());
108 
109  m_writeStmt->executeUpdate();
110 
111 
112  } catch (SQLException &e) {
113  throw(std::runtime_error("ODBadXTInfo::writeDB(): "+e.getMessage()));
114  }
115  // Now get the ID
116  if (!this->fetchID()) {
117  throw(std::runtime_error("ODBadXTInfo::writeDB: Failed to write"));
118  } else {
119  int old_version=this->getVersion();
120  m_readStmt = m_conn->createStatement();
121  this->fetchData (this);
122  m_conn->terminateStatement(m_readStmt);
123  if(this->getVersion()!=old_version) std::cout << "ODBadXTInfo>>WARNING version is "<< getVersion()<< endl;
124  }
125 
126 
127 }
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
void fetchData(ODBadXTInfo *result)
Definition: ODBadXTInfo.cc:130
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
int getVersion() const
Definition: ODBadXTInfo.h:24
void checkPrepare()
Definition: IODConfig.h:39
Statement * m_readStmt
Definition: IODConfig.h:37
std::string getConfigTag()
Definition: IODConfig.h:32
tuple cout
Definition: gather_cfg.py:145
void checkConnection() const
Definition: IDBObject.h:41

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 11 of file ODBadXTInfo.h.

Member Data Documentation

int ODBadXTInfo::m_ID
private

Definition at line 42 of file ODBadXTInfo.h.

Referenced by getId(), and setId().

int ODBadXTInfo::m_version
private

Definition at line 43 of file ODBadXTInfo.h.

Referenced by getVersion(), and setVersion().