TDbiResultSetNonAgg.cxx
Go to the documentation of this file.00001
00002
00003 #include "TDbiBinaryFile.hxx"
00004 #include "TDbiResultKey.hxx"
00005 #include "TDbiResultSetNonAgg.hxx"
00006 #include "TDbiInRowStream.hxx"
00007 #include "TDbiTableRow.hxx"
00008 #include "TDbiTimerManager.hxx"
00009 #include <TSK_DBI_Log.hxx>
00010 #include <MsgFormat.h>
00011 using std::endl;
00012
00013 ClassImp(TDbiResultSetNonAgg)
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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 TDbiResultSetNonAgg::TDbiResultSetNonAgg(TDbiInRowStream* resultSet,
00067 const TDbiTableRow* tableRow,
00068 const TDbiValidityRec* vrec,
00069 Bool_t dropSeqNo,
00070 const string& sqlQualifiers) :
00071 TDbiResultSet(resultSet,vrec,sqlQualifiers),
00072 fBuffer(0)
00073 {
00074
00075 this->DebugCtor();
00076
00077 if ( ! resultSet || resultSet->IsExhausted() || ! tableRow ) return;
00078
00079 if ( vrec ) TDbiTimerManager::gTimerManager.RecFillAgg(vrec->GetAggregateNo());
00080
00081
00082 TDbiInRowStream& rs = *resultSet;
00083 if ( rs.IsBeforeFirst() ) rs.FetchRow();
00084 if ( rs.IsExhausted() ) return;
00085
00086
00087 Int_t seqNo = 0;
00088 if ( dropSeqNo && rs.CurColName() == "SEQNO" ) {
00089 rs >> seqNo;
00090 rs.DecrementCurCol();
00091 }
00092
00093
00094 bool hasRowCounter = ! rs.IsVLDTable();
00095
00096
00097
00098 while ( ! rs.IsExhausted() ) {
00099
00100
00101
00102 if ( seqNo != 0 ) {
00103 Int_t nextSeqNo;
00104 rs >> nextSeqNo;
00105 if ( nextSeqNo != seqNo ) {
00106 rs.DecrementCurCol();
00107 break;
00108 }
00109 }
00110
00111
00112 if ( hasRowCounter ) rs.IncrementCurCol();
00113 TDbiTableRow* row = tableRow->CreateTableRow();
00114 if ( vrec) TDbiTimerManager::gTimerManager.StartSubWatch(3);
00115 row->SetOwner(this);
00116 row->Fill(rs,vrec);
00117 if ( vrec) TDbiTimerManager::gTimerManager.StartSubWatch(2);
00118 fRows.push_back(row);
00119 rs.FetchRow();
00120 if ( vrec) TDbiTimerManager::gTimerManager.StartSubWatch(1);
00121 }
00122
00123
00124 this->SetResultsFromDb();
00125 if ( seqNo == 0 )
00126 SK_DBI_Info( "Created unaggregated VLD result set no. of rows: "
00127 << this->GetNumRows() << " ");
00128 else SK_DBI_Info( "Created unaggregated result set for SeqNo: " << seqNo
00129 << " no. of rows: " << this->GetNumRows() << " ");
00130
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 TDbiResultSetNonAgg::~TDbiResultSetNonAgg() {
00160
00161
00162 SK_DBI_Trace( "Destroying TDbiResultSetNonAgg." << " ");
00163
00164 if ( ! fBuffer ) for ( vector<TDbiTableRow*>::iterator itr = fRows.begin();
00165 itr != fRows.end();
00166 ++itr) delete *itr;
00167 else {
00168 delete [] fBuffer;
00169 fBuffer = 0;
00170 }
00171 }
00172
00173
00174 TDbiResultKey* TDbiResultSetNonAgg::CreateKey() const {
00175
00176
00177
00178
00179
00180 string rowName("empty_table");
00181 const TDbiTableRow* row = this->GetTableRow(0);
00182 if ( row ) rowName = row->GetName();
00183 const TDbiValidityRec& vrec = this->GetValidityRec();
00184 return new TDbiResultKey(this->TableName(),
00185 rowName,
00186 vrec.GetSeqNo(),
00187 vrec.GetCreationDate() );
00188
00189 }
00190
00191
00192
00193 void TDbiResultSetNonAgg::DebugCtor() const {
00194
00195 SK_DBI_Trace( "Creating TDbiResultSetNonAgg" << (void*) this << " ");
00196 static const TDbiResultSetNonAgg* that = 0;
00197 if ( this == that ) {
00198 cout << "debug " << (void*) this << endl;
00199 }
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 const TDbiTableRow* TDbiResultSetNonAgg::GetTableRow(UInt_t rowNum) const {
00219
00220
00221
00222
00223
00224
00225 if ( rowNum >= fRows.size() ) return 0;
00226 return fRows[rowNum];
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 const TDbiTableRow* TDbiResultSetNonAgg::GetTableRowByIndex(UInt_t index) const {
00249
00250
00251 if ( ! this->LookUpBuilt() ) this->BuildLookUpTable();
00252
00253
00254 return this->TDbiResultSet::GetTableRowByIndex(index);
00255
00256 }
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 Bool_t TDbiResultSetNonAgg::Owns(const TDbiTableRow* row ) const {
00270
00271 vector<TDbiTableRow*>::const_iterator itr = fRows.begin();
00272 vector<TDbiTableRow*>::const_iterator itrEnd = fRows.end();
00273
00274 for (; itr != itrEnd; ++itr) if ( *itr == row ) return kTRUE;
00275
00276 return kFALSE;
00277
00278
00279 }
00280
00281
00282
00283 Bool_t TDbiResultSetNonAgg::Satisfies(const TDbiValidityRec& vrec,
00284 const string& sqlQualifiers) {
00285
00286
00287
00288
00289 SK_DBI_Debug( "Trying to satisfy: Vrec " << vrec << " SQL: " << sqlQualifiers
00290 << "\n with CanReuse: " << this->CanReuse()
00291 << " vrec: " << this->GetValidityRec()
00292 << " sqlQualifiers: " << this->GetSqlQualifiers()
00293 << " ");
00294
00295 if ( this->CanReuse() ) {
00296 const TDbiValidityRec& this_vrec = this->GetValidityRec();
00297 if ( sqlQualifiers == this->GetSqlQualifiers()
00298 && vrec.GetSeqNo() == this_vrec.GetSeqNo()
00299 && vrec.GetCreationDate() == this_vrec.GetCreationDate()
00300 ) return kTRUE;
00301 }
00302
00303 return kFALSE;
00304
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 void TDbiResultSetNonAgg::Streamer(TDbiBinaryFile& file) {
00317
00318 if ( file.IsReading() ) {
00319 this->TDbiResultSet::Streamer(file);
00320 SK_DBI_Debug( " Restoring TDbiResultSetNonAgg ..." << " ");
00321 file >> fRows;
00322
00323 fBuffer = file.ReleaseArrayBuffer();
00324 this->BuildLookUpTable();
00325 SK_DBI_Debug( " Restored TDbiResultSetNonAgg. Size:"
00326 << fRows.size() << " rows" << " ");
00327 }
00328 else if ( file.IsWriting() ) {
00329 this->TDbiResultSet::Streamer(file);
00330 SK_DBI_Debug( " Saving TDbiResultSetNonAgg. Size:"
00331 << fRows.size() << " rows" << " ");
00332 file << fRows;
00333 }
00334 }
00335
00336
00337
00338
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