DbiTableProxy Class Reference

#include <DbiTableProxy.h>

List of all members.

Public Member Functions

const DbiDBProxyGetDBProxy () const
DbiCascaderGetCascader ()
const DbiTableMetaDataGetMetaData () const
const DbiTableMetaDataGetMetaValid () const
string GetRowName () const
string GetTableName () const
DbiCacheGetCache ()
const DbiResultQuery (const VldContext &vc, const Dbi::Task &task, Bool_t findFullTimeWindow=true)
const DbiResultQuery (const string &context, const Dbi::Task &task, const string &data, const string &fillOpts)
const DbiResultQuery (UInt_t seqNo, UInt_t dbNo)
const DbiResultQuery (const DbiValidityRec &vrec, Bool_t canReuse=kTRUE)
VldTimeStamp QueryOverlayCreationDate (const DbiValidityRec &vrec, UInt_t dbNo)
void RefreshMetaData ()
void SetSqlCondition (const string &sql)
Bool_t TableExists () const

Protected Member Functions

 DbiTableProxy (DbiCascader *cascader, const string &tableName, const string &vldSuffix, const DbiTableRow *tableRow)
virtual ~DbiTableProxy ()

Private Member Functions

 DbiTableProxy (const DbiTableProxy &)
DbiTableProxyoperator= (const DbiTableProxy &)
Bool_t CanReadL2Cache () const
Bool_t CanWriteL2Cache () const
Bool_t RestoreFromL2Cache (const DbiValidityRecBuilder &builder)
Bool_t SaveToL2Cache (const string &name, DbiResult &res)

Private Attributes

DbiCascaderfCascader
 Pointer to one and only cascader.
DbiTableMetaData fMetaData
 Meta data for main(data) table.
DbiTableMetaData fMetaValid
 Meta data for aux. (validity)table.
Bool_t fCanL2Cache
 True if row supports L2 cache.
DbiCachefCache
 Associated cache for result.
DbiDBProxy fDBProxy
 Proxy to database.
Bool_t fExists
 true if table exists;
string fTableName
 Table Name.
DbiTableRowfTableRow
 Pet object used to create new rows.

Friends

class DbiTableProxyRegistry

Detailed Description

Id
DbiTableProxy.h,v 1.25 2006/08/08 10:51:32 west Exp

Definition at line 44 of file DbiTableProxy.h.


Constructor & Destructor Documentation

DbiTableProxy::DbiTableProxy ( DbiCascader cascader,
const string &  tableName,
const string &  vldSuffix,
const DbiTableRow tableRow 
) [protected]

Definition at line 33 of file DbiTableProxy.cxx.

References Msg::kInfo, Msg::kVerbose, LEA_CTOR, and MSG.

00036                                                           :
00037   fCascader(cascader),
00038 fMetaData(tableName),
00039 fMetaValid(tableName+vldSuffix),
00040 fCanL2Cache(kFALSE),
00041 fCache(0),
00042 fDBProxy(*cascader,tableName,&fMetaData,&fMetaValid,this),
00043 fExists(0),
00044 fTableName(tableName),
00045 fTableRow(tableRow->CreateTableRow())
00046 {
00047 //
00048 //
00049 //  Purpose:  Constructor
00050 //
00051 //  Arguments:   
00052 //             in  cascader   Reference to one and only cascader
00053 //             in  tableName  Table name.
00054 //             in  vldSuffix  Suffix to tableName for validity table
00055 //             in  tableRow   Example table row object.
00056 //
00057 //  Return:    n/a
00058 //
00059 //  Contact:   N. West
00060 //
00061 //  Specification:-
00062 //  =============
00063 //
00064 //  o Create table proxy for supplied table name.
00065 
00066 
00067 //  Program Notes:-
00068 //  =============
00069 
00070 //  None.
00071 
00072   LEA_CTOR    //Leak Checker
00073 
00074   fCache = new DbiCache(*this,fTableName);
00075   this->RefreshMetaData();
00076   fExists = fDBProxy.TableExists();
00077   fCanL2Cache = tableRow->CanL2Cache();
00078   if ( fCanL2Cache ) {
00079     MSG("Dbi", Msg::kInfo) << "DbiTableProxy: Can L2 cache " 
00080                            << this->GetRowName() << endl;
00081   }
00082   MSG("Dbi", Msg::kVerbose) << "Creating DbiTableProxy " 
00083                           << fTableName.c_str() << " at " << this
00084                           << ( fExists ? " (table exists)" 
00085                                        : " (table missing)" )
00086                           << endl;
00087 }

