DbiResultNonAgg Class Reference

#include <DbiResultNonAgg.h>

Inheritance diagram for DbiResultNonAgg:
DbiResult

List of all members.

Public Member Functions

 DbiResultNonAgg (DbiResultSet *resultSet=0, const DbiTableRow *tableRow=0, const DbiValidityRec *vrec=0, Bool_t dropSeqNo=kTRUE, const string &sqlQualifiers="")
virtual ~DbiResultNonAgg ()
virtual DbiResultKeyCreateKey () const
virtual UInt_t GetNumAggregates () const
virtual UInt_t GetNumRows () const
virtual const DbiTableRowGetTableRow (UInt_t rowNum) const
virtual const DbiTableRowGetTableRowByIndex (UInt_t index) const
virtual Bool_t Owns (const DbiTableRow *row) const
Bool_t Satisfies (const DbiValidityRec &vrec, const string &sqlQualifiers="")
virtual void Streamer (DbiBinaryFile &file)

Private Member Functions

void DebugCtor () const

Private Attributes

std::vector< DbiTableRow * > fRows
 Set of table rows eqv. to ResultSet.
char * fBuffer
 Not null only if table rows read from BinaryFile.

Detailed Description

Id
DbiResultNonAgg.h,v 1.16 2006/08/08 10:51:32 west Exp

Definition at line 38 of file DbiResultNonAgg.h.


Constructor & Destructor Documentation

DbiResultNonAgg::DbiResultNonAgg ( DbiResultSet resultSet = 0,
const DbiTableRow tableRow = 0,
const DbiValidityRec vrec = 0,
Bool_t  dropSeqNo = kTRUE,
const string &  sqlQualifiers = "" 
)

Definition at line 28 of file DbiResultNonAgg.cxx.

References DbiRowStream::CurColName(), DbiRowStream::DecrementCurCol(), DbiResultSet::FetchRow(), DbiTableRow::Fill(), DbiTimerManager::gTimerManager, DbiRowStream::HasRowCounter(), DbiRowStream::IncrementCurCol(), DbiResultSet::IsBeforeFirst(), DbiResultSet::IsExhausted(), Msg::kSynopsis, LEA_CTOR, MSG, DbiTimerManager::RecFillAgg(), DbiTableRow::SetOwner(), and DbiTimerManager::StartSubWatch().

