#include <DbiResult.h>
Inheritance diagram for DbiResult:

Public Member Functions | |
| DbiResult (DbiResultSet *resultSet=0, const DbiValidityRec *vrec=0, const string &sqlQualifiers="") | |
| virtual | ~DbiResult () |
| virtual Bool_t | CanReuse () const |
| virtual Bool_t | CanSave () const |
| virtual void | Connect () const |
| virtual DbiResultKey * | CreateKey () const =0 |
| virtual void | Disconnect () const |
| const DbiExceptionLog & | GetExceptionLog () const |
| Int_t | GetID () const |
| virtual const DbiResultKey * | GetKey () const |
| virtual UInt_t | GetNumAggregates () const =0 |
| virtual UInt_t | GetNumClients () const |
| virtual UInt_t | GetNumRows () const =0 |
| const string & | GetSqlQualifiers () const |
| virtual const DbiTableRow * | GetTableRow (UInt_t rowNum) const =0 |
| virtual const DbiTableRow * | GetTableRowByIndex (UInt_t index) const |
| virtual const DbiValidityRec & | GetValidityRec (const DbiTableRow *=0) const |
| virtual const DbiValidityRec & | GetValidityRecGlobal () const |
| Bool_t | IsExtendedContext () const |
| virtual Bool_t | Owns (const DbiTableRow *) const |
| Bool_t | ResultsFromDb () const |
| virtual const string & | TableName () const |
| void | CaptureExceptionLog (UInt_t startFrom) |
| virtual Bool_t | CanDelete (const DbiResult *res=0) |
| Return true if no clients and unlikely to be reused. | |
| virtual Bool_t | Satisfies (const VldContext &vc, const Dbi::Task &task) |
| virtual Bool_t | Satisfies (const string &) |
| virtual Bool_t | Satisfies (const DbiValidityRec &, const string &="") |
| virtual void | DeRegisterKey () |
| Key handling. | |
| virtual void | RegisterKey () |
| virtual void | Streamer (DbiBinaryFile &file) |
| virtual void | SetCanReuse (Bool_t reuse) |
Protected Member Functions | |
| void | SetResultsFromDb () |
| void | BuildLookUpTable () const |
| Bool_t | LookUpBuilt () const |
| virtual void | SetTableName (const string &tableName) |
| virtual void | SetValidityRec (const DbiValidityRec &vRec) |
Private Attributes | |
| Int_t | fID |
| Unique ID within the current job. | |
| Bool_t | fCanReuse |
| DbiValidityRec | fEffVRec |
| IndexToRow_t | fIndexKeys |
| const DbiResultKey * | fKey |
| Bool_t | fResultsFromDb |
| True is at least part didn't come from cache. | |
| Int_t | fNumClients |
| string | fTableName |
| string | fSqlQualifiers |
| DbiExceptionLog | fExceptionLog |
| Exception log produced when query was executed. | |
Static Private Attributes | |
| Int_t | fgLastID |
| Used to allocate unique ID within the current job. | |
DatabaseInterface
Contact: n.west1@physics.ox.ac.uk
Definition at line 48 of file DbiResult.h.
|
||||||||||||||||
|
Definition at line 51 of file DbiResult.cxx. References fEffVRec, fTableName, LEA_CTOR, MSG, and DbiRowStream::TableNameTc(). 00053 : 00054 fID(++fgLastID), 00055 fCanReuse(kTRUE), 00056 fEffVRec(0), 00057 fKey(0), 00058 fResultsFromDb(kFALSE), 00059 fNumClients(0), 00060 fTableName("Unknown"), 00061 fSqlQualifiers(sqlQualifiers) 00062 { 00063 // 00064 // 00065 // Purpose: Default constructor 00066 // 00067 // Arguments: 00068 // resultSet in Pointer DbiResultSet from query. May be null. 00069 // vrec in Pointer to validity record from query. 00070 // May be null 00071 // sqlQualifier in Extended Context sql qualifiers 00072 // 00073 // Return: n/a 00074 // 00075 // Contact: N. West 00076 // 00077 // Specification:- 00078 // ============= 00079 // 00080 // o Create Result from DbiResultSet generated by query. 00081 00082 00083 // Program Notes:- 00084 // ============= 00085 00086 // None. 00087 00088 LEA_CTOR //Leak Checker 00089 00090 MSG("Dbi", Msg::kVerbose) << "Creating DbiResult" << endl; 00091 00092 if ( vrec ) fEffVRec = *vrec; 00093 if ( resultSet ) fTableName = resultSet->TableNameTc(); 00094 00095 }
|
|
|
Definition at line 99 of file DbiResult.cxx. References DeRegisterKey(), fNumClients, LEA_DTOR, and MSG. 00099 {
00100 //
00101 //
00102 // Purpose: Destructor
00103 //
00104 // Arguments:
00105 // None.
00106 //
00107 // Return: n/a
00108 //
00109 // Contact: N. West
00110 //
00111 // Specification:-
00112 // =============
00113 //
00114 // o Destroy Result.
00115
00116
00117 // Program Notes:-
00118 // =============
00119
00120 // None.
00121
00122 LEA_DTOR //Leak Checker
00123
00124 MSG("Dbi", Msg::kVerbose) << "Destroying DbiResult." << endl;
00125
00126 if ( fNumClients ) MSG("Dbi", Msg::kWarning)
00127 << "Warning: Destroying DbiResult with " << fNumClients
00128 << " clients " << endl;
00129
00130 this->DeRegisterKey();
00131
00132 }
|
|
|
Definition at line 135 of file DbiResult.cxx. References fIndexKeys, DbiTableRow::GetAggregateNo(), DbiTableRow::GetIndex(), GetNumRows(), DbiTableRow::GetOwner(), DbiValidityRec::GetSeqNo(), GetTableRow(), GetTableRowByIndex(), GetValidityRec(), IsExtendedContext(), MAXMSG, MSG, and TableName(). Referenced by DbiResultNonAgg::GetTableRowByIndex(), and DbiResultNonAgg::Streamer(). 00135 {
00136 //
00137 //
00138 // Purpose: Build look-up Natural Index -> TableRow.
00139 //
00140 // Contact: N. West
00141 //
00142 // Program Notes:-
00143 // =============
00144 //
00145 // This member function assumes that the sub-class can support
00146 // the GetTableRow(...) and GetNumRows methods so take care if
00147 // called in the sub-class ctor.
00148
00149 // Extended Context serach can produce duplicates.
00150 Bool_t duplicatesOK = this->IsExtendedContext();
00151
00152 MSG("Dbi", Msg::kVerbose) << "Building look-uptable. Allow duplicates: "
00153 << duplicatesOK << endl;
00154
00155 for ( Int_t rowNo = this->GetNumRows()-1;
00156 rowNo >= 0;
00157 --rowNo ) {
00158 const DbiTableRow* row = this->GetTableRow(rowNo);
00159 UInt_t index = row->GetIndex(rowNo);
00160 // Ensure we use this class's GetTableRowByIndex, the method is
00161 // virtual but if the subclass has called this method then it must
00162 // be the right one to use. [Actually DbiResultAgg overrides
00163 // GetTableRowByIndex, but only to make building lazy].
00164 const DbiTableRow* row2 = this->DbiResult::GetTableRowByIndex(index);
00165
00166 MSG("Dbi", Msg::kVerbose)
00167 << "Look-up. Row no " << rowNo
00168 << " index " << index
00169 << " row,row2 " << (void*) row << "," << (void*) row2 << endl;
00170
00171 if ( row2 != 0 && row2 != row && ! duplicatesOK ) {
00172 std::ostringstream msg;
00173 msg << "Duplicated row natural index: " << index
00174 << " Found at row " << rowNo
00175 << " of table " << this->TableName()
00176 << ":-\n index of agg " << row->GetAggregateNo();
00177 if ( row->GetOwner() ) msg << "(SEQNO " << row->GetOwner()->GetValidityRec(row).GetSeqNo() << ")";
00178 msg << " matches agg " << row2->GetAggregateNo();
00179 if ( row2->GetOwner() ) msg << "(SEQNO " << row2->GetOwner()->GetValidityRec(row2).GetSeqNo() << ")";
00180 MAXMSG("Dbi",Msg::kError,20) << msg.str() << endl;
00181 }
00182
00183 else fIndexKeys[index] = row;
00184 }
00185
00186 }
|
|
|
Return true if no clients and unlikely to be reused.
Definition at line 190 of file DbiResult.cxx. References CanReuse(), GetNumClients(), GetValidityRec(), DbiValidityRec::HasExpired(), and SetCanReuse(). Referenced by DbiCache::Purge(). 00190 {
00191 //
00192 //
00193 // Purpose: See if suitable for deleting.
00194 //
00195 // Arguments:
00196 // res in A DbiResult that is currently used.
00197 // Optional: default = 0.
00198
00199 // If the query would be satisfied apart from the date, then
00200 // assume we have moved out of the validity window, never
00201 // to return!
00202
00203 if ( res
00204 && this->CanReuse()
00205 && this->GetValidityRec().HasExpired(res->GetValidityRec())
00206 ) this->SetCanReuse(kFALSE);
00207
00208 return ! this->GetNumClients() && ! this->CanReuse();
00209 }
|
|
|
Definition at line 61 of file DbiResult.h. Referenced by CanDelete(), DbiResultNonAgg::Satisfies(), DbiResultAgg::Satisfies(), and Satisfies(). 00061 { return fCanReuse; }
|
|
|
Definition at line 62 of file DbiResult.h. Referenced by DbiTableProxy::SaveToL2Cache(). 00062 { return kTRUE; }
|
|
|
Definition at line 213 of file DbiResult.cxx. References DbiExceptionLog::Clear(), DbiExceptionLog::Copy(), fExceptionLog, and DbiExceptionLog::GetGELog(). Referenced by DbiTableProxy::Query(). 00213 {
00214 //
00215 //
00216 // Purpose: Capture Exception Log from latest entries in Global Exception Log.
00217
00218 fExceptionLog.Clear();
00219 DbiExceptionLog::GetGELog().Copy(fExceptionLog,startFrom);
00220
00221 }
|
|
|
Definition at line 63 of file DbiResult.h. Referenced by DbiResultAgg::DbiResultAgg(), DbiResultPtr< T >::DbiResultPtr(), and DbiResultPtr< T >::NewQuery(). 00063 { ++fNumClients; }
|
|
|
Implemented in DbiResultAgg, and DbiResultNonAgg. Referenced by DbiResultAgg::CreateKey(), and RegisterKey(). |
|
|
Key handling.
Definition at line 225 of file DbiResult.cxx. References DbiRecord::DeleteKey(), fKey, DbiServices::GetRecord(), and MSG. Referenced by ~DbiResult(). 00225 {
00226 //
00227 //
00228 // Purpose: Deregister key if it exists.
00229
00230 if ( ! fKey ) return;
00231
00232 DbiRecord* record = DbiServices::GetRecord();
00233 if ( ! record ) {
00234 MSG("Dbi",Msg::kWarning) << "Attempting to deregister DbiResultKey at " << (void*) fKey
00235 << " but owning DbiRecord cannot be found." << endl;
00236 }
00237 else {
00238 record->DeleteKey(fKey);
00239 fKey = 0;
00240 }
00241
00242 }
|
|
|
Definition at line 65 of file DbiResult.h. Referenced by DbiResultPtr< T >::Disconnect(). 00065 { --fNumClients; }
|
|
|
Definition at line 66 of file DbiResult.h. 00066 { return fExceptionLog; }
|
|
|
Definition at line 67 of file DbiResult.h. Referenced by DbiResultPtr< T >::GetResultID(). 00067 { return fID; }
|
|
|
Definition at line 245 of file DbiResult.cxx. References fKey, and DbiResultKey::GetEmptyKey(). Referenced by DbiCache::Adopt(), and DbiResultPtr< T >::GetKey(). 00245 {
00246
00247 // Purpose: Get the associated DbiResultKey, or an empty one if none exists.
00248
00249 return fKey ? fKey : DbiResultKey::GetEmptyKey();
00250
00251 }
|
|
|
Implemented in DbiResultAgg, and DbiResultNonAgg. Referenced by DbiCache::Search(). |
|
|
Definition at line 70 of file DbiResult.h. Referenced by CanDelete(), DbiCache::Purge(), and Satisfies(). 00070 {
00071 return fNumClients; }
|
|
|
|
Definition at line 73 of file DbiResult.h. Referenced by DbiResultNonAgg::Satisfies(), and DbiResultAgg::Satisfies(). 00073 { return fSqlQualifiers; }
|
|
|
Implemented in DbiResultAgg, and DbiResultNonAgg. Referenced by BuildLookUpTable(), DbiResultAgg::DbiResultAgg(), DbiResultPtr< T >::GetRow(), and DbiValRecSet::GetTableRow(). |
|
|
Reimplemented in DbiResultNonAgg. Definition at line 255 of file DbiResult.cxx. References fIndexKeys. Referenced by BuildLookUpTable(), DbiResultPtr< T >::GetRowByIndex(), and DbiResultNonAgg::GetTableRowByIndex(). 00255 {
00256 //
00257 //
00258 // Purpose: Return row corresponding to Natural Index (or 0 if none)
00259 //
00260 // Contact: N. West
00261 //
00262
00263 // Use Find rather than operator[] to avoid creating entry
00264 // if index missing
00265 IndexToRow_t::const_iterator idx = fIndexKeys.find(index);
00266 return ( idx == fIndexKeys.end() ) ? 0 : (*idx).second;
00267
00268 }
|
|
|
Reimplemented in DbiResultAgg. Definition at line 76 of file DbiResult.h. Referenced by DbiCache::Adopt(), BuildLookUpTable(), CanDelete(), DbiResultNonAgg::CreateKey(), DbiResultAgg::CreateKey(), DbiResultPtr< T >::GetValidityRec(), DbiResultPtr< T >::NewQuery(), DbiResultPtr< T >::NextQuery(), DbiCache::Purge(), DbiTableProxy::RestoreFromL2Cache(), DbiResultNonAgg::Satisfies(), and Satisfies(). 00077 {
00078 return GetValidityRecGlobal(); }
|
|
|
Definition at line 79 of file DbiResult.h. Referenced by DbiCache::Adopt(), DbiResultAgg::GetValidityRec(), and DbiResultAgg::Streamer(). 00079 {
00080 return fEffVRec; }
|
|
|
Definition at line 81 of file DbiResult.h. Referenced by BuildLookUpTable(), and Satisfies(). 00081 {
00082 return this->GetSqlQualifiers() != ""; }
|
|
|
Definition at line 116 of file DbiResult.h. Referenced by DbiResultNonAgg::GetTableRowByIndex(). 00116 { return fIndexKeys.size() > 0; }
|
|
|
Reimplemented in DbiResultNonAgg. Definition at line 83 of file DbiResult.h. 00083 { return kFALSE; }
|
|
|
Definition at line 272 of file DbiResult.cxx. References DbiRecord::AdoptKey(), CreateKey(), fKey, GetNumRows(), DbiServices::GetRecord(), and MSG. Referenced by DbiCache::Adopt(). 00272 {
00273 //
00274 //
00275 // Purpose: Create and register key if set not empty and not already done.
00276
00277 if ( fKey || this->GetNumRows() == 0) return;
00278
00279 DbiRecord* record = DbiServices::GetRecord();
00280 if ( ! record ) {
00281 MSG("Dbi",Msg::kWarning) << "cannot create and register key"
00282 << ", owning DbiRecord cannot be found." << endl;
00283 }
00284 else {
00285 DbiResultKey* key = this->CreateKey();
00286 record->AdoptKey(key);
00287 fKey = key;
00288 }
00289
00290 }
|
|
|
Definition at line 84 of file DbiResult.h. Referenced by DbiResultPtr< T >::ResultsFromDb(), and DbiTableProxy::SaveToL2Cache(). 00084 { return fResultsFromDb; }
|
|
||||||||||||
|
Reimplemented in DbiResultNonAgg. Definition at line 100 of file DbiResult.h. 00101 {return kFALSE;}
|
|
|
Not all DbiResult classes can satisfy these types of query so those that do must override. Reimplemented in DbiResultAgg. Definition at line 99 of file DbiResult.h. 00099 {return kFALSE;}
|
|
||||||||||||
|
All DbiResult classes can satisfy this type of primary query so impliment here. Definition at line 293 of file DbiResult.cxx. References CanReuse(), GetNumClients(), GetValidityRec(), DbiValidityRec::HasExpired(), DbiValidityRec::IsCompatible(), IsExtendedContext(), MSG, and SetCanReuse(). Referenced by DbiCache::Search(). 00294 {
00295 //
00296 //
00297 // Purpose: Check to see if this Result satisfies specific context query.
00298 //
00299 // Arguments:
00300 // vc in Context of query
00301 // task in Task of query
00302 //
00303 // Return: kTRUE if can satisfy query.
00304 //
00305 // Contact: N. West
00306 //
00307 // Program Notes:-
00308 // =============
00309
00310 // If it cannot satisfy the query in a way that suggests
00311 // that its unlikely that it will satisfy future queries
00312 // then mark as cannot reuse so that it becomes eligible
00313 // for purging.
00314
00315 // Extended Context queries cannot satisfy specific context queries.
00316
00317 Bool_t isExtendedContext = this->IsExtendedContext();
00318 Bool_t canReuse = this->CanReuse();
00319 Bool_t isCompatible = this->GetValidityRec().IsCompatible(vc,task);
00320 Bool_t hasExpired = this->GetValidityRec().HasExpired(vc,task);
00321 UInt_t numClients = this->GetNumClients();
00322 MSG("Dbi",Msg::kDebug)
00323 << " Checking result with DbiValidityRec:- \n " << this->GetValidityRec()
00324 << " With extended context: " << isExtendedContext
00325 << " CanReuse: " << canReuse
00326 << " Is Compatible: " << isCompatible
00327 << " HasExpired: " << hasExpired
00328 << " number of clients: " << numClients
00329 << endl;
00330
00331 if ( isExtendedContext ) return kFALSE;
00332
00333 if ( canReuse && isCompatible ) return kTRUE;
00334
00335 // If the query would be satisfied apart from the date, then
00336 // assume we have moved out of the validity window, never
00337 // to return!
00338
00339 if ( canReuse && hasExpired && numClients == 0 ) {
00340 MSG("Dbi",Msg::kDebug) << " Marking result as not reusable" << endl;
00341 this-> SetCanReuse(kFALSE);
00342 }
00343
00344 return kFALSE;
00345
00346 }
|
|
|
Definition at line 108 of file DbiResult.h. Referenced by CanDelete(), DbiResultAgg::DbiResultAgg(), DbiTableProxy::Query(), Satisfies(), and DbiCache::SetStale(). 00108 { fCanReuse = reuse ; }
|
|
|
Definition at line 111 of file DbiResult.h. 00111 { fResultsFromDb = kTRUE; }
|
|
|
Definition at line 120 of file DbiResult.h. 00120 {
00121 fTableName = tableName; }
|
|
|
Definition at line 122 of file DbiResult.h. 00122 {
00123 fEffVRec = vRec; }
|
|
|
Reimplemented in DbiResultAgg, and DbiResultNonAgg. Definition at line 349 of file DbiResult.cxx. References fEffVRec, fNumClients, fResultsFromDb, fTableName, DbiBinaryFile::IsReading(), DbiBinaryFile::IsWriting(), MSG, and DbiValidityRec::Streamer(). Referenced by operator<<(), operator>>(), and DbiResultNonAgg::Streamer(). 00349 {
00350 //
00351 //
00352 // Purpose: I/O to binary file
00353 //
00354 // Program Notes:-
00355 // =============
00356
00357 // Don't store fIndexKeys; it will be rebuilt on input by the subclass.
00358
00359 if ( file.IsReading() ) {
00360 MSG("Dbi", Msg::kDebug) << " Restoring DbiResult ..." << endl;
00361 file >> fCanReuse;
00362 fEffVRec.Streamer(file);
00363 MSG("Dbi", Msg::kVerbose) << " Restored " << fEffVRec << endl;
00364 fResultsFromDb = kFALSE;
00365 fNumClients = 0;
00366 file >> fTableName;
00367 MSG("Dbi", Msg::kVerbose) << " Restored string " << fTableName << endl;
00368 }
00369 else if ( file.IsWriting() ) {
00370 MSG("Dbi", Msg::kDebug) << " Saving DbiResult ..." << endl;
00371 file << fCanReuse;
00372 MSG("Dbi", Msg::kVerbose) << " Saving " << fEffVRec << endl;
00373 fEffVRec.Streamer(file);
00374 MSG("Dbi", Msg::kVerbose) << " Saving string " << fTableName << endl;
00375 file << fTableName;
00376 }
00377 }
|
|
|
Definition at line 85 of file DbiResult.h. Referenced by DbiCache::Adopt(), BuildLookUpTable(), DbiValRecSet::GetTableName(), and DbiCache::Purge(). 00085 { return fTableName; }
|
|
|
Definition at line 134 of file DbiResult.h. |
|
|
Definition at line 137 of file DbiResult.h. Referenced by DbiResult(), and Streamer(). |
|
|
Exception log produced when query was executed.
Definition at line 158 of file DbiResult.h. Referenced by CaptureExceptionLog(). |
|
|
Used to allocate unique ID within the current job.
|
|
|
Unique ID within the current job.
Definition at line 131 of file DbiResult.h. |
|
|
Definition at line 140 of file DbiResult.h. Referenced by BuildLookUpTable(), and GetTableRowByIndex(). |
|
|
Definition at line 143 of file DbiResult.h. Referenced by DeRegisterKey(), GetKey(), and RegisterKey(). |
|
|
Definition at line 148 of file DbiResult.h. Referenced by Streamer(), and ~DbiResult(). |
|
|
True is at least part didn't come from cache.
Definition at line 146 of file DbiResult.h. Referenced by Streamer(). |
|
|
Null unless Extended Context query in which case it contains:- context-sql;data-sql;fill-options Definition at line 155 of file DbiResult.h. |
|
|
Definition at line 151 of file DbiResult.h. Referenced by DbiResult(), and Streamer(). |
1.3.9.1