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/ODDelaysDat.h"
00006
00007 using namespace std;
00008 using namespace oracle::occi;
00009
00010 ODDelaysDat::ODDelaysDat()
00011 {
00012 m_env = NULL;
00013 m_conn = NULL;
00014 m_writeStmt = NULL;
00015 m_readStmt = NULL;
00016
00017 m_sm = 0;
00018 m_fed = 0;
00019 m_tt = 0;
00020 m_t1 = 0;
00021
00022 }
00023
00024
00025
00026 ODDelaysDat::~ODDelaysDat()
00027 {
00028 }
00029
00030
00031
00032 void ODDelaysDat::prepareWrite()
00033 throw(std::runtime_error)
00034 {
00035 this->checkConnection();
00036
00037 try {
00038 m_writeStmt = m_conn->createStatement();
00039 m_writeStmt->setSQL("INSERT INTO "+getTable()+" (rec_id, sm_id, fed_id, tt_id, time_offset ) "
00040 "VALUES (:1, :2, :3, :4, :5 )");
00041 } catch (SQLException &e) {
00042 throw(std::runtime_error("ODDelaysDat::prepareWrite(): "+e.getMessage()));
00043 }
00044 }
00045
00046
00047
00048 void ODDelaysDat::writeDB(const ODDelaysDat* item, ODFEDelaysInfo* iov )
00049 throw(std::runtime_error)
00050 {
00051 this->checkConnection();
00052
00053 try {
00054 m_writeStmt->setInt(1, item->getId());
00055 m_writeStmt->setInt(2, item->getSMId());
00056 m_writeStmt->setInt(3, item->getFedId() );
00057 m_writeStmt->setInt(4, item->getTTId() );
00058 m_writeStmt->setInt(5, item->getTimeOffset() );
00059
00060 m_writeStmt->executeUpdate();
00061 } catch (SQLException &e) {
00062 throw(std::runtime_error("ODDelaysDat::writeDB(): "+e.getMessage()));
00063 }
00064 }
00065
00066 void ODDelaysDat::fetchData(std::vector< ODDelaysDat >* p, ODFEDelaysInfo* iov)
00067 throw(std::runtime_error) {
00068 iov->setConnection(m_env, m_conn);
00069 int iovID = iov->fetchID();
00070 fetchData(p, iovID);
00071 }
00072
00073 void ODDelaysDat::fetchData(std::vector< ODDelaysDat >* p, int iovID)
00074 throw(std::runtime_error)
00075 {
00076 this->checkConnection();
00077
00078 if (!iovID) {
00079
00080 return;
00081 }
00082
00083 try {
00084 m_readStmt = m_conn->createStatement();
00085 m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by sm_id, fed_id, tt_id");
00086 m_readStmt->setInt(1, iovID);
00087 ResultSet* rset = m_readStmt->executeQuery();
00088
00089
00090 ODDelaysDat dat;
00091 while(rset->next()) {
00092
00093 dat.setSMId( rset->getInt(2) );
00094 dat.setFedId( rset->getInt(3) );
00095 dat.setTTId( rset->getInt(4) );
00096 dat.setTimeOffset( rset->getInt(5) );
00097
00098 p->push_back( dat);
00099
00100 }
00101 } catch (SQLException &e) {
00102 throw(std::runtime_error("ODDelaysDat::fetchData(): "+e.getMessage()));
00103 }
00104 }
00105
00106
00107
00108 void ODDelaysDat::writeArrayDB(const std::vector< ODDelaysDat > data, ODFEDelaysInfo* iov)
00109 throw(std::runtime_error)
00110 {
00111 this->checkConnection();
00112
00113 int iovID = iov->fetchID();
00114 if (!iovID) { throw(std::runtime_error("ODDelays::writeArrayDB: ODFEDelaysInfo not in DB")); }
00115
00116
00117 int nrows=data.size();
00118 int* ids= new int[nrows];
00119 int* xx= new int[nrows];
00120 int* yy= new int[nrows];
00121 int* zz= new int[nrows];
00122 int* st= new int[nrows];
00123
00124
00125
00126 ub2* ids_len= new ub2[nrows];
00127 ub2* x_len= new ub2[nrows];
00128 ub2* y_len= new ub2[nrows];
00129 ub2* z_len= new ub2[nrows];
00130 ub2* st_len= new ub2[nrows];
00131
00132
00133 ODDelaysDat dataitem;
00134
00135 int n_data= (int) data.size();
00136
00137 for (int count = 0; count < n_data ; count++) {
00138 dataitem=data[count];
00139 ids[count]=iovID;
00140 xx[count]=dataitem.getSMId();
00141 yy[count]=dataitem.getFedId();
00142 zz[count]=dataitem.getTTId();
00143 st[count]=dataitem.getTimeOffset();
00144
00145
00146 ids_len[count]=sizeof(ids[count]);
00147 x_len[count]=sizeof(xx[count]);
00148 y_len[count]=sizeof(yy[count]);
00149 z_len[count]=sizeof(zz[count]);
00150 st_len[count]=sizeof(st[count]);
00151
00152 }
00153
00154
00155 try {
00156 m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]),ids_len);
00157 m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
00158 m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00159 m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00160 m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00161
00162 m_writeStmt->executeArrayUpdate(nrows);
00163
00164 delete [] ids;
00165 delete [] xx;
00166 delete [] yy;
00167 delete [] zz;
00168 delete [] st;
00169
00170 delete [] ids_len;
00171 delete [] x_len;
00172 delete [] y_len;
00173 delete [] z_len;
00174 delete [] st_len;
00175
00176 } catch (SQLException &e) {
00177 throw(std::runtime_error("ODDelaysDat::writeArrayDB(): "+e.getMessage()));
00178 }
00179 }