00032                                                               :
00033 DbiResult(resultSet,vrec,sqlQualifiers),
00034 fBuffer(0)
00035 {
00036 //
00037 //
00038 //  Purpose:  Default constructor
00039 //
00040 //  Arguments: 
00041 //      resultSet    in/out Pointer DbiResultSet from query. May be null.  
00042 //      tableRow     in     Pointer to a sample tableRow object. 
00043 //                          May be null.
00044 //      vrec         in     Pointer to validity record from query. 
00045 //                          May be null
00046 //      dropSeqNo    in     If = kTRUE, drop SeqNo if it is the first col.
00047 //      sqlQualifier in     Extended Context sql qualifiers
00048 //
00049 //  Return:    n/a
00050 //
00051 //  Contact:   N. West
00052 //
00053 //  Specification:-
00054 //  =============
00055 //
00056 //  o Create Result from DbiResultSet generated by query.  If first
00057 //    column is named SeqNo then strip it off before filling each 
00058 //    DbiTableRow and quit as soon as the SeqNo changes. 
00059 //     
00060 
00061 //  Program Notes:-
00062 //  =============
00063 
00064 //  o tableRow is just used to create new subclass DbiTableRow objects.
00065 //
00066 //  o  The special treatment for tables that start with SeqNo allow   
00067 //     a single DbiResultSet to fill multiple DbiResult objects but does
00068 //     require that the result set is ordered by SeqNo.
00069 //
00070 //  The look-up table is not built by default, its construction is
00071 //  triggered by use (GetTableRowByIndex).  For DbiResultNonAgg
00072 //  that are part of a DbiResultAgg there is no need to build the
00073 //  table.
00074 
00075 
00076 
00077   LEA_CTOR    //Leak Checker
00078   this->DebugCtor();
00079 
00080   if ( ! resultSet || resultSet->IsExhausted() || ! tableRow ) return;
00081 
00082   if ( vrec ) DbiTimerManager::gTimerManager.RecFillAgg(vrec->GetAggregateNo());
00083 
00084 //Move to first row if result set not yet started.
00085   DbiResultSet& rs = *resultSet;
00086   if ( rs.IsBeforeFirst() ) rs.FetchRow();
00087   if ( rs.IsExhausted() ) return;
00088     
00089 //Check and load sequence number if necessary.
00090   Int_t seqNo = 0;
00091   if ( dropSeqNo && rs.CurColName() == "SEQNO" ) {
00092     rs >> seqNo;
00093     rs.DecrementCurCol();
00094   }
00095 
00096 // Check for ROW_COUNTER (which has to be ignored when reading).
00097   bool hasRowCounter = rs.HasRowCounter();
00098 
00099 // Create and fill table row object and move result set onto next row.
00100 
00101   while ( ! rs.IsExhausted() ) {
00102 
00103 //  If stripping off sequence numbers check the next and quit,
00104 //  having restored the last, if it changes.
00105     if ( seqNo != 0 ) {
00106       Int_t nextSeqNo;
00107       rs >> nextSeqNo;
00108       if ( nextSeqNo != seqNo ) {
00109         rs.DecrementCurCol();
00110         break;
00111       }
00112     }
00113 
00114 // Strip off ROW_COUNTER if present.
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   //Flag that data was read from Database.
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 }

DbiResultNonAgg::~DbiResultNonAgg (  )  [virtual]

Definition at line 139 of file DbiResultNonAgg.cxx.

References fBuffer, fRows, Msg::kVerbose, LEA_DTOR, and MSG.

00139                                   {
00140 //
00141 //
00142 //  Purpose: Destructor
00143 //
00144 //  Arguments: 
00145 //    None.
00146 //
00147 //  Return:    n/a
00148 //
00149 //  Contact:   N. West
00150 //
00151 //  Specification:-
00152 //  =============
00153 //
00154 //  o  Destroy ResultNonAgg and all its owned DbiTableRow subclass 
00155 //     objects.
00156 
00157 
00158 //  Program Notes:-
00159 //  =============
00160 
00161 //  If fRows restored from BinaryFile then it doesn't own its
00162 //  DbiTableRows.
00163 
00164   LEA_DTOR    //Leak Checker
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 }


Member Function Documentation

DbiResultKey * DbiResultNonAgg::CreateKey (  )  const [virtual]

Implements DbiResult.

Definition at line 178 of file DbiResultNonAgg.cxx.

References DbiValidityRec::GetCreationDate(), DbiValidityRec::GetSeqNo(), GetTableRow(), DbiResult::GetValidityRec(), and DbiResult::TableName().

00178                                                {
00179 //
00180 //
00181 //  Purpose:  Create a key that corresponds to this result.
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 }

void DbiResultNonAgg::DebugCtor (  )  const [private]

Definition at line 197 of file DbiResultNonAgg.cxx.

References Msg::kVerbose, and MSG.

00197                                       {
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 }

virtual UInt_t DbiResultNonAgg::GetNumAggregates (  )  const [inline, virtual]

Implements DbiResult.

Definition at line 60 of file DbiResultNonAgg.h.

00060 { return 1; }

virtual UInt_t DbiResultNonAgg::GetNumRows (  )  const [inline, virtual]

Implements DbiResult.

Definition at line 61 of file DbiResultNonAgg.h.

References fRows.

Referenced by DbiResultAgg::DbiResultAgg(), DbiValidityRecBuilder::DbiValidityRecBuilder(), and DbiTableProxy::Query().

00061                                                   { 
00062                                                   return fRows.size(); }

const DbiTableRow * DbiResultNonAgg::GetTableRow ( UInt_t  rowNum  )  const [virtual]

Implements DbiResult.

Definition at line 207 of file DbiResultNonAgg.cxx.

References fRows.

Referenced by CreateKey(), DbiValidityRecBuilder::DbiValidityRecBuilder(), and DbiTableProxy::Query().

00207                                                                    {
00208 //
00209 //
00210 //  Purpose:  Return TableRow from last query.
00211 //
00212 //  Arguments: 
00213 //    rowNum      in    Required row number (0..NumRows-1)
00214 //
00215 //  Return:    TableRow ptr, or =0 if no row.
00216 //
00217 //  Contact:   N. West
00218 //
00219 //  Specification:-
00220 //  =============
00221 //
00222 //  o Return TableRow from last query, or =0 if no row.
00223 
00224 //  Program Notes:-
00225 //  =============
00226 
00227 //  None.
00228 
00229   if ( rowNum >= fRows.size() ) return 0;
00230   return fRows[rowNum];
00231 }

const DbiTableRow * DbiResultNonAgg::GetTableRowByIndex ( UInt_t  index  )  const [virtual]

Reimplemented from DbiResult.

Definition at line 235 of file DbiResultNonAgg.cxx.

References DbiResult::BuildLookUpTable(), and DbiResult::LookUpBuilt().

00235                                                                          {
00236 //
00237 //
00238 //  Purpose: Return TableRow with supplied index, or =0 if no row. 
00239 //
00240 //  Arguments: 
00241 //    index        in    Required index.
00242 //
00243 //  Return:    TableRow with required index, or =0 if no row.
00244 //
00245 //  Contact:   N. West
00246 //
00247 //  Specification:-
00248 //  =============
00249 //
00250 //  o If look-up table not yet built, build it.
00251 //
00252 //  o Return TableRow with supplied index, or =0 if no row. 
00253 
00254  
00255   if ( ! this->LookUpBuilt() ) this->BuildLookUpTable();
00256 
00257 // The real look-up still takes place in the base class.
00258   return this->DbiResult::GetTableRowByIndex(index);
00259 
00260 }

Bool_t DbiResultNonAgg::Owns ( const DbiTableRow row  )  const [virtual]

Reimplemented from DbiResult.

Definition at line 263 of file DbiResultNonAgg.cxx.

References fRows.

00263                                                           {
00264 //
00265 //
00266 //  Purpose:  Return true if owns row.
00267 //
00268 
00269 //  Program Notes:-
00270 //  =============
00271 
00272 //  Only DbiResultNonAggs own rows; the base class DbiResult supplies
00273 //  the default method that returns false.
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 }

Bool_t DbiResultNonAgg::Satisfies ( const DbiValidityRec vrec,
const string &  sqlQualifiers = "" 
) [virtual]

Reimplemented from DbiResult.

Definition at line 287 of file DbiResultNonAgg.cxx.

References DbiResult::CanReuse(), DbiValidityRec::GetCreationDate(), DbiValidityRec::GetSeqNo(), DbiResult::GetSqlQualifiers(), DbiResult::GetValidityRec(), Msg::kDebug, and MSG.

00288                                                                {
00289 //
00290 //
00291 //  Purpose: Check to see if this Result matches the supplied  DbiValidityRec.
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 }

void DbiResultNonAgg::Streamer ( DbiBinaryFile file  )  [virtual]

Reimplemented from DbiResult.

Definition at line 314 of file DbiResultNonAgg.cxx.

References DbiResult::BuildLookUpTable(), fBuffer, fRows, DbiBinaryFile::IsReading(), DbiBinaryFile::IsWriting(), Msg::kDebug, MSG, and DbiBinaryFile::ReleaseArrayBuffer().

00314                                                   {
00315 //
00316 //
00317 //  Purpose:  I/O to binary file
00318 //
00319 //  Program Notes:-
00320 //  =============
00321 
00322 //  Do I/O for base class DbiResult first.  Rebuild fIndexKeys on input.
00323 
00324   if ( file.IsReading() ) {
00325     this->DbiResult::Streamer(file);
00326     MSG("Dbi", Msg::kDebug) << "    Restoring DbiResultNonAgg ..." << endl; 
00327     file >> fRows;
00328 //  Take ownership of the memory holding the array.
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 }


Member Data Documentation

char* DbiResultNonAgg::fBuffer [private]

Not null only if table rows read from BinaryFile.

Definition at line 83 of file DbiResultNonAgg.h.

Referenced by Streamer(), and ~DbiResultNonAgg().

std::vector<DbiTableRow*> DbiResultNonAgg::fRows [private]

Set of table rows eqv. to ResultSet.

Definition at line 80 of file DbiResultNonAgg.h.

Referenced by GetNumRows(), GetTableRow(), Owns(), Streamer(), and ~DbiResultNonAgg().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1