DbiTableProxy::~DbiTableProxy (  )  [protected, virtual]

Definition at line 91 of file DbiTableProxy.cxx.

References fCache, fTableName, fTableRow, Msg::kVerbose, LEA_DTOR, and MSG.

00091                               {
00092 //
00093 //
00094 //  Purpose: Destructor
00095 //
00096 //  Arguments: 
00097 //    None.
00098 //
00099 //  Return:    n/a
00100 //
00101 //  Contact:   N. West
00102 //
00103 //  Specification:-
00104 //  =============
00105 //
00106 //  o  Destroy object.
00107 
00108 
00109 //  Program Notes:-
00110 //  =============
00111 
00112 //  None.
00113 
00114   LEA_DTOR    //Leak Checker
00115 
00116     MSG("Dbi", Msg::kVerbose) << "Destroying DbiTableProxy " 
00117                             << fTableName << " at " << this
00118                             << endl;
00119   delete fCache;
00120   delete fTableRow;
00121 
00122 }

DbiTableProxy::DbiTableProxy ( const DbiTableProxy  )  [private]

Member Function Documentation

Bool_t DbiTableProxy::CanReadL2Cache (  )  const [private]

Definition at line 125 of file DbiTableProxy.cxx.

References fCanL2Cache.

Referenced by Query(), and RestoreFromL2Cache().

00125                                            {
00126 //
00127 
00128   return fCanL2Cache && DbiBinaryFile::CanReadL2Cache();
00129 
00130 }

Bool_t DbiTableProxy::CanWriteL2Cache (  )  const [private]

Definition at line 131 of file DbiTableProxy.cxx.

References fCanL2Cache.

Referenced by SaveToL2Cache().

00131                                             {
00132 //
00133 
00134   return fCanL2Cache && DbiBinaryFile::CanWriteL2Cache();
00135 
00136 }

DbiCache* DbiTableProxy::GetCache ( void   )  [inline]
DbiCascader& DbiTableProxy::GetCascader (  )  [inline]

Definition at line 53 of file DbiTableProxy.h.

References fCascader.

Referenced by DbiWriter< T >::Close(), and DbiLogEntry::Write().

00053 { return *fCascader; }

const DbiDBProxy& DbiTableProxy::GetDBProxy (  )  const [inline]
const DbiTableMetaData& DbiTableProxy::GetMetaData (  )  const [inline]
const DbiTableMetaData& DbiTableProxy::GetMetaValid (  )  const [inline]

Definition at line 55 of file DbiTableProxy.h.

References fMetaValid.

Referenced by DbiSqlValPacket::AddRow(), DbiSqlValPacket::Recreate(), and DbiSqlValPacket::SetMetaData().

00055 { return fMetaValid; }

string DbiTableProxy::GetRowName (  )  const [inline]

Definition at line 56 of file DbiTableProxy.h.

References fTableRow.

Referenced by RestoreFromL2Cache(), and SaveToL2Cache().

00056                                            { 
00057                       return fTableRow ? fTableRow->ClassName() : "Unknown";}

string DbiTableProxy::GetTableName (  )  const [inline]
DbiTableProxy& DbiTableProxy::operator= ( const DbiTableProxy  )  [private]
const DbiResult * DbiTableProxy::Query ( const DbiValidityRec vrec,
Bool_t  canReuse = kTRUE 
)

Definition at line 352 of file DbiTableProxy.cxx.

References DbiCache::Adopt(), DbiResult::CaptureExceptionLog(), Munits::cm, fCache, fCascader, fDBProxy, fTableRow, DbiValidityRec::GetDbNo(), DbiExceptionLog::GetGELog(), DbiValidityRec::GetL2CacheName(), DbiValidityRec::GetSeqNo(), GetTableName(), DbiValidityRec::GetTableProxy(), Msg::kError, MAXMSG, DbiDBProxy::QuerySeqNo(), RestoreFromL2Cache(), SaveToL2Cache(), DbiCache::Search(), DbiResult::SetCanReuse(), and DbiExceptionLog::Size().

