00001
00002
00003 #include "DatabaseInterface/DbiBinaryFile.h"
00004 #include "DatabaseInterface/DbiResultKey.h"
00005 #include "DatabaseInterface/DbiResultNonAgg.h"
00006 #include "DatabaseInterface/DbiResultSet.h"
00007 #include "DatabaseInterface/DbiTableRow.h"
00008 #include "DatabaseInterface/DbiTimerManager.h"
00009 #include "LeakChecker/Lea.h"
00010 #include "MessageService/MsgService.h"
00011
00012 ClassImp(DbiResultNonAgg)
00013
00014
00015
00016
00017 CVSID("$Id: DbiResultNonAgg.cxx,v 1.25 2006/08/08 10:51:32 west Exp $");
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 DbiResultNonAgg::DbiResultNonAgg(DbiResultSet* resultSet,
00029 const DbiTableRow* tableRow,
00030 const DbiValidityRec* vrec,
00031 Bool_t dropSeqNo,
00032 const string& sqlQualifiers) :
00033 DbiResult(resultSet,vrec,sqlQualifiers),
00034 fBuffer(0)
00035 {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 LEA_CTOR
00078 this->DebugCtor();
00079
00080 if ( ! resultSet || resultSet->IsExhausted() || ! tableRow ) return;
00081
00082 if ( vrec ) DbiTimerManager::gTimerManager.RecFillAgg(vrec->GetAggregateNo());
00083
00084
00085 DbiResultSet& rs = *resultSet;
00086 if ( rs.IsBeforeFirst() ) rs.FetchRow();
00087 if ( rs.IsExhausted() ) return;
00088
00089
00090 Int_t seqNo = 0;
00091 if ( dropSeqNo && rs.CurColName() == "SEQNO" ) {
00092 rs >> seqNo;
00093 rs.DecrementCurCol();
00094 }
00095
00096
00097 bool hasRowCounter = rs.HasRowCounter();
00098
00099
00100
00101 while ( ! rs.IsExhausted() ) {
00102
00103
00104
00105 if ( seqNo != 0 ) {
00106 Int_t nextSeqNo;
00107 rs >> nextSeqNo;
00108 if ( nextSeqNo != seqNo ) {
00109 rs.DecrementCurCol();
00110 break;
00111 }
00112 }
00113
00114
00115 if ( hasRowCounter ) rs.IncrementCurCol();
00116 DbiTableRow* row = tableRow->CreateTableRow();
00117 if ( vrec) DbiTimerManager::gTimerManager.StartSubWatch(3);
00118 row->SetOwner(this);
00119 row->Fill(rs,vrec);
00120 if ( vrec) DbiTimerManager::gTimerManager.StartSubWatch(2);
00121 fRows.push_back(row);
00122 rs.FetchRow();
00123 if ( vrec) DbiTimerManager::gTimerManager.StartSubWatch(1);
00124 }
00125
00126
00127 this->SetResultsFromDb();
00128 if ( seqNo == 0 )
00129 MSG("Dbi",Msg::kSynopsis) << "Created unaggregated VLD result set no. of rows: "
00130 << this->GetNumRows() << endl;
00131 else MSG("Dbi",Msg::kSynopsis) << "Created unaggregated result set for SeqNo: " << seqNo
00132 << " no. of rows: " << this->GetNumRows() << endl;
00133
00134 }
00135
00136
00137
00138
00139 DbiResultNonAgg::~DbiResultNonAgg() {
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 LEA_DTOR
00165
00166 MSG("Dbi", Msg::kVerbose) << "Destroying DbiResultNonAgg." << endl;
00167
00168 if ( ! fBuffer ) for ( vector<DbiTableRow*>::iterator itr = fRows.begin();
00169 itr != fRows.end();
00170 ++itr) delete *itr;
00171 else {
00172 delete [] fBuffer;
00173 fBuffer = 0;
00174 }
00175 }
00176
00177
00178 DbiResultKey* DbiResultNonAgg::CreateKey() const {
00179
00180
00181
00182
00183
00184 string rowName("empty_table");
00185 const DbiTableRow* row = this->GetTableRow(0);
00186 if ( row ) rowName = row->GetName();
00187 const DbiValidityRec& vrec = this->GetValidityRec();
00188 return new DbiResultKey(this->TableName(),
00189 rowName,
00190 vrec.GetSeqNo(),
00191 vrec.GetCreationDate() );
00192
00193 }
00194
00195
00196
00197 void DbiResultNonAgg::DebugCtor() const {
00198
00199 MSG("Dbi", Msg::kVerbose) << "Creating DbiResultNonAgg" << (void*) this << endl;
00200 static const DbiResultNonAgg* that = 0;
00201 if ( this == that ) {
00202 cout << "debug " << (void*) this << endl;
00203 }
00204 }
00205
00206
00207 const DbiTableRow* DbiResultNonAgg::GetTableRow(UInt_t rowNum) const {
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 if ( rowNum >= fRows.size() ) return 0;
00230 return fRows[rowNum];
00231 }
00232
00233
00234
00235 const DbiTableRow* DbiResultNonAgg::GetTableRowByIndex(UInt_t index) const {
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 if ( ! this->LookUpBuilt() ) this->BuildLookUpTable();
00256
00257
00258 return this->DbiResult::GetTableRowByIndex(index);
00259
00260 }
00261
00262
00263 Bool_t DbiResultNonAgg::Owns(const DbiTableRow* row ) const {
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 vector<DbiTableRow*>::const_iterator itr = fRows.begin();
00276 vector<DbiTableRow*>::const_iterator itrEnd = fRows.end();
00277
00278 for (; itr != itrEnd; ++itr) if ( *itr == row ) return kTRUE;
00279
00280 return kFALSE;
00281
00282
00283 }
00284
00285
00286
00287 Bool_t DbiResultNonAgg::Satisfies(const DbiValidityRec& vrec,
00288 const string& sqlQualifiers) {
00289
00290
00291
00292
00293 MSG("Dbi",Msg::kDebug)
00294 << "Trying to satisfy: Vrec " << vrec << " SQL: " << sqlQualifiers
00295 << "\n with CanReuse: " << this->CanReuse()
00296 << " vrec: " << this->GetValidityRec()
00297 << " sqlQualifiers: " << this->GetSqlQualifiers()
00298 << endl;
00299
00300 if ( this->CanReuse() ) {
00301 const DbiValidityRec& this_vrec = this->GetValidityRec();
00302 if ( sqlQualifiers == this->GetSqlQualifiers()
00303 && vrec.GetSeqNo() == this_vrec.GetSeqNo()
00304 && vrec.GetCreationDate() == this_vrec.GetCreationDate()
00305 ) return kTRUE;
00306 }
00307
00308 return kFALSE;
00309
00310 }
00311
00312
00313
00314 void DbiResultNonAgg::Streamer(DbiBinaryFile& file) {
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 if ( file.IsReading() ) {
00325 this->DbiResult::Streamer(file);
00326 MSG("Dbi", Msg::kDebug) << " Restoring DbiResultNonAgg ..." << endl;
00327 file >> fRows;
00328
00329 fBuffer = file.ReleaseArrayBuffer();
00330 this->BuildLookUpTable();
00331 MSG("Dbi", Msg::kDebug) << " Restored DbiResultNonAgg. Size:"
00332 << fRows.size() << " rows" << endl;
00333 }
00334 else if ( file.IsWriting() ) {
00335 this->DbiResult::Streamer(file);
00336 MSG("Dbi", Msg::kDebug) << " Saving DbiResultNonAgg. Size:"
00337 << fRows.size() << " rows" << endl;
00338 file << fRows;
00339 }
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372