Go to the documentation of this file.00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004
00005 #include "OnlineDB/EcalCondDB/interface/ODWeightsSamplesDat.h"
00006
00007 using namespace std;
00008 using namespace oracle::occi;
00009
00010 ODWeightsSamplesDat::ODWeightsSamplesDat()
00011 {
00012 m_env = NULL;
00013 m_conn = NULL;
00014 m_writeStmt = NULL;
00015 m_readStmt = NULL;
00016
00017 m_fed = 0;
00018
00019 }
00020
00021
00022
00023 ODWeightsSamplesDat::~ODWeightsSamplesDat()
00024 {
00025 }
00026
00027
00028
00029 void ODWeightsSamplesDat::prepareWrite()
00030 throw(std::runtime_error)
00031 {
00032 this->checkConnection();
00033
00034 try {
00035 m_writeStmt = m_conn->createStatement();
00036 m_writeStmt->setSQL("INSERT INTO "+getTable()+" (rec_id, fed_id, sample_id, weight_number ) "
00037 "VALUES (:1, :2, :3, :4 )");
00038 } catch (SQLException &e) {
00039 throw(std::runtime_error("ODWeightsSamplesDat::prepareWrite(): "+e.getMessage()));
00040 }
00041 }
00042
00043
00044
00045 void ODWeightsSamplesDat::writeDB(const ODWeightsSamplesDat* item, ODFEWeightsInfo* iov )
00046 throw(std::runtime_error)
00047 {
00048 this->checkConnection();
00049
00050 try {
00051 m_writeStmt->setInt(1, item->getId());
00052 m_writeStmt->setInt(2, item->getFedId() );
00053 m_writeStmt->setInt(3, item->getSampleId() );
00054 m_writeStmt->setInt(4, item->getWeightNumber() );
00055
00056 m_writeStmt->executeUpdate();
00057 } catch (SQLException &e) {
00058 throw(std::runtime_error("ODWeightsSamplesDat::writeDB(): "+e.getMessage()));
00059 }
00060 }
00061
00062
00063
00064 void ODWeightsSamplesDat::fetchData(std::vector< ODWeightsSamplesDat >* p, ODFEWeightsInfo* iov)
00065 throw(std::runtime_error)
00066 {
00067 this->checkConnection();
00068
00069 iov->setConnection(m_env, m_conn);
00070 int iovID = iov->fetchID();
00071 if (!iovID) {
00072 std::cout <<"ID not in the DB"<< endl;
00073 return;
00074 }
00075
00076 try {
00077 m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by fed_id, sample_id");
00078 m_readStmt->setInt(1, iovID);
00079 ResultSet* rset = m_readStmt->executeQuery();
00080
00081
00082 ODWeightsSamplesDat dat;
00083 while(rset->next()) {
00084
00085 dat.setFedId( rset->getInt(2) );
00086 dat.setSampleId( rset->getInt(3) );
00087 dat.setWeightNumber( rset->getInt(4) );
00088
00089 p->push_back( dat);
00090
00091 }
00092
00093 } catch (SQLException &e) {
00094 throw(std::runtime_error("ODWeightsSamplesDat::fetchData(): "+e.getMessage()));
00095 }
00096 }
00097
00098
00099
00100 void ODWeightsSamplesDat::writeArrayDB(const std::vector< ODWeightsSamplesDat > data, ODFEWeightsInfo* iov)
00101 throw(std::runtime_error)
00102 {
00103 this->checkConnection();
00104
00105 int iovID = iov->fetchID();
00106 if (!iovID) { throw(std::runtime_error("ODDelays::writeArrayDB: ODFEDelaysInfo not in DB")); }
00107
00108
00109 int nrows=data.size();
00110 int* ids= new int[nrows];
00111 int* xx= new int[nrows];
00112 int* yy= new int[nrows];
00113 int* zz= new int[nrows];
00114
00115 ub2* ids_len= new ub2[nrows];
00116 ub2* x_len= new ub2[nrows];
00117 ub2* y_len= new ub2[nrows];
00118 ub2* z_len= new ub2[nrows];
00119
00120 ODWeightsSamplesDat dataitem;
00121
00122 int n_data= (int) data.size();
00123 for (int count = 0; count <n_data ; count++) {
00124 dataitem=data[count];
00125 ids[count]=iovID;
00126 xx[count]=dataitem.getFedId();
00127 yy[count]=dataitem.getSampleId();
00128 zz[count]=dataitem.getWeightNumber();
00129
00130
00131 ids_len[count]=sizeof(ids[count]);
00132 x_len[count]=sizeof(xx[count]);
00133 y_len[count]=sizeof(yy[count]);
00134 z_len[count]=sizeof(zz[count]);
00135
00136 }
00137
00138
00139 try {
00140 m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]),ids_len);
00141 m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
00142 m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00143 m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00144
00145
00146 m_writeStmt->executeArrayUpdate(nrows);
00147
00148 delete [] ids;
00149 delete [] xx;
00150 delete [] yy;
00151 delete [] zz;
00152
00153 delete [] ids_len;
00154 delete [] x_len;
00155 delete [] y_len;
00156 delete [] z_len;
00157
00158 } catch (SQLException &e) {
00159 throw(std::runtime_error("ODWeightsSamplesDat::writeArrayDB(): "+e.getMessage()));
00160 }
00161 }