00353                                                                      {
00354 //
00355 //
00356 //  Purpose:  Apply non-agregate query to database table and return result.
00357 //
00358 //  Arguments: 
00359 //    vrec         in    The validity record that satisfies the query.
00360 //    canReuse     in    True if result is to be cached.
00361 //
00362 //  Return:    Query result (never zero even if query fails).
00363 //
00364 //  Contact:   N. West
00365 //
00366 //  Specification:-
00367 //  =============
00368 //
00369 //  o Apply non-aggregated query to main database table. Cache if required,
00370 //    and return result.
00371 
00372 
00373 // See if it can be recovered from the level 2 disk cache.
00374 
00375   DbiConnectionMaintainer cm(fCascader);  //Stack object to hold connections
00376 
00377 // Make Global Exception Log bookmark
00378   UInt_t startGEL = DbiExceptionLog::GetGELog().Size()+1;
00379 
00380   if ( canReuse ) {
00381     DbiValidityRecBuilder builder(vrec,this->GetTableName());
00382     if ( this->RestoreFromL2Cache(builder) ) {
00383       const DbiResult* res = fCache->Search(vrec);
00384       if ( res ) return res;
00385     }
00386   }
00387 
00388   unsigned int seqNo = vrec.GetSeqNo();
00389   DbiResult* result = 0;
00390 
00391 //  If no records, create an empty DbiResult.
00392   if ( ! seqNo ) {
00393     result = new DbiResultNonAgg(0,0,&vrec);
00394   }
00395 
00396 //  If query does not apply to this table, report error and
00397 //  produce an empty DbiResult.
00398 
00399   else if (vrec.GetTableProxy()->GetTableName() != GetTableName() ) {
00400     MAXMSG("Dbi",Msg::kError,20) 
00401        << "Unable to satisfy DbiValidityRec keyed query:" << endl
00402        << vrec
00403        << " was filled by " << vrec.GetTableProxy()->GetTableName() 
00404        << " not by this DbiTableProxy (" 
00405        << GetTableName() << ")" << endl;
00406     result = new DbiResultNonAgg(0,0,&vrec);
00407   }
00408 
00409   else {
00410 
00411 
00412 // Apply query, and build DiResult from its DbiResultSet.
00413 
00414     DbiResultSet* rs = fDBProxy.QuerySeqNo(seqNo,vrec.GetDbNo());
00415     result = new DbiResultNonAgg(rs,fTableRow,&vrec);
00416     delete rs;
00417   }
00418 
00419 // Record latest entries from Global Exception Log.
00420   result->CaptureExceptionLog(startGEL);
00421 
00422 //  Cache in memory and on disk if required and return the results.
00423 
00424   fCache->Adopt(result);
00425   if ( canReuse ) this->SaveToL2Cache(vrec.GetL2CacheName(),*result);
00426   else result->SetCanReuse(kFALSE);
00427 
00428   return result;
00429 
00430 }

const DbiResult * DbiTableProxy::Query ( UInt_t  seqNo,
UInt_t  dbNo 
)

Definition at line 306 of file DbiTableProxy.cxx.

References DbiCache::Adopt(), DbiResult::CaptureExceptionLog(), Munits::cm, fCache, fCascader, fDBProxy, DbiExceptionLog::GetGELog(), DbiResultNonAgg::GetNumRows(), DbiResultNonAgg::GetTableRow(), Query(), DbiDBProxy::QueryValidity(), and DbiExceptionLog::Size().

00306                                                               {
00307 //
00308 //
00309 //  Purpose:  Apply non-agregate query to database table and return result.
00310 //
00311 //  Arguments: 
00312 //    seqNo        in    The sequence number of validity record that satisfies the query.
00313 //    dbNo         in    Database number in the cascade.
00314 //
00315 //  Return:    Query result (never zero even if query fails).
00316 
00317   DbiConnectionMaintainer cm(fCascader);  //Stack object to hold connections
00318 
00319 // Make Global Exception Log bookmark
00320   UInt_t startGEL = DbiExceptionLog::GetGELog().Size()+1;
00321 
00322   // Apply SEQNO query to cascade member.
00323   DbiResultSet* rs = fDBProxy.QueryValidity(seqNo,dbNo);
00324   DbiValidityRec tr;
00325   DbiResultNonAgg result(rs,&tr,0,kFALSE);
00326   delete rs;
00327 
00328   // If query failed, return an empty result.
00329   if ( result.GetNumRows() == 0 ) {
00330     DbiResultNonAgg* empty = new DbiResultNonAgg();
00331 //  Record latest entries from Global Exception Log.
00332     empty->CaptureExceptionLog(startGEL);
00333     fCache->Adopt(empty);
00334     return empty;
00335   }
00336 
00337 // Otherwise perform a validity rec query, but don't
00338 // allow result to be used; it's validity has not been trimmed
00339 // by neighbouring records.
00340 
00341   const DbiValidityRec* vrec 
00342        = dynamic_cast<const DbiValidityRec*>(result.GetTableRow(0));
00343 //  Force off const - we haven't finished with DbiResult yet!
00344   DbiResult* res = const_cast<DbiResult*>(Query(*vrec,kFALSE));
00345 // Record latest entries from Global Exception Log.
00346   res->CaptureExceptionLog(startGEL);
00347   return res;
00348 
00349 }

