CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IODConfig.h
Go to the documentation of this file.
1 #ifndef IODCONFIG_H
2 #define IODCONFIG_H
3 #include <stdexcept>
4 #include <string>
5 #include <fstream>
6 #include <iostream>
7 #include <stdio.h>
8 #include <cstring>
9 
10 
12 
14 
19 class IODConfig : public IDBObject {
20 
21  public:
23  typedef oracle::occi::Statement Statement;
24  typedef oracle::occi::Stream Stream;
25  typedef oracle::occi::Clob Clob;
26 
28 
29  virtual std::string getTable() =0;
30 
33 
34 
35  protected:
38 
39  inline void checkPrepare()
40  throw(std::runtime_error)
41  {
42  if (m_writeStmt == NULL) {
43  throw(std::runtime_error("Write statement not prepared"));
44  }
45  }
46 
48  throw(std::runtime_error)
49  {
50  if (m_writeStmt != NULL) {
51  m_conn->terminateStatement(m_writeStmt);
52  } else {
53  std::cout << "Warning from IDataItem: statement was aleady closed"<< std::endl;
54  }
55  }
56 
57 
58  inline void createReadStatement()
59  throw(std::runtime_error)
60  {
61  m_readStmt=m_conn->createStatement();
62  }
63 
64  inline void setPrefetchRowCount(int ncount)
65  throw(std::runtime_error)
66  {
67  m_readStmt->setPrefetchRowCount(ncount);
68  }
69 
70  inline void terminateReadStatement()
71  throw(std::runtime_error)
72  {
73  if (m_readStmt != NULL) {
74  m_conn->terminateStatement(m_readStmt);
75  } else {
76  std::cout << "Warning from IDataItem: statement was aleady closed"<< std::endl;
77  }
78  }
79 
80 
81 
82  // Prepare a statement for writing operations
83  virtual void prepareWrite() throw(std::runtime_error) =0;
84 
85  // virtual void writeDB() throw(std::runtime_error) ;
86 
87 
88 void populateClob (Clob &clob, std::string fname, unsigned int bufsize)
89  throw (std::runtime_error)
90 {
91 
92  try{
93  // Uses stream here
94  std::cout << "Populating the Clob using writeBuffer(Stream) method" << std::endl;
95  std::cout<<"we are here0"<<std::endl;
96 
97  char *file = (char *)fname.c_str();
98  std::cout<<"we are here0.5 file is:"<<fname<<std::endl;
99 
100  std::ifstream inFile;
101  inFile.open(file,std::ios::in);
102  if (!inFile)
103  {
104  std::cout << fname <<" file not found\n";
105  inFile.close();
106 
107  std::string fname2="/nfshome0/ecaldev/francesca/null_file.txt";
108  inFile.open((char*)fname2.c_str(),std::ios::in);
109 
110 
111 
112  }
113  if(bufsize==0){
114 
115 
116  inFile.seekg( 0,std::ios::end );
117  bufsize = inFile.tellg();
118  std::cout <<" bufsize ="<<bufsize<< std::endl;
119  // set file pointer to start again
120  inFile.seekg( 0,std::ios::beg );
121 
122  }
123 
124  char *buffer = new char[bufsize + 1];
125 
126 
127  std::cout<<"we are here1"<<std::endl;
128  unsigned int size;
129  Stream *strm=clob.getStream();
130  std::cout<<"we are here2"<<std::endl;
131  // while(inFile)
132  // {
133  int buf=0;
134  memset (buffer, buf, bufsize + 1);
135  inFile.read(buffer,bufsize);
136  std::cout<<"we are here2.5"<<std::endl;
137 
138  strm->writeBuffer(buffer,strlen(buffer));
139  std::cout<<"we are here2.6"<<std::endl;
140 
141  //}
142  std::cout<<"we are here3"<<std::endl;
143  strcpy(buffer," ");
144  size=strlen(buffer);
145  strm->writeLastBuffer(buffer,size);
146  clob.closeStream(strm);
147  inFile.close();
148  std::cout<<"we are here4"<<std::endl;
149  delete[] buffer;
150 
151 
152  }catch (SQLException &e) {
153  throw(std::runtime_error("populateClob(): "+e.getMessage()));
154  }
155 
156  std::cout << "Populating the Clob - Success" << std::endl;
157 }
158 
159 
160 unsigned char* readClob (Clob &clob, int size)
161  throw (std::runtime_error)
162 {
163 
164  try{
165  Stream *instream = clob.getStream (1,0);
166  unsigned char *buffer= new unsigned char[size];
167  int buf=0;
168  memset (buffer, buf, size);
169 
170  instream->readBuffer ((char*)buffer, size);
171  std::cout << "remember to delete the char* at the end of the program ";
172  for (int i = 0; i < size; ++i)
173  std::cout << (char) buffer[i];
174  std::cout << std::endl;
175 
176 
177  clob.closeStream (instream);
178 
179  return buffer;
180 
181  }catch (SQLException &e) {
182  throw(std::runtime_error("readClob(): "+e.getMessage()));
183  }
184 
185 }
186 
187 
188 
189 };
190 
191 #endif
192 
193 
void populateClob(Clob &clob, std::string fname, unsigned int bufsize)
Definition: IODConfig.h:88
int i
Definition: DBlmapReader.cc:9
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
Statement * m_writeStmt
Definition: IODConfig.h:36
oracle::occi::Stream Stream
Definition: IODConfig.h:24
virtual void prepareWrite()=0
unsigned char * readClob(Clob &clob, int size)
Definition: IODConfig.h:160
#define NULL
Definition: scimark2.h:8
virtual std::string getTable()=0
void terminateReadStatement()
Definition: IODConfig.h:70
void terminateWriteStatement()
Definition: IODConfig.h:47
std::string m_config_tag
Definition: IODConfig.h:27
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
#define end
Definition: vmac.h:37
void createReadStatement()
Definition: IODConfig.h:58
oracle::occi::Statement Statement
Definition: IODConfig.h:23
oracle::occi::Clob Clob
Definition: IODConfig.h:25
void checkPrepare()
Definition: IODConfig.h:39
string fname
main script
void setConfigTag(std::string x)
Definition: IODConfig.h:31
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
Statement * m_readStmt
Definition: IODConfig.h:37
void setPrefetchRowCount(int ncount)
Definition: IODConfig.h:64
std::string getConfigTag()
Definition: IODConfig.h:32
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10
tuple size
Write out results.