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
00067
00068 void ODDelaysDat::fetchData(std::vector< ODDelaysDat >* p, ODFEDelaysInfo* iov)
00069 throw(std::runtime_error)
00070 {
00071 this->checkConnection();
00072
00073 iov->setConnection(m_env, m_conn);
00074 int iovID = iov->fetchID();
00075 if (!iovID) {
00076
00077 return;
00078 }
00079
00080 try {
00081 m_readStmt->setSQL("SELECT * FROM " + getTable() + "WHERE rec_id = :rec_id order by sm_id, fed_id, tt_id ");
00082 m_readStmt->setInt(1, iovID);
00083 ResultSet* rset = m_readStmt->executeQuery();
00084
00085
00086 ODDelaysDat dat;
00087 while(rset->next()) {
00088
00089 dat.setSMId( rset->getInt(2) );
00090 dat.setFedId( rset->getInt(3) );
00091 dat.setTTId( rset->getInt(4) );
00092 dat.setTimeOffset( rset->getInt(5) );
00093
00094 p->push_back( dat);
00095
00096 }
00097 } catch (SQLException &e) {
00098 throw(std::runtime_error("ODDelaysDat::fetchData(): "+e.getMessage()));
00099 }
00100 }
00101
00102
00103
00104 void ODDelaysDat::writeArrayDB(const std::vector< ODDelaysDat > data, ODFEDelaysInfo* iov)
00105 throw(std::runtime_error)
00106 {
00107 this->checkConnection();
00108
00109 int iovID = iov->fetchID();
00110 if (!iovID) { throw(std::runtime_error("ODDelays::writeArrayDB: ODFEDelaysInfo not in DB")); }
00111
00112
00113 int nrows=data.size();
00114 int* ids= new int[nrows];
00115 int* xx= new int[nrows];
00116 int* yy= new int[nrows];
00117 int* zz= new int[nrows];
00118 int* st= new int[nrows];
00119
00120
00121
00122 ub2* ids_len= new ub2[nrows];
00123 ub2* x_len= new ub2[nrows];
00124 ub2* y_len= new ub2[nrows];
00125 ub2* z_len= new ub2[nrows];
00126 ub2* st_len= new ub2[nrows];
00127
00128
00129 ODDelaysDat dataitem;
00130
00131 int n_data= (int) data.size();
00132
00133 for (int count = 0; count < n_data ; count++) {
00134 dataitem=data[count];
00135 ids[count]=iovID;
00136 xx[count]=dataitem.getSMId();
00137 yy[count]=dataitem.getFedId();
00138 zz[count]=dataitem.getTTId();
00139 st[count]=dataitem.getTimeOffset();
00140
00141
00142 ids_len[count]=sizeof(ids[count]);
00143 x_len[count]=sizeof(xx[count]);
00144 y_len[count]=sizeof(yy[count]);
00145 z_len[count]=sizeof(zz[count]);
00146 st_len[count]=sizeof(st[count]);
00147
00148 }
00149
00150
00151 try {
00152 m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]),ids_len);
00153 m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
00154 m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00155 m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00156 m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00157
00158 m_writeStmt->executeArrayUpdate(nrows);
00159
00160 delete [] ids;
00161 delete [] xx;
00162 delete [] yy;
00163 delete [] zz;
00164 delete [] st;
00165
00166 delete [] ids_len;
00167 delete [] x_len;
00168 delete [] y_len;
00169 delete [] z_len;
00170 delete [] st_len;
00171
00172 } catch (SQLException &e) {
00173 throw(std::runtime_error("ODDelaysDat::writeArrayDB(): "+e.getMessage()));
00174 }
00175 }