const DbiResult * DbiTableProxy::Query ( const string &  context,
const Dbi::Task task,
const string &  data,
const string &  fillOpts 
)

Definition at line 233 of file DbiTableProxy.cxx.

References DbiCache::Adopt(), DbiResult::CaptureExceptionLog(), Munits::cm, fCache, fCascader, fDBProxy, fTableName, fTableRow, DbiExceptionLog::GetGELog(), Dbi::kAnyTask, Msg::kVerbose, MSG, DbiCache::Search(), and DbiExceptionLog::Size().

00236                                                              {
00237 //
00238 //
00239 //  Purpose:  Apply extended context query to database table and return result.
00240 //
00241 //  Arguments: 
00242 //    context      in    The Validity Context (see DbiSqlContext)
00243 //    task         in    The task of the query.
00244 //    data         in    Optional SQL extension to secondary query.
00245 //    fillOpts     in    Optional fill options (available to DbiTableRow)
00246 //
00247 //  Return:    Query result (never zero even if query fails).
00248 //
00249 //  Contact:   N. West
00250 //
00251 //  Specification:-
00252 //  =============
00253 //
00254 //  o Apply extended context query to database table and return result.
00255 //
00256 //  o Don't save/restore to L2 cache: encoding the query name as a file name
00257 //    would be cumbersome and in any case extended queries are abnormal
00258 //    so optimisation is unwarranted.
00259 
00260 
00261 //  Construct the query's "SQL Qualifiers" by forming the 3 strings 
00262 //  (which task encoded into the context) into a single semi-colon 
00263 //  separated string.
00264 
00265   std::ostringstream os;
00266   os << context;
00267   if ( task != Dbi::kAnyTask
00268        ) os << " and  Task = " << task;
00269   os <<  ';' << data << ';' << fillOpts;
00270   string sqlQualifiers = os.str();
00271 
00272   MSG("Dbi", Msg::kVerbose) 
00273     << "Extended query: sqlQualifiers: " << sqlQualifiers << endl;
00274 
00275 //  See if there is one already in the cache.
00276 
00277   if ( const DbiResult* result = fCache->Search(sqlQualifiers) 
00278      ) return result;
00279 
00280   DbiConnectionMaintainer cm(fCascader);  //Stack object to hold connections
00281 
00282 // Make Global Exception Log bookmark
00283   UInt_t startGEL = DbiExceptionLog::GetGELog().Size()+1;
00284 
00285 // Build a complete set of effective validity records from the database.
00286   DbiValidityRecBuilder builder(fDBProxy,context,task);
00287 
00288 // For extended context queries, DbiValidityRecBuilder will always 
00289 // assemble a result that has to be represented by a DbiResultAgg
00290 
00291   DbiResult* result = new DbiResultAgg(fTableName,
00292                                        fTableRow,
00293                                        fCache,
00294                                        &builder,
00295                                        &fDBProxy,
00296                                        sqlQualifiers);
00297 // Record latest entries from Global Exception Log.
00298   result->CaptureExceptionLog(startGEL);
00299 
00300   fCache->Adopt(result);
00301   return result;
00302 
00303 }

const DbiResult * DbiTableProxy::Query ( const VldContext vc,
const Dbi::Task task,
Bool_t  findFullTimeWindow = true 
)

Definition at line 140 of file DbiTableProxy.cxx.

References DbiCache::Adopt(), CanReadL2Cache(), DbiResult::CaptureExceptionLog(), Munits::cm, fCache, fCascader, fDBProxy, fTableName, fTableRow, DbiExceptionLog::GetGELog(), DbiValidityRecBuilder::GetL2CacheName(), DbiValidityRecBuilder::GetNumValidityRec(), DbiValidityRecBuilder::GetValidityRec(), DbiValidityRec::IsGap(), Msg::kInfo, MSG, DbiValidityRecBuilder::NonAggregated(), RestoreFromL2Cache(), SaveToL2Cache(), DbiCache::Search(), and DbiExceptionLog::Size().

