Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbBdbWCondition.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbBdbWCondition.cc,v 1.33 2005/09/15 05:07:31 gapon Exp $
00003 
00004 /// The implementation of the CdbBdbWCondition class.
00005 /**
00006   * @see CdbBdbWCondition
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #include "CdbBdbWrapper/CdbBdbWCondition.hh"
00012 
00013 #include "CdbBase/Cdb.hh"
00014 #include "CdbBase/CdbDatabase.hh"
00015 #include "CdbBase/CdbView.hh"
00016 #include "CdbBase/CdbFolder.hh"
00017 #include "CdbBase/CdbRevisionPolicy.hh"
00018 #include "CdbBase/CdbObject.hh"
00019 #include "CdbBase/CdbObjectItr.hh"
00020 #include "CdbBase/CdbObjectFactoryBase.hh"
00021 #include "CdbBase/CdbId.hh"
00022 #include "CdbBase/CdbCompositeName.hh"
00023 #include "CdbBase/CdbDebugStream.hh"
00024 
00025 #include "CdbBdb/CdbBdbObjectCreator.hh"
00026 #include "CdbBdb/CdbBdbObjectConvertor.hh"
00027 
00028 #include "CdbBdbWrapper/CdbBdbWRevision.hh"
00029 #include "CdbBdbWrapper/CdbBdbWRevisionIdItr.hh"
00030 #include "CdbBdbWrapper/CdbBdbWRevisionNameItr.hh"
00031 
00032 #include "BdbTime/BdbTime.hh"
00033 #include "BdbTime/BdbIntervalBase.hh"
00034 
00035 #include "BdbCond/BdbObject.hh"
00036 #include "BdbCond/BdbObsoleteDatabase.hh"
00037 #include "BdbCond/BdbCondRegistry.hh"
00038 #include "BdbCond/BdbCondRevision.hh"
00039 #include "BdbCond/BdbIntervalItr.hh"
00040 
00041 #include "ErrLogger/ErrLog.hh"
00042 
00043 #include <stdio.h>
00044 using std::endl;
00045 
00046 namespace {
00047 
00048     /////////////////////////////
00049     // Class: CdbBdbWObjectItr //
00050     /////////////////////////////
00051 
00052     class CdbBdbWObjectItr : public CdbObjectItr::InterfaceType {
00053  
00054     private:
00055  
00056       /// The default constructor (NOT IMPLEMENTED)
00057       /**
00058         * Is disabled...
00059         */
00060         CdbBdbWObjectItr( );
00061  
00062     public:
00063  
00064       /// The normal constructor
00065       /**
00066         * More details...
00067         */
00068         CdbBdbWObjectItr( const CdbConditionPtr& theParentPtr,          /**< a smart pointer onto the parent condition */
00069                           const BdbIntervalItr&  theInputItr,           /**< the source of information about objects */
00070                           const BdbTime&         theEndValidityTime     /**< a point beyond which we should stop iteration */
00071                         );
00072  
00073       /// The copy constructor
00074       /** 
00075         * More details to come...
00076         */ 
00077         CdbBdbWObjectItr( const CdbBdbWObjectItr& theItr );
00078  
00079       /// The assignment operator
00080       /** 
00081         * More details to come...
00082         */ 
00083         CdbBdbWObjectItr& operator=( const CdbBdbWObjectItr& theItr );
00084  
00085       /// The destructor
00086       /** 
00087         * Details...
00088         */ 
00089         virtual ~CdbBdbWObjectItr( );
00090  
00091       /// Reset an iterator to its initial state.
00092       /** 
00093         * This implements the corresponding method of the base class.
00094         * 
00095         * @see CdbIItr::reset
00096         * @see CdbStatus
00097         */ 
00098         virtual CdbStatus reset( );
00099  
00100       /// Advance an iterator to the next position.
00101       /** 
00102         * This implements the corresponding method of the base class.
00103         * 
00104         * @see CdbIItr::next()
00105         */ 
00106         virtual bool next( );
00107  
00108       /// Obtain the currently reffered value.
00109       /** 
00110         * This implements the corresponding method of the base class.
00111         * 
00112         * @see CdbIItr::value()
00113         * 
00114         * @return the current value the iterator is set on
00115         */ 
00116         virtual CdbObjectPtr value( );
00117 
00118       /// Check if an iterator is valid.
00119       /** 
00120         * This implements the corresponding method of the base class.
00121         * 
00122         * @see CdbIItr::isValid()
00123         */ 
00124         virtual bool isValid( );
00125  
00126       /// Make a clone of itself
00127       /** 
00128         * @see CdbIItr::clone()
00129         */ 
00130         virtual InterfaceType* clone( ) const;
00131  
00132     private: 
00133  
00134       /// Set up current context from specified source
00135       /** 
00136         * More details...
00137         */ 
00138         void setUpSelf( const CdbBdbWObjectItr& theItr );
00139  
00140       /// Try to advance the iterator to the next position
00141       /** 
00142         * Return "true" if successful.
00143         */ 
00144         bool tryNext( );
00145  
00146     private: 
00147  
00148         bool _isValid;
00149         bool _hasEverBeenAdvanced;
00150  
00151         CdbConditionPtr _myParentPtr;
00152         BdbIntervalItr  _itr;
00153         BdbTime         _endTime;
00154  
00155         CdbObjectPtr _objectPtr;
00156     };
00157 
00158     CdbBdbWObjectItr::CdbBdbWObjectItr( const CdbConditionPtr& theParentPtr,
00159                                         const BdbIntervalItr&  theInputItr,
00160                                         const BdbTime&         theEndValidityTime ) :
00161         _isValid            (false),
00162         _hasEverBeenAdvanced(false),
00163         _myParentPtr        (theParentPtr),
00164         _itr                (theInputItr),
00165         _endTime            (theEndValidityTime),
00166         _objectPtr          (0)
00167     {
00168         if( theParentPtr.isNull( ))
00169             ErrMsg(fatal) << "a null pointer instead f a parent object passed into the constructor." << endmsg;
00170     }
00171  
00172     CdbBdbWObjectItr::CdbBdbWObjectItr( const CdbBdbWObjectItr& theItr ) :
00173         _isValid            (theItr._isValid),
00174         _hasEverBeenAdvanced(theItr._hasEverBeenAdvanced),
00175         _myParentPtr        (theItr._myParentPtr),
00176         _itr                (theItr._itr),
00177         _endTime            (theItr._endTime),
00178         _objectPtr          (theItr._objectPtr)
00179     { }
00180  
00181     CdbBdbWObjectItr::~CdbBdbWObjectItr( )
00182     { }
00183 
00184     CdbBdbWObjectItr&
00185     CdbBdbWObjectItr::operator=( const CdbBdbWObjectItr& theItr )
00186     { 
00187         if( this != &theItr ) {
00188             _isValid             = theItr._isValid;
00189             _hasEverBeenAdvanced = theItr._hasEverBeenAdvanced;
00190             _myParentPtr         = theItr._myParentPtr;
00191             _itr                 = theItr._itr;
00192             _endTime             = theItr._endTime;
00193             _objectPtr           = theItr._objectPtr;
00194         } 
00195         return *this;
00196     } 
00197  
00198     CdbStatus 
00199     CdbBdbWObjectItr::reset( )
00200     { 
00201         _isValid             = false;
00202         _hasEverBeenAdvanced = false;
00203  
00204         _objectPtr = 0;
00205  
00206         _itr.reset( );
00207  
00208         return CdbStatus::Success;
00209     }
00210 
00211     bool 
00212     CdbBdbWObjectItr::tryNext( )
00213     { 
00214         bool result = _itr.next( );
00215         if( result ) {
00216  
00217           // Get to the current handle
00218  
00219             BdbHandle(BdbIntervalR) intervalH;
00220             intervalH = _itr;
00221  
00222           // Initialize a generic object
00223  
00224             CdbStatus status = CdbBdbObjectCreator::object( _objectPtr,
00225                                                             _myParentPtr,
00226                                                             intervalH->beginTime( ),        // begin of the 'original' interval
00227                                                             intervalH->endTime( ),          // end   of the 'original' interval
00228                                                             intervalH->beginTime( ),
00229                                                             intervalH->endTime( ),
00230                                                             intervalH->getVersionTime( ),   // begin of 'duration' interval
00231                                                             BdbTime::plusInfinity,          // end   of 'duration' interval
00232                                                             intervalH->getVersionTime( ),
00233                                                             intervalH->getObject( ));
00234             result = ( CdbStatus::Success == status );
00235         } 
00236         if( !result ) {
00237             _objectPtr = 0;
00238         } 
00239         return result;
00240     }
00241 
00242     bool 
00243     CdbBdbWObjectItr::next( )
00244     { 
00245         if( _hasEverBeenAdvanced ) {
00246             if( _isValid ) {
00247  
00248               // Proceed only if the end time of the current object is not beyond the limit
00249               // passed to the constructor of the current class.
00250  
00251                 if( _objectPtr->end( ) >= _endTime ) {
00252  
00253                     _objectPtr = 0;
00254  
00255                     _isValid = false;
00256  
00257                 } else {
00258                     _isValid = tryNext( );
00259                 }
00260  
00261             } else {
00262                 ;       // leave iterator past the end of the collection
00263             } 
00264  
00265         } else { 
00266             _hasEverBeenAdvanced = true;
00267             _isValid             = tryNext( );
00268         } 
00269         return _isValid;
00270     }
00271 
00272     CdbObjectPtr
00273     CdbBdbWObjectItr::value( )
00274     { 
00275         return _objectPtr;
00276     } 
00277  
00278     bool 
00279     CdbBdbWObjectItr::isValid( )
00280     { 
00281         return _isValid;
00282     } 
00283  
00284     CdbBdbWObjectItr::InterfaceType*
00285     CdbBdbWObjectItr::clone( ) const
00286     { 
00287         return new CdbBdbWObjectItr( *this );
00288     }
00289 };
00290 
00291 /////////////////////////////
00292 // Class: CdbBdbWCondition //
00293 /////////////////////////////
00294 
00295 CdbCondition*
00296 CdbBdbWCondition::clone( ) const
00297 {
00298     CdbBdbWCondition* mySelf = const_cast<CdbBdbWCondition*>( this );
00299     return new CdbBdbWCondition( mySelf->parent( ),
00300                                  mySelf->parentDatabase( ),
00301                                  mySelf->name( ));
00302 }
00303 
00304 std::string
00305 CdbBdbWCondition::description( ) const
00306 {
00307     return std::string( "<not available in this implementation>" );
00308 }
00309 
00310 bool
00311 CdbBdbWCondition::isPartitionable( ) const
00312 {
00313     return false;
00314 }
00315 
00316 CdbCompositeName
00317 CdbBdbWCondition::physicalName( ) const
00318 {
00319     return CdbCompositeName( "<local>", name( ));
00320 }
00321 
00322 CdbId
00323 CdbBdbWCondition::physicalId( ) const
00324 {
00325     return CdbId( 0, 0 );
00326 }
00327 
00328 BdbTime
00329 CdbBdbWCondition::created( ) const
00330 {
00331     return BdbTime::minusInfinity;
00332 }
00333 
00334 BdbTime
00335 CdbBdbWCondition::registered( ) const
00336 {
00337     return BdbTime::minusInfinity;
00338 }
00339 
00340 BdbTime
00341 CdbBdbWCondition::modified( ) const
00342 {
00343     return BdbTime::minusInfinity;
00344 }
00345 
00346 CdbStatus
00347 CdbBdbWCondition::findObject( CdbObjectPtr&  theObjectPtr,
00348                               const BdbTime& theValidityTime,
00349                               const BdbTime& theInsertionTime )
00350 {
00351 /******************************************************************
00352  *
00353  * IMPLEMENTATION NOTES:
00354  *
00355  * - THIS METHOD IGNORSE THE INSERTION TIME PASSED AS THE PARAMETER
00356  * - IT RELIES ON THE CURRENT REVISION PATH CONFIGURATION
00357  *
00358  ******************************************************************
00359  */
00360     CdbStatus result = CdbStatus::Error;
00361 
00362     theObjectPtr = 0;
00363 
00364     do {
00365 
00366       // Find the corresponding object and its parameters in the database.
00367       //
00368       // NOTE: We always rely on the revision configuration in
00369       //        the BdbCondRevisionPath.
00370 
00371         BdbObsoleteDatabase            db( parent( )->name( ));
00372         BdbHandle(BdbInterval) intervalH;
00373         BdbHandle(BdbObject)   objectH;
00374         BdbIntervalBase        bdbTransientInterval;
00375         BdbTime                bdbInsertionTime( 0 );
00376 
00377         CDB_DEBUG_STREAM << "CDB_FETCH_: detector=" << parent( )->name( ) << " container=" << name( ) << " fetch_time=" << theValidityTime << endl;
00378 
00379         BdbStatus bdbStatus = db.fetch( objectH,
00380                                         bdbTransientInterval,
00381                                         bdbInsertionTime,
00382                                         name( ),
00383                                         theValidityTime );
00384         if( BdbcSuccess != bdbStatus ) break;
00385 
00386       // Create a transient object through the creator factory.
00387       //
00388       // DESIGN NOTE: We need to construct a smart pointer against a clone since
00389       //              we don't know a smart pointer pointing to the current
00390       //              instance, therefore we can't guarantee the lifetime
00391       //              of the current instance.
00392 
00393         CdbConditionPtr myPtr( this->clone( ));
00394         result = CdbBdbObjectCreator::object( theObjectPtr,
00395                                               myPtr,
00396                                               bdbTransientInterval.beginTime( ),    // begin of the 'duration' interval
00397                                               bdbTransientInterval.endTime( ),      // end   of the 'duration' interval
00398                                               bdbTransientInterval.beginTime( ),
00399                                               bdbTransientInterval.endTime( ),
00400                                               bdbInsertionTime,         // begin of the 'duration' interval
00401                                               BdbTime::plusInfinity,    // end   of the 'duration' interval
00402                                               bdbInsertionTime,
00403                                               objectH );
00404 
00405     } while( false );
00406 
00407     return result;
00408 }
00409 
00410 CdbStatus
00411 CdbBdbWCondition::findObject( CdbObjectPtr&            theObjectPtr,
00412                               const CdbRevisionPolicy& thePolicy,
00413                               const BdbTime&           theValidityTime,
00414                               const BdbTime&           theInsertionTime )
00415 {
00416     return findObject( theObjectPtr,
00417                        theValidityTime,
00418                        theInsertionTime );
00419 }
00420 
00421 CdbStatus
00422 CdbBdbWCondition::objectIterator( CdbObjectItr&  theItr,
00423                                   const BdbTime& theBeginValidity,
00424                                   const BdbTime& theEndValidity )
00425 { 
00426     CdbStatus result = CdbStatus::Error;
00427  
00428     do {
00429  
00430         const char* detectorName  = parent( )->name( );
00431         const char* conditionName = name( );
00432  
00433       // Verify parameters to make sure that at least one point of the validity
00434       // timeline is in the specified interval.
00435  
00436         if( theBeginValidity > theEndValidity ) {
00437 
00438             ErrMsg(error) << "illegal validity range for the iterator:" << endl
00439                           << "    DETECTOR   : \"" << detectorName << "\"" << endl
00440                           << "    CONDITION  : \"" << conditionName << "\"" << endl
00441                           << "    BEGIN TIME : "   << theBeginValidity << endl
00442                           << "    END   TIME : "   << theEndValidity << endmsg;
00443             break;
00444         }
00445  
00446       // Find out the revision information
00447  
00448         bool    useTopVersionFlag = true;
00449         d_ULong revisionId        = BdbCondRevision::BASELINE;
00450  
00451         if( BdbcSuccess != BdbCondPath::instance( )->getRevision( detectorName,
00452                                                                   conditionName,
00453                                                                   useTopVersionFlag,
00454                                                                   revisionId )) {
00455 
00456             ErrMsg(error) << "failed to obtain the revision configuration for:" << endl
00457                           << "    DETECTOR  : \"" << detectorName << "\"" << endl
00458                           << "    CONDITION : \"" << conditionName << "\"" << endmsg;
00459             break;
00460         }
00461 
00462       // Set up the iterator
00463  
00464         BdbIntervalItr itr;
00465         bool           itrWasSetup = false;
00466  
00467         if( useTopVersionFlag ) {
00468  
00469             itrWasSetup = itr.setTopmost( detectorName,
00470                                           conditionName,
00471                                           theBeginValidity );
00472         } else {
00473  
00474             if( BdbCondRevision::BASELINE == revisionId ) {
00475  
00476                 itrWasSetup = itr.setBaseline( detectorName,
00477                                                conditionName,
00478                                                theBeginValidity );
00479             } else {
00480  
00481                 itrWasSetup = itr.setRevision( detectorName,
00482                                                conditionName,
00483                                                revisionId,
00484                                                theBeginValidity );
00485             }
00486         } 
00487         if( !itrWasSetup ) {
00488             ErrMsg(error) << "failed to set up the iterator for:" << endl
00489                           << "    DETECTOR   : \"" << detectorName << "\"" << endl
00490                           << "    CONDITION  : \"" << conditionName << "\"" << endl
00491                           << "    BEGIN TIME : "   << theBeginValidity << endmsg;
00492             break;
00493         }
00494 
00495       // ATTENTION: This is not a memory leak - the created object
00496       //            will be destroyed by the iterator.
00497  
00498         CdbConditionPtr myPtr( this->clone( ));
00499         theItr = CdbObjectItr( new CdbBdbWObjectItr( myPtr,
00500                                                      itr,
00501                                                      theEndValidity ));
00502  
00503       // Done.
00504  
00505         result = CdbStatus::Success;
00506  
00507     } while( false );
00508  
00509     return result;
00510 }
00511 
00512 CdbStatus
00513 CdbBdbWCondition::objectIterator( CdbObjectItr&            theItr,
00514                                   const CdbRevisionPolicy& thePolicy,
00515                                   const BdbTime&           theBeginValidity,
00516                                   const BdbTime&           theEndValidity )
00517 {
00518     return objectIterator( theItr,
00519                            theBeginValidity,
00520                            theEndValidity );
00521 }
00522 
00523 CdbStatus
00524 CdbBdbWCondition::originalObjectIterator( CdbObjectItr&        theItr,
00525                                           const BdbTime&       theBeginInsertion,
00526                                           const BdbTime&       theEndInsertion,
00527                                           const unsigned short thePartitionId )
00528 {
00529     return CdbStatus::NotImplemented;
00530 }
00531 
00532 CdbStatus
00533 CdbBdbWCondition::storeObject( CdbObjectFactoryBase& theObjectFactory,
00534                                const BdbTime&        theBegin,
00535                                const BdbTime&        theEnd,
00536                                CdbObjectPtr&         theObjectPtr )
00537 {
00538     CdbStatus result = CdbStatus::Error;
00539 
00540     theObjectPtr = 0;
00541 
00542     do {
00543 
00544       // Invoke the object creator first.
00545 
00546         CdbConditionPtr myPtr( this->clone( ));
00547 
00548         if( CdbStatus::Success != theObjectFactory.create( theObjectPtr, myPtr, theBegin, theEnd )) break;
00549         if( theObjectPtr.isNull( )) break;
00550 
00551       // Get object handle
00552 
00553         BdbHandle(BdbObject) objectH;
00554 
00555         if( CdbStatus::Success != CdbBdbObjectConvertor::narrow( objectH, theObjectPtr )) break;
00556         if( BdbIsNull(objectH)) break;
00557 
00558       // Store the persistent object in the database.
00559 
00560         BdbObsoleteDatabase db( parent( )->name( ));
00561 
00562         if( BdbcSuccess != db.store( objectH, name( ), theBegin, theEnd )) break;
00563 
00564       // Done
00565 
00566         result = CdbStatus::Success;
00567 
00568     } while( false );
00569 
00570     return result;
00571 }
00572 
00573 CdbStatus
00574 CdbBdbWCondition::storeAndTruncateObject( CdbObjectFactoryBase& theObjectFactory,
00575                                           const BdbTime&        theStoreTime,
00576                                           const BdbTime&        theTruncateTime,
00577                                           CdbObjectPtr&         theObjectPtr )
00578 {
00579     CdbStatus result = CdbStatus::Error;
00580 
00581     theObjectPtr = 0;
00582 
00583     do {
00584 
00585       // Invoke the object creator first.
00586       //
00587       // NOTE: We're passing +Infinity instead of the "truncate" time because
00588       //       the newely created object can (if applied to teh LastInterval) be valid
00589       //       to +Infinity.
00590 
00591         CdbConditionPtr myPtr( this->clone( ));
00592 
00593         if( CdbStatus::Success != theObjectFactory.create( theObjectPtr, myPtr, theStoreTime, BdbTime::plusInfinity )) break;
00594         if( theObjectPtr.isNull( )) break;
00595 
00596       // Get object handle
00597 
00598         BdbHandle(BdbObject) objectH;
00599 
00600         if( CdbStatus::Success != CdbBdbObjectConvertor::narrow( objectH, theObjectPtr )) break;
00601         if( BdbIsNull(objectH)) break;
00602 
00603       // Store the persistent object in the database.
00604 
00605         BdbObsoleteDatabase db( parent( )->name( ));
00606 
00607         if( BdbcSuccess != db.storeAndTruncate( objectH, name( ), theStoreTime, theTruncateTime )) break;
00608 
00609       // Done
00610 
00611         result = CdbStatus::Success;
00612 
00613     } while( false );
00614 
00615     return result;
00616 }
00617 
00618 CdbStatus
00619 CdbBdbWCondition::split( const BdbTime& theTime )
00620 {
00621     CdbStatus result = CdbStatus::Error;
00622 
00623     do {
00624 
00625         const char* detectorName  = parent( )->name( );
00626         const char* conditionName = name( );
00627 
00628       // Find the LastInterval
00629 
00630         BdbObsoleteDatabase db( detectorName );
00631 
00632         BdbStatus status;
00633         BdbHandle(BdbIntervalR) lastIntervalH;
00634 
00635         status = db.lastInterval( lastIntervalH, conditionName ); 
00636         if( BdbcSuccess != status || BdbIsNull(lastIntervalH)) {
00637 
00638             ErrMsg(error) << "failed to locate the LastInterval for:" << endl
00639                           << "    DETECTOR   : \"" << detectorName  << "\"" << endl
00640                           << "    CONDITION  : \"" << conditionName << "\"" << endmsg;
00641             break;
00642         }
00643 
00644       // Do the actual split only if the specified time falls inside the last interval,
00645       // excluding its begin and end (+Infinity).
00646 
00647         if(( lastIntervalH->beginTime( ) < theTime ) && ( theTime < lastIntervalH->endTime( ))) {
00648             if( BdbcSuccess != db.split( conditionName, theTime )) {
00649 
00650                 ErrMsg(error) << "failed to split the LastInterval for:" << endl
00651                               << "    DETECTOR   : \"" << detectorName  << "\"" << endl
00652                               << "    CONDITION  : \"" << conditionName << "\"" << endl
00653                               << "    SPLIT TIME : \"" << theTime       << "\"" << endmsg;
00654                 break;
00655             }
00656         }
00657 
00658       // Done
00659 
00660         result = CdbStatus::Success;
00661 
00662     } while( false );
00663 
00664     return result;
00665 }
00666 
00667 CdbBdbWCondition::CdbBdbWCondition( const CdbFolderPtr&   theFolderPtr,
00668                                     const CdbDatabasePtr& theDatabasePtr,
00669                                     const char*           theName ) :
00670     CdbCondition( theFolderPtr,
00671                   theDatabasePtr,
00672                   theName )
00673 { }
00674 
00675 CdbBdbWCondition::~CdbBdbWCondition( )
00676 { }
00677 
00678 bool
00679 CdbBdbWCondition::isValid( )
00680 {
00681     return true;
00682 }
00683 
00684 bool
00685 CdbBdbWCondition::isOpen( )
00686 {
00687     return true;
00688 }
00689 
00690 CdbStatus
00691 CdbBdbWCondition::open( )
00692 {
00693     return CdbStatus::Success;
00694 }
00695 
00696 CdbStatus
00697 CdbBdbWCondition::close( )
00698 {
00699     return CdbStatus::Success;
00700 }
00701 
00702 CdbStatus
00703 CdbBdbWCondition::findRevision( CdbRevisionPtr& thePtr,
00704                                 const BdbTime&  theId,
00705                                 unsigned short  thePartitionId )
00706 {
00707     CdbStatus result = CdbStatus::Error;
00708 
00709     thePtr = 0;
00710 
00711     do {
00712 
00713       // Shortcat for the "TOPMOST" revision ID.
00714 
00715         if( BdbTime::plusInfinity == theId ) {
00716 
00717           // DESIGN NOTE: We need to construct a smart pointer against a clone since
00718           //              we don't know a smart pointer pointing to the current
00719           //              instance, therefore we can't guarantee the lifetime
00720           //              of the current instance.
00721 
00722             CdbConditionPtr myPtr( this->clone( ));
00723             thePtr = new CdbBdbWRevision( myPtr,
00724                                           theId,
00725                                           "<topmost>",
00726                                           BdbTime::plusInfinity,        // creation time
00727                                           "It's TOPMOST layer",         // description
00728                                           BdbCondRevision::ILLEGAL );   // "old" revision id
00729 
00730             result = CdbStatus::Success;
00731             break;
00732         }
00733 
00734       // Real revisions require to get to the persistent store.
00735 
00736       // Get to the Registry.
00737 
00738         BdbObsoleteDatabase                db( parent( )->name( ));
00739         BdbHandle(BdbCondRegistry) registryH;
00740 
00741         BdbStatus bdbStatus = db.findRegistry( registryH,
00742                                                name( ));
00743         if(( BdbcSuccess != bdbStatus ) || BdbIsNull(registryH)) break;
00744 
00745       // Check every single persistent revision if it matches
00746       // specified parameters.
00747 
00748         BdbItr(BdbCondRevision)    revisionItr;
00749         BdbHandle(BdbCondRevision) revisionH;
00750 
00751         registryH->setRevisionItr( revisionItr );
00752         while( revisionItr.next( )) {
00753 
00754             revisionH = revisionItr;
00755 
00756             BdbTime revisionCreationTime( revisionH->creationTime( ));
00757 
00758             char revisionIdName[11];
00759             sprintf( revisionIdName, "%u", (unsigned) revisionH->id( ));
00760 
00761           // "OLD" -> "NEW" mapping rules for revisions:
00762           //
00763           //    - We treat the creation time of the "old" revisions
00764           //      as the identifiers of the "new" ones.
00765           //
00766           //    - We also use the textual representation of the "old"
00767           //      revisions as the names of "new" revisions.
00768 
00769             if( theId == revisionCreationTime ) {
00770 
00771               // DESIGN NOTE: We need to construct a smart pointer against a clone since
00772               //              we don't know a smart pointer pointing to the current
00773               //              instance, therefore we can't guarantee the lifetime
00774               //              of the current instance.
00775 
00776                 CdbConditionPtr myPtr( this->clone( ));
00777                 thePtr = new CdbBdbWRevision( myPtr,
00778                                               theId,
00779                                               revisionIdName,
00780                                               revisionH->creationTime( ),
00781                                               revisionH->description( ),
00782                                               revisionH->id( ));
00783 
00784                 result = CdbStatus::Success;
00785                 break;
00786             }
00787         }
00788 
00789     } while( false );
00790 
00791     return result;
00792 }
00793 
00794 CdbStatus
00795 CdbBdbWCondition::findRevision( CdbRevisionPtr& thePtr,
00796                                 const char*     theName,
00797                                 unsigned short  thePartitionId )
00798 {
00799     CdbStatus result = CdbStatus::Error;
00800 
00801     thePtr = 0;
00802 
00803     do {
00804 
00805       // Shortcat for the "TOPMOST" revision ID.
00806 
00807         if( 0 == strcmp( "<topmost>", theName )) {
00808 
00809           // DESIGN NOTE: We need to construct a smart pointer against a clone since
00810           //              we don't know a smart pointer pointing to the current
00811           //              instance, therefore we can't guarantee the lifetime
00812           //              of the current instance.
00813 
00814             CdbConditionPtr myPtr( this->clone( ));
00815             thePtr = new CdbBdbWRevision( myPtr,
00816                                           BdbTime::plusInfinity,
00817                                           theName,
00818                                           BdbTime::plusInfinity,        // creation time
00819                                           "It's TOPMOST layer",         // description
00820                                           BdbCondRevision::ILLEGAL );   // "old" revision id
00821 
00822             result = CdbStatus::Success;
00823             break;
00824         }
00825 
00826       // Real revisions require to get to the persistent store.
00827 
00828       // Get to the Registry.
00829 
00830         BdbObsoleteDatabase                db( parent( )->name( ));
00831         BdbHandle(BdbCondRegistry) registryH;
00832 
00833         BdbStatus bdbStatus = db.findRegistry( registryH,
00834                                                name( ));
00835         if(( BdbcSuccess != bdbStatus ) || BdbIsNull(registryH)) break;
00836 
00837       // Check every single persistent revision if it matches
00838       // specified parameters.
00839 
00840         BdbItr(BdbCondRevision)    revisionItr;
00841         BdbHandle(BdbCondRevision) revisionH;
00842 
00843         registryH->setRevisionItr( revisionItr );
00844         while( revisionItr.next( )) {
00845 
00846             revisionH = revisionItr;
00847 
00848             BdbTime revisionCreationTime( revisionH->creationTime( ));
00849 
00850             char revisionIdName[11];
00851             sprintf( revisionIdName, "%u", (unsigned) revisionH->id( ));
00852 
00853           // "OLD" -> "NEW" mapping rules for revisions:
00854           //
00855           //    - We treat the creation time of the "old" revisions
00856           //      as the identifiers of the "new" ones.
00857           //
00858           //    - We also use the textual representation of the "old"
00859           //      revisions as the names of "new" revisions.
00860 
00861             if( 0 == strcmp( revisionIdName, theName )) {
00862 
00863               // DESIGN NOTE: We need to construct a smart pointer against a clone since
00864               //              we don't know a smart pointer pointing to the current
00865               //              instance, therefore we can't guarantee the lifetime
00866               //              of the current instance.
00867 
00868                 CdbConditionPtr myPtr( this->clone( ));
00869                 thePtr = new CdbBdbWRevision( myPtr,
00870                                               revisionH->creationTime( ),
00871                                               theName,
00872                                               revisionH->creationTime( ),
00873                                               revisionH->description( ),
00874                                               revisionH->id( ));
00875 
00876                 result = CdbStatus::Success;
00877                 break;
00878             }
00879         }
00880 
00881     } while( false );
00882 
00883     return result;
00884 }
00885 
00886 CdbStatus
00887 CdbBdbWCondition::revisionIdIterator( CdbItr<BdbTime>& theItr,
00888                                       unsigned short   thePartitionId )
00889 {
00890     CdbConditionPtr myPtr( this->clone( ));
00891 
00892   // ATTENTION: This is not a memory leak - the created object
00893   //            will be destroyed by the iterator.
00894 
00895     theItr = CdbItr<BdbTime>( new CdbBdbWRevisionIdItr( myPtr ));
00896 
00897     return CdbStatus::Success;
00898 }
00899 
00900 CdbStatus
00901 CdbBdbWCondition::revisionNameIterator( CdbItr<const char*>& theItr,
00902                                         unsigned short       thePartitionId )
00903 {
00904     CdbConditionPtr myPtr( this->clone( ));
00905 
00906   // ATTENTION: This is not a memory leak - the created object
00907   //            will be destroyed by the iterator.
00908 
00909     theItr = CdbItr<const char*>( new CdbBdbWRevisionNameItr( myPtr ));
00910 
00911     return CdbStatus::Success;
00912 }
00913 
00914 CdbStatus
00915 CdbBdbWCondition::createRevision( CdbRevisionPtr& thePtr,
00916                                   const BdbTime&  theId,
00917                                   const char*     theName,
00918                                   const char*     theDescription,
00919                                   unsigned short  thePartitionId )
00920 {
00921     return CdbStatus::NotImplemented;
00922 }
00923 
00924 CdbStatus
00925 CdbBdbWCondition::historyEventIterator( CdbHistoryEventItr& theItr,
00926                                         const BdbTime&      theBeginTime,
00927                                         const BdbTime&      theEndTime,
00928                                         const char**        theEventsToSelect )
00929 {
00930     return CdbStatus::NotImplemented;
00931 }
00932 
00933 CdbStatus
00934 CdbBdbWCondition::historyEventTypeIterator( CdbHistoryEventTypeItr& theItr )
00935 {
00936     return CdbStatus::NotImplemented;
00937 }
00938 
00939 CdbStatus
00940 CdbBdbWCondition::hint( BdbRefAny&     theHint,
00941                         const BdbTime& theBegin,
00942                         const BdbTime& theEnd )
00943 {
00944   // Ignore tha validity range and condition name and get the hint
00945   // in the scope of the curren detector
00946 
00947     BdbObsoleteDatabase db( parent( )->name( ));
00948 
00949     theHint = db.updatedHint( );
00950 
00951     return CdbStatus::Success;
00952 }
00953 
00954 CdbStatus
00955 CdbBdbWCondition::verify( const BdbRefAny&         theHint,
00956                           const BdbRef(BdbObject)& theObjectRef )
00957 {
00958     CdbStatus result = CdbStatus::Error;
00959 
00960     do {
00961 
00962       // All we're going to check is to see if both the hint and
00963       // the objects are located in the same container.
00964 
00965         if( BdbIsNull( theHint ))      break;
00966         if( BdbIsNull( theObjectRef )) break;
00967 
00968         BdbRef(BdbContObj) hintContRef;
00969         BdbRef(BdbContObj) objectContRef;
00970 
00971         theHint.containedIn( hintContRef );
00972         theObjectRef.containedIn( objectContRef );
00973 
00974         if( BdbIsNull( hintContRef ))   break;
00975         if( BdbIsNull( objectContRef )) break;
00976 
00977         if( hintContRef == objectContRef ) result = CdbStatus::Success;
00978 
00979     } while( false );
00980 
00981     return result;
00982 }
00983 
00984 /////////////////
00985 // End Of File //
00986 /////////////////

Generated on Mon Dec 5 18:22:04 2005 for CDB by doxygen1.3-rc3