Referenced by DbiResultPtr< T >::NewQuery(), and Query().

00142                                                                  {
00143 //
00144 //
00145 //  Purpose:  Apply context specific query to database table and return result.
00146 //
00147 //  Arguments: 
00148 //    vc           in    The Validity Context for the query.
00149 //    task         in    The task of the query.
00150 //    findFullTimeWindow
00151 //                 in    Attempt to find full validity of query 
00152 //                        i.e. beyond Dbi::GetTimeGate
00153 //
00154 //  Return:    Query result (never zero even if query fails).
00155 //
00156 //  Contact:   N. West
00157 //
00158 //  Specification:-
00159 //  =============
00160 //
00161 //  o Apply query to database table and return result.
00162 
00163 //  Program Notes:-
00164 //  =============
00165 
00166 //  None.
00167 
00168 //  See if there is one already in the cache for universal aggregate no.
00169 
00170   if ( const DbiResult* result = fCache->Search(vc,task) 
00171      ) return result;
00172 
00173   DbiConnectionMaintainer cm(fCascader);  //Stack object to hold connections
00174 
00175 // Make Global Exception Log bookmark
00176   UInt_t startGEL = DbiExceptionLog::GetGELog().Size()+1;
00177 
00178 // Build a complete set of effective validity record from the database.
00179   DbiValidityRecBuilder builder(fDBProxy,vc,task,-1,findFullTimeWindow);
00180 
00181 // Deal with non-aggregated data.
00182 
00183   if ( builder.NonAggregated() ) {
00184 
00185     DbiValidityRec effVRec = builder.GetValidityRec(0);
00186 //  Force off const - we haven't finished with DbiResult yet!
00187     DbiResult* result = const_cast<DbiResult*>(Query(effVRec));
00188 //  Record latest entries from Global Exception Log.
00189     result->CaptureExceptionLog(startGEL);
00190     return result;
00191   }
00192 
00193 // Deal with aggregated data.
00194 
00195 // Don't look in the level 2 cache if more than half of the 
00196 // component aggregates are already in the cache;
00197 // for in this case, the chances are that we have just 
00198 // crossed a validity boundary in only a few aggregates and 
00199 // we don't want to waste time loading in a full set only to throw
00200 // it away again.
00201 
00202   if ( this->CanReadL2Cache() ) {
00203     UInt_t numPresent  = 0;
00204     UInt_t numRequired = 0;
00205     Int_t maxRow = builder.GetNumValidityRec() - 1;
00206     for ( Int_t rowNo = 1; rowNo <= maxRow; ++rowNo ) {
00207       const DbiValidityRec& vrec = builder.GetValidityRec(rowNo);
00208       if ( fCache->Search(vrec) ) ++numPresent;
00209       else if ( ! vrec.IsGap() ) ++numRequired;
00210     }
00211     if ( numRequired < numPresent ) MSG("Dbi",Msg::kInfo) 
00212       << "Skipping search of L2 cache; already have "
00213       << numPresent << " aggregates, and only require a further "
00214       << numRequired << endl;
00215     else this->RestoreFromL2Cache(builder);
00216   }
00217 
00218   DbiResult* result = new DbiResultAgg(fTableName,
00219                                        fTableRow,
00220                                        fCache,
00221                                        &builder,
00222                                        &fDBProxy);
00223 // Record latest entries from Global Exception Log.
00224   result->CaptureExceptionLog(startGEL);
00225 
00226   fCache->Adopt(result);
00227   this->SaveToL2Cache(builder.GetL2CacheName(),*result);
00228   return result;
00229 
00230 }

VldTimeStamp DbiTableProxy::QueryOverlayCreationDate ( const DbiValidityRec vrec,
UInt_t  dbNo 
)

Definition at line 446 of file DbiTableProxy.cxx.

References Munits::cm, fCascader, fDBProxy, DbiValidityRec::GetAggregateNo(), DbiValidityRec::GetTask(), DbiValidityRec::GetVldRange(), Msg::kDebug, and MSG.

Referenced by DbiWriter< T >::Close().

00448 {
00449 //
00450 //  Purpose:  Determine a suitable Creation Date so that this validity
00451 //            record, if written to the selected DB, will overlay
00452 //            correctly.
00453 //
00454 //  Specification:-
00455 //  =============
00456 //
00457 //  o Determine optimal Creation Date to overlay new data.  See Program Notes.
00458 
00459 //  Program Notes:-
00460 //  =============
00461 
00462 
00463 // It is normal practice, particularly for calibration data, to have
00464 // overlapping the validity records.  Each time a new set of runs are
00465 // processed the start time of the validity is set to the start time of
00466 // the first run and the end time is set beyond the start time by an
00467 // interval that characterises the stability of the constants.  So long
00468 // as a new set of constants is created before the end time is reached
00469 // there will be no gap.  Where there is an overlap the Creation Date is
00470 // used to select the later constants on the basis that later is better.
00471 // However, if reprocessing old data it is also normal practice to
00472 // process recent data first and in this case the constants for earlier
00473 // data get later creation dates and overlay works the wrong way.  To
00474 // solve this, the creation date is faked as follows:-
00475 //
00476 //
00477 //   1.  For new data i.e. data that does not overlay any existing data,
00478 //       the creation date is set to the validity start time.
00479 //
00480 //   2.  For replacement data i.e. data that does overlay existing data,
00481 //       the creation date is set to be one minute greater than the Creation
00482 //       Date on the current best data.
00483 //
00484 // This scheme ensures that new data will overlay existing data at the 
00485 // start of its validity but will be itself overlaid by data that has 
00486 // a later start time (assuming validity record start times are more 
00487 // than a few minutes apart)
00488 
00489 
00490   //  Create a context that corresponds to the start time of the validity
00491   //  range.  Note that it is O.K. to use SimFlag and Detector masks 
00492   //  even though this could make the context ambiguous because the 
00493   //  context is only to be used to query the database and the SimFlag and 
00494   //  Detector values will be ORed against existing data so will match
00495   //  all possible data that this validity range could overlay which is
00496   //  just what we want.
00497 
00498   const VldRange& vr(vrec.GetVldRange());
00499   VldContext vc((Detector::Detector_t) vr.GetDetectorMask(),
00500                   (SimFlag::SimFlag_t) vr.GetSimMask(),
00501                                        vr.GetTimeStart());
00502 
00503   DbiConnectionMaintainer cm(fCascader);  //Stack object to hold connections
00504 
00505   // Build a complete set of effective validity records from the 
00506   // selected database.
00507   DbiValidityRecBuilder builder(fDBProxy,vc,vrec.GetTask(),dbNo);
00508 
00509   // Pick up the validity record for the current aggregate.
00510   const DbiValidityRec& vrecOvlay(builder.GetValidityRecFromAggNo(vrec.GetAggregateNo()));
00511 
00512   // If its a gap i.e. nothing is overlayed, return the start time, otherwise
00513   // return its Creation Date plus one minute.
00514   VldTimeStamp ovlayTS(vr.GetTimeStart());
00515   if ( ! vrecOvlay.IsGap() ) {
00516     time_t overlaySecs = vrecOvlay.GetCreationDate().GetSec();
00517     ovlayTS = VldTimeStamp(overlaySecs + 60,0);
00518   }
00519 
00520   MSG("Dbi",Msg::kDebug) << "Looking for overlay creation date for: " 
00521                    << vrec << "found it would overlap: "
00522                    << vrecOvlay << " so overlay creation date set to "
00523                    << ovlayTS.AsString("s") << endl;
00524   return ovlayTS;                                          
00525 
00526 }

void DbiTableProxy::RefreshMetaData (  ) 

Definition at line 434 of file DbiTableProxy.cxx.

References fDBProxy, fMetaData, fMetaValid, and DbiDBProxy::StoreMetaData().

Referenced by DbiTableProxyRegistry::RefreshMetaData().

00434                                     {
00435 //
00436 //
00437 //  Purpose:  Refresh meta data for table.
00438 //
00439 
00440   fDBProxy.StoreMetaData(fMetaData);
00441   fDBProxy.StoreMetaData(fMetaValid);
00442 
00443 }

Bool_t DbiTableProxy::RestoreFromL2Cache ( const DbiValidityRecBuilder builder  )  [private]

Definition at line 529 of file DbiTableProxy.cxx.

References DbiCache::Adopt(), CanReadL2Cache(), fCache, DbiValidityRecBuilder::GetL2CacheName(), GetRowName(), DbiValidityRec::GetSeqNo(), GetTableName(), DbiResult::GetValidityRec(), DbiValidityRecBuilder::GetValidityRecFromSeqNo(), DbiTimerManager::gTimerManager, Msg::kDebug, Msg::kInfo, Msg::kWarning, MSG, DbiTimerManager::RecMainQuery(), and DbiCache::Search().

Referenced by Query().

00529                                                                              {
00530 //
00531 //
00532 //  Purpose: Restore results from named level 2 disk cache into memory cache. 
00533 //  Returns true if anything restored
00534 
00535 //  Specification:-
00536 //  =============
00537 //
00538 //  o Restore to cache but only if enabled and exists.
00539 
00540   const string name(builder.GetL2CacheName());
00541   MSG("Dbi",Msg::kDebug) << "Request to restore query result  " << name 
00542                          << endl;
00543   if ( ! this->CanReadL2Cache() ) return kFALSE;
00544   string cacheFileName;
00545   if (  name != "" 
00546    ) cacheFileName =  this->GetTableName() + "_" 
00547                     + this->GetRowName() + "_" 
00548                     +  name + ".dbi_cache";
00549   DbiBinaryFile bf(cacheFileName.c_str());
00550   if ( ! bf.IsOK() ) {
00551     MSG("Dbi",Msg::kDebug) << "Caching disabled or cannot open " 
00552                            << bf.GetFileName() << endl;
00553     return kFALSE;
00554   }
00555 
00556   static bool warnOnce = true;
00557   if ( warnOnce ) {
00558     MSG("Dbi",Msg::kWarning) << "\n\n\n"
00559      << " WARNING:  Reading from the Level 2 cache has been activated.\n"
00560      << " *******   This should only be used for development and never for production !!!\n\n\n";
00561     warnOnce = false;
00562   }
00563 
00564   MSG("Dbi",Msg::kInfo) << "Restoring query result from " << bf.GetFileName() << endl;
00565   DbiTimerManager::gTimerManager.RecMainQuery();
00566 
00567   DbiResult* result    = 0;
00568   unsigned numRowsRest = 0;
00569   unsigned numRowsIgn  = 0;
00570   UInt_t numNonAgg     = 0;
00571   bf >> numNonAgg;  
00572 
00573   while ( numNonAgg-- ) {
00574     if ( ! bf.IsOK() ) break;
00575     if ( ! result ) result = new DbiResultNonAgg;
00576     bf >> *result;
00577 
00578 //  The original query may have had a validity range truncated by
00579 //  the time window, so replace its DbiValidityRec with the one
00580 //  just obtained from the database.
00581     const DbiValidityRec& vrec = result->GetValidityRec();
00582     UInt_t seqNo = vrec.GetSeqNo();
00583     MSG("Dbi",Msg::kDebug) << "Fix up L2 cache DbiValidityRec, by replacing: " << vrec 
00584                            << "    with: " << builder.GetValidityRecFromSeqNo(seqNo) << endl;
00585 //  Sneaky end-run round const to fix-up DbiValidityRec.
00586     (const_cast<DbiValidityRec&>(vrec)) = builder.GetValidityRecFromSeqNo(seqNo);
00587 
00588 //  Adopt only if not already in memory cache.
00589     if ( ! fCache->Search(vrec) ) {
00590       numRowsRest += result->GetNumRows();
00591       fCache->Adopt(result);
00592       result = 0;
00593     }
00594     else numRowsIgn += result->GetNumRows();
00595   }
00596   MSG("Dbi",Msg::kInfo) << "   a total of " << numRowsRest << " were restored ("
00597                         << numRowsIgn << " ignored - already in memory)" << endl;
00598 
00599   delete result;
00600   result = 0;
00601 
00602   return numRowsRest > 0;
00603 
00604 }

Bool_t DbiTableProxy::SaveToL2Cache ( const string &  name,
DbiResult res 
) [private]

Definition at line 607 of file DbiTableProxy.cxx.

References DbiResult::CanSave(), CanWriteL2Cache(), DbiResult::GetNumRows(), GetRowName(), GetTableName(), DbiTimerManager::gTimerManager, Msg::kDebug, Msg::kInfo, MSG, DbiTimerManager::RecMainQuery(), and DbiResult::ResultsFromDb().

Referenced by Query().

00607                                                                       {
00608 //
00609 //
00610 //  Purpose: Save result to named level 2 cache. Returns true if saved.
00611 
00612 //  Specification:-
00613 //  =============
00614 //
00615 //  o Save to cache but only if enabled and suitable.
00616 
00617   MSG("Dbi",Msg::kDebug) << "Request to save query result as " << name 
00618                          << " data from DB? " << res.ResultsFromDb()
00619                          << " can be saved? " << res.CanSave() << endl;
00620   if ( ! this->CanWriteL2Cache() || ! res.ResultsFromDb() || ! res.CanSave() ) return kFALSE;
00621 
00622   string cacheFileName;
00623   if (  name != "" 
00624    ) cacheFileName =  this->GetTableName() + "_" 
00625                     + this->GetRowName() + "_" 
00626                     +  name + ".dbi_cache";
00627   DbiBinaryFile bf(cacheFileName.c_str(),kFALSE);
00628   if ( bf.IsOK() ) {
00629     MSG("Dbi",Msg::kInfo) << "Saving query result (" << res.GetNumRows()
00630                           << " rows) to " << bf.GetFileName() << endl;
00631      DbiTimerManager::gTimerManager.RecMainQuery();
00632 
00633     // if writing a DbiResultNonAgg, add leading count of 1. (if writing
00634     // a DbiResultAgg it will writes its one leading count.
00635     if ( dynamic_cast<DbiResultNonAgg*>(&res) ) {
00636       UInt_t numNonAgg = 1;
00637       bf << numNonAgg;
00638     }
00639     bf << res;
00640     return kTRUE;
00641   }
00642   MSG("Dbi",Msg::kDebug) << "Caching disabled or cannot open " 
00643                          << bf.GetFileName() << endl;
00644   return kFALSE;
00645 
00646 }

void DbiTableProxy::SetSqlCondition ( const string &  sql  ) 

Definition at line 649 of file DbiTableProxy.cxx.

References fDBProxy, and DbiDBProxy::SetSqlCondition().

Referenced by DbiTableProxyRegistry::ApplySqlCondition().

00649                                                      {
00650 //
00651 //
00652 //  Purpose:  Apply Sql condition to its DbiDBProxy.
00653 //
00654 //  Arguments: 
00655 //   sql           in    SQL condition string (excluding where).
00656 //
00657 //  Return:  n/a  
00658 //
00659 //  Contact:   N. West
00660 //
00661 //  Specification:-
00662 //  =============
00663 //
00664 //  o Apply Sql condition to its DbiDBProxy.
00665 
00666 //  Program Notes:-
00667 //  =============
00668 
00669 //  None.
00670 
00671   fDBProxy.SetSqlCondition(sql);
00672 
00673 }

Bool_t DbiTableProxy::TableExists (  )  const [inline]

Definition at line 75 of file DbiTableProxy.h.

References fExists.

Referenced by DbiResultPtr< T >::ApplyAbortTest().

00075 { return fExists; }


Friends And Related Function Documentation

friend class DbiTableProxyRegistry [friend]

Definition at line 47 of file DbiTableProxy.h.


Member Data Documentation

Associated cache for result.

Definition at line 121 of file DbiTableProxy.h.

Referenced by GetCache(), Query(), RestoreFromL2Cache(), and ~DbiTableProxy().

Bool_t DbiTableProxy::fCanL2Cache [private]

True if row supports L2 cache.

Definition at line 118 of file DbiTableProxy.h.

Referenced by CanReadL2Cache(), and CanWriteL2Cache().

Pointer to one and only cascader.

Definition at line 109 of file DbiTableProxy.h.

Referenced by GetCascader(), Query(), and QueryOverlayCreationDate().

Proxy to database.

Definition at line 124 of file DbiTableProxy.h.

Referenced by GetDBProxy(), Query(), QueryOverlayCreationDate(), RefreshMetaData(), and SetSqlCondition().

Bool_t DbiTableProxy::fExists [private]

true if table exists;

Definition at line 127 of file DbiTableProxy.h.

Referenced by TableExists().

Meta data for main(data) table.

Definition at line 112 of file DbiTableProxy.h.

Referenced by GetMetaData(), and RefreshMetaData().

Meta data for aux. (validity)table.

Definition at line 115 of file DbiTableProxy.h.

Referenced by GetMetaValid(), and RefreshMetaData().

string DbiTableProxy::fTableName [private]

Table Name.

Definition at line 130 of file DbiTableProxy.h.

Referenced by GetTableName(), Query(), and ~DbiTableProxy().

Pet object used to create new rows.

Definition at line 133 of file DbiTableProxy.h.

Referenced by GetRowName(), Query(), and ~DbiTableProxy().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1