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

CdbRooRoDatabase.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbRooRoDatabase.cc,v 1.6 2005/08/13 01:42:15 gapon Exp $
00003 
00004 /// The implementation of the CdbRooRoDatabase class.
00005 /**
00006   * @see CdbRooRoDatabase
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #include "CdbRooReadonly/CdbRooRoDatabase.hh"
00012 
00013 #include "CdbBase/Cdb.hh"
00014 #include "CdbBase/CdbView.hh"
00015 #include "CdbBase/CdbId.hh"
00016 #include "CdbBase/CdbCompositeName.hh"
00017 #include "CdbBase/CdbEnvironment.hh"
00018 #include "CdbBase/CdbPartition.hh"
00019 #include "CdbBase/CdbProperty.hh"
00020 #include "CdbBase/CdbOrigin.hh"
00021 #include "CdbBase/CdbFolder.hh"
00022 #include "CdbBase/CdbCondition.hh"
00023 #include "CdbBase/CdbSimpleVectorAdapterItr.hh"
00024 
00025 #include "CdbRooReadonly/CdbRooRoRegistry.hh"
00026 #include "CdbRooReadonly/CdbRooRoOriginR.hh"
00027 #include "CdbRooReadonly/CdbRooRoOriginCollectionR.hh"
00028 #include "CdbRooReadonly/CdbRooRoView.hh"
00029 #include "CdbRooReadonly/CdbRooRoViewR.hh"
00030 #include "CdbRooReadonly/CdbRooRoViewCollectionR.hh"
00031 #include "CdbRooReadonly/CdbRooRoViewItr.hh"
00032 #include "CdbRooReadonly/CdbRooRoPartitionsLayoutR.hh"
00033 #include "CdbRooReadonly/CdbRooRoPartitionR.hh"
00034 #include "CdbRooReadonly/CdbRooRoCondition.hh"
00035 #include "CdbRooReadonly/CdbRooRoConditionAtFolderR.hh"
00036 #include "CdbRooReadonly/CdbRooRoConditionCollectionR.hh"
00037 
00038 #include <iostream>
00039 using std::cerr;
00040 using std::endl;
00041 
00042 namespace {
00043 
00044   ////////////////////////////////
00045   // Class CdbRooRoPartitionItr //
00046   ////////////////////////////////
00047 
00048   /// The implementation of the iterator of partitions
00049   /**
00050     * This iterator is only meant to retranslate type of the result
00051     * produced by a persistent iterator.
00052     */
00053     class CdbRooRoPartitionItr : public CdbItr<unsigned short>::InterfaceType {
00054 
00055     private:
00056 
00057       /// The default constructor (NOT IMPLEMENTED)
00058 
00059         CdbRooRoPartitionItr( );
00060 
00061     public:
00062 
00063       /// The normal constructor
00064  
00065         CdbRooRoPartitionItr( const CdbItr<UShort_t>& theInputItr ) : _itr(theInputItr) { }
00066 
00067       /// The copy constructor
00068 
00069         CdbRooRoPartitionItr( const CdbRooRoPartitionItr& theItr ) : _itr(theItr._itr) { }
00070 
00071       /// The assignment operator
00072 
00073         CdbRooRoPartitionItr& operator=( const CdbRooRoPartitionItr& theItr )
00074         {
00075             if( this != &theItr ) {
00076                 _itr = theItr._itr;
00077             }
00078             return *this;
00079         }
00080 
00081       /// The destructor
00082 
00083         virtual ~CdbRooRoPartitionItr( ) { }
00084 
00085       /// Reset an iterator to its initial state.
00086       /**
00087         * This implements the corresponding method of the base class.
00088         *
00089         * @see CdbIItr::reset
00090         * @see CdbStatus
00091         */
00092         virtual CdbStatus reset( ) { return _itr.reset( ); }
00093 
00094       /// Advance an iterator to the next position.
00095       /**
00096         * This implements the corresponding method of the base class.
00097         *
00098         * @see CdbIItr::next()
00099         */
00100         virtual bool next( ) { return _itr.next( ); }
00101 
00102       /// Obtain the currently reffered value.
00103       /**
00104         * This implements the corresponding method of the base class.
00105         *
00106         * @see CdbIItr::value()
00107         * @see CdbIItr::ValueType
00108         *
00109         * @return the current value the iterator is set on
00110         */
00111         virtual ValueType value( ) { return _itr.value( ); }
00112 
00113       /// Check if an iterator is valid.
00114       /**
00115         * This implements the corresponding method of the base class.
00116         *
00117         * @see CdbIItr::isValid()
00118         */
00119         virtual bool isValid( ) { return _itr.isValid( ); }
00120 
00121       /// Make a clone of itself
00122       /**
00123         * @see CdbIItr::clone()
00124         */
00125         virtual InterfaceType* clone( ) const { return new CdbRooRoPartitionItr( *this ); }
00126 
00127     private:
00128 
00129         CdbItr<UShort_t> _itr;
00130     };
00131 
00132   /////////////////////////////
00133   // Class CdbRooRoPartition //
00134   /////////////////////////////
00135 
00136   /// The implementation of the partition API class
00137 
00138     class CdbRooRoPartition : public CdbPartition {
00139 
00140     private:
00141 
00142       /// The default constructor (NOT IMPLEMENTED)
00143 
00144         CdbRooRoPartition( );
00145 
00146       /// The copy constructor (NOT IMPLEMENTED)
00147 
00148         CdbRooRoPartition( const CdbRooRoPartition& thePartition );
00149 
00150       /// The assignment operator (NOT IMPLEMENTED)
00151 
00152         CdbRooRoPartition& operator=( const CdbRooRoPartition& thePartition );
00153 
00154     public:
00155 
00156       /// The normal constructor
00157 
00158         CdbRooRoPartition( const CdbDatabasePtr&                theDatabasePtr,                      
00159                            const CdbCPtr< CdbRooRoPartitionR >& thePartitionPtr,
00160                            unsigned short                       theOwnerId,
00161                            const char*                          theOwnerName )  :
00162             CdbPartition( theDatabasePtr,
00163                           thePartitionPtr->id( ),
00164                           theOwnerId,
00165                           theOwnerName,
00166                           thePartitionPtr->description( ).c_str( ),
00167                           thePartitionPtr->created( ),
00168                           thePartitionPtr->cell( ).beginValidity ( ),
00169                           thePartitionPtr->cell( ).endValidity   ( ),
00170                           thePartitionPtr->cell( ).beginInsertion( )),
00171             _partitionPtr(thePartitionPtr)
00172         { }
00173 
00174       /// The destructor
00175 
00176         virtual ~CdbRooRoPartition( ) { }
00177 
00178       /// The begin time in the "insertion" dimension
00179       /**
00180         * Implements the corresponding method of its base class or an interface.
00181         *
00182         * @see CdbPartition::endInsertion()
00183         */
00184         virtual BdbTime endInsertion( ) const { return _partitionPtr->cell( ).endInsertion( ); }
00185 
00186       /// The recent modification time of the partition
00187       /**
00188         * Implements the corresponding method of its base class or an interface.
00189         *
00190         * @see CdbPartition::modified()
00191         */
00192         virtual BdbTime modified( ) const { return _partitionPtr->modified( ); }
00193 
00194       /// The status of the partition
00195       /**
00196         * Implements the corresponding method of its base class or an interface.
00197         *
00198         * @see CdbPartition::isClosed()
00199         */
00200         virtual bool isClosed( ) const { return _partitionPtr->isClosed( ); }
00201 
00202       /// The status of the partition
00203       /**
00204         * Implements the corresponding method of its base class or an interface.
00205         *
00206         * @see CdbPartition::isInstantiated()
00207         */
00208         virtual bool isInstantiated( ) const { return _partitionPtr->isInstantiated( ); }
00209 
00210     private:
00211 
00212         CdbCPtr< CdbRooRoPartitionR > _partitionPtr;
00213     };
00214 
00215   /////////////////////////////
00216   // Class CdbRooRoOriginItr //
00217   /////////////////////////////
00218 
00219   /// The implementation of the iterator of partitions
00220   /**
00221     * This iterator is only meant to retranslate type of the result
00222     * produced by a persistent iterator.
00223     */
00224     class CdbRooRoOriginItr : public CdbItr<unsigned short>::InterfaceType {
00225 
00226     private:
00227 
00228       /// The default constructor (NOT IMPLEMENTED)
00229  
00230         CdbRooRoOriginItr( );
00231 
00232     public:
00233 
00234       /// The normal constructor
00235 
00236         CdbRooRoOriginItr( const CdbItr<UShort_t>& theInputItr ) : _itr(theInputItr) { }
00237 
00238       /// The copy constructor
00239 
00240         CdbRooRoOriginItr( const CdbRooRoOriginItr& theItr ) : _itr(theItr._itr) { }
00241 
00242       /// The assignment operator
00243 
00244         CdbRooRoOriginItr& operator=( const CdbRooRoOriginItr& theItr )
00245         {
00246             if( this != &theItr ) {
00247                 _itr = theItr._itr;
00248             }
00249             return *this;
00250         }
00251 
00252       /// The destructor
00253 
00254         virtual ~CdbRooRoOriginItr( ) { }
00255 
00256       /// Reset an iterator to its initial state.
00257       /**
00258         * This implements the corresponding method of the base class.
00259         *
00260         * @see CdbIItr::reset
00261         * @see CdbStatus
00262         */
00263         virtual CdbStatus reset( ) { return _itr.reset( ); }
00264 
00265       /// Advance an iterator to the next position.
00266       /**
00267         * This implements the corresponding method of the base class.
00268         *
00269         * @see CdbIItr::next()
00270         */
00271         virtual bool next( ) { return _itr.next( ); }
00272 
00273       /// Obtain the currently reffered value.
00274       /**
00275         * This implements the corresponding method of the base class.
00276         *
00277         * @see CdbIItr::value()
00278         * @see CdbIItr::ValueType
00279         *
00280         * @return the current value the iterator is set on
00281         */
00282         virtual ValueType value( ) { return _itr.value( ); }
00283 
00284       /// Check if an iterator is valid.
00285       /**
00286         * This implements the corresponding method of the base class.
00287         *
00288         * @see CdbIItr::isValid()
00289         */
00290         virtual bool isValid( ) { return _itr.isValid( ); }
00291 
00292       /// Make a clone of itself
00293       /**
00294         * @see CdbIItr::clone()
00295         */
00296         virtual InterfaceType* clone( ) const { return new CdbRooRoOriginItr( *this ); }
00297 
00298     private:
00299 
00300         CdbItr<UShort_t> _itr;
00301     };
00302 
00303   /////////////////////////////////////
00304   // Class CdbRooRoOriginPropertyItr //
00305   /////////////////////////////////////
00306 
00307   /// The implementation of a transient origin's property iterator
00308   /**
00309     * This is the "no-one-element" iterator since there are no properties
00310     * specific to the current implementation of the CDB API.
00311     */
00312     class CdbRooRoOriginPropertyItr : public CdbItr<CdbProperty>::InterfaceType {
00313 
00314     public:
00315 
00316       /// The default constructor
00317 
00318         CdbRooRoOriginPropertyItr( ) { }
00319 
00320       /// The copy constructor
00321 
00322         CdbRooRoOriginPropertyItr( const CdbRooRoOriginPropertyItr& theItr ) { }
00323 
00324       /// The assignment operator
00325 
00326         CdbRooRoOriginPropertyItr& operator=( const CdbRooRoOriginPropertyItr& theItr ) { return *this; }
00327 
00328       /// The destructor
00329 
00330         virtual ~CdbRooRoOriginPropertyItr( ) { }
00331 
00332       /// Reset an iterator to its initial state.
00333       /**
00334         * This implements the corresponding method of the base class.
00335         *
00336         * @see CdbIItr::reset
00337         * @see CdbStatus
00338         */
00339         virtual CdbStatus reset( ) { return CdbStatus::Success; }
00340 
00341       /// Advance an iterator to the next position.
00342       /**
00343         * This implements the corresponding method of the base class.
00344         *
00345         * @see CdbIItr::next()
00346         */
00347         virtual bool next( ) { return false; }
00348 
00349       /// Obtain the currently reffered value.
00350       /**
00351         * This implements the corresponding method of the base class.
00352         *
00353         * @see CdbIItr::value()
00354         * @see CdbIItr::ValueType
00355         *
00356         * @return the current value the iterator is set on
00357         */
00358         virtual ValueType value( )
00359         {
00360             assert( 0 );
00361             return CdbProperty( );
00362         }
00363 
00364       /// Check if an iterator is valid.
00365       /**
00366         * This implements the corresponding method of the base class.
00367         *
00368         * @see CdbIItr::isValid()
00369         */
00370         virtual bool isValid( ) { return false; }
00371 
00372       /// Make a clone of itself
00373       /**
00374         * @see CdbIItr::clone()
00375         */
00376         virtual InterfaceType* clone( ) const { return new CdbRooRoOriginPropertyItr( *this ); }
00377     };
00378 
00379   //////////////////////////
00380   // Class CdbRooRoOrigin //
00381   //////////////////////////
00382 
00383   /// The implementation of a transient origin
00384   /**
00385     * This is the only "origin" of the 'Wraper' implementation.
00386     */
00387     class CdbRooRoOrigin : public CdbOrigin {
00388 
00389     private:
00390 
00391       /// The constructor (NOT IMPLEMENTED)
00392 
00393         CdbRooRoOrigin( );
00394 
00395       /// The copy constructor (NOT IMPLEMENTED)
00396 
00397         CdbRooRoOrigin( const CdbRooRoOrigin& theOrigin );
00398 
00399       /// The assignment operator (NOT IMPLEMENTED)
00400 
00401         CdbRooRoOrigin& operator=( const CdbRooRoOrigin& theOrigin );
00402 
00403     public:
00404 
00405       /// The normal constructor.
00406       /**
00407         * Initialize context with specified parameters.
00408         *
00409         * @see CdbDatabase
00410         * @see CdbDatabasePtr
00411         */
00412         CdbRooRoOrigin( const CdbDatabasePtr&             theDatabasePtr,           /**< the smart pointer providing a back back link to the parent database object */
00413                         const CdbCPtr< CdbRooRoOriginR >& thePersistentOriginPtr    /**< the persistent origin */
00414                       ) :
00415             CdbOrigin( theDatabasePtr,
00416                        thePersistentOriginPtr->name( ).c_str( ),
00417                        thePersistentOriginPtr->id( )),
00418             _persistentOriginPtr(thePersistentOriginPtr)
00419         { }
00420 
00421       /// The destructor.
00422       /**
00423         * More details...
00424         */
00425         virtual ~CdbRooRoOrigin( ) { }
00426 
00427       /// Obtain the creation time of the origin
00428       /**
00429         * This implements the corresponding method of the base class.
00430         *
00431         * @see CdbOrigin::created()
00432         */
00433         virtual BdbTime created( ) { return _persistentOriginPtr->created( ); }
00434 
00435       /// Obtain the origin description
00436       /**
00437         * This implements the corresponding method of the base class.
00438         *
00439         * @see CdbOrigin::description()
00440         */
00441         virtual std::string description( ) { return _persistentOriginPtr->description( ); }
00442 
00443       /// Check if this origin is the local one
00444       /**
00445         * This implements the corresponding method of the base class.
00446         *
00447         * @see CdbOrigin::isLocal()
00448         */
00449         virtual bool isLocal( ) const
00450         {
00451           // Use parent object to get the local origin's identifier.
00452 
00453             return parent( )->localOrigin( )->id( ) == _persistentOriginPtr->id( );
00454         }
00455 
00456       /// Check if data corresponding to this origin are available in the local database
00457       /**
00458         * This implements the corresponding method of the base class.
00459         *
00460         * @see CdbOrigin::isInstantiated()
00461         */
00462         virtual bool isInstantiated( ) const
00463         {
00464           // Try to find the persistent registry corresponding to the current origin's identifier.
00465           // The presense of this reqistry would mean that the data from this database are either
00466           // native to the current database or they have already been brough from the corresponding
00467           // remote database into the current one.
00468 
00469             CdbCPtr< CdbRooRoRegistry > ptr;
00470             return CdbStatus::Success == CdbRooRoRegistry::findByOrigin( ptr,
00471                                                                          _persistentOriginPtr->id( ));
00472         }
00473 
00474       /// Check if this origin is the "master" one
00475       /**
00476         * This implements the corresponding method of the base class.
00477         *
00478         * @see CdbOrigin::isMaster()
00479         */
00480         virtual bool isMaster( ) const { return _persistentOriginPtr->type( ) == CdbRooRoOriginR::MASTER; }
00481 
00482       /// Check if this origin is a "slave" one
00483       /**
00484         * This implements the corresponding method of the base class.
00485         *
00486         * @see CdbOrigin::isSlave()
00487         */
00488         virtual bool isSlave( ) const { return _persistentOriginPtr->type( ) == CdbRooRoOriginR::SLAVE; }
00489 
00490       /// Check if this origin is a "test" one
00491       /**
00492         * This implements the corresponding method of the base class.
00493         *
00494         * @see CdbOrigin::isTest()
00495         */
00496         virtual bool isTest( ) const { return _persistentOriginPtr->type( ) == CdbRooRoOriginR::TEST; }
00497 
00498       /// Set up an iterator of properties
00499       /**
00500         * This implements the corresponding method of the base class.
00501         *
00502         * @see CdbOrigin::propertyIterator()
00503         */
00504         virtual CdbStatus propertyIterator( CdbItr<CdbProperty>& theItr )
00505         {
00506           // ATTENTION: This is not a memory leak - the created object
00507           //            will be destroyed by the iterator.
00508 
00509             theItr = CdbItr<CdbProperty>( new CdbRooRoOriginPropertyItr( ));
00510 
00511             return CdbStatus::Success;
00512         }
00513 
00514     private:
00515 
00516         CdbCPtr< CdbRooRoOriginR > _persistentOriginPtr;
00517     };
00518 }
00519 
00520 ////////////////////////////
00521 // Class CdbRooRoDatabase //
00522 ////////////////////////////
00523 
00524 CdbDatabase*
00525 CdbRooRoDatabase::clone( ) const
00526 {
00527   // IMPLEMENTATION NOTE: The resulting object will be "closed".
00528 
00529     return new CdbRooRoDatabase( this->parent( ),
00530                                  this->name( ));
00531 }
00532 
00533 CdbRooRoDatabase::CdbRooRoDatabase( const CdbPtr& theCdbPtr,
00534                                     const char*   theName ) :
00535     CdbDatabase( theCdbPtr,
00536                  theName ),
00537     _isValid(true),
00538     _isOpen (false)
00539 { }
00540 
00541 CdbRooRoDatabase::~CdbRooRoDatabase( )
00542 { }
00543 
00544 bool
00545 CdbRooRoDatabase::isValid( )
00546 {
00547     return _isValid;
00548 }
00549 
00550 bool
00551 CdbRooRoDatabase::isOpen( )
00552 {
00553     return _isOpen;
00554 }
00555 
00556 CdbStatus
00557 CdbRooRoDatabase::open( )
00558 {
00559     const char* errorStr = "CdbRooRoDatabase::open() - ERROR.";
00560 
00561     if( !_isOpen ) {
00562 
00563       // Find local registry first because it can also be a master one
00564 
00565         if( CdbStatus::Success != CdbRooRoRegistry::findLocal( _localRegistryPtr )) {
00566             cerr << errorStr << endl
00567                  << "    Failed to find the local registry. The database was not properly" << endl
00568                  << "    initialized/loaded." << endl;
00569             return CdbStatus::Error;
00570         }
00571 
00572       // Find the master if required
00573 
00574         if( _localRegistryPtr->isMaster( )) {
00575             _masterRegistryPtr = _localRegistryPtr;
00576         } else {
00577             if( CdbStatus::Success != CdbRooRoRegistry::findMaster( _masterRegistryPtr )) {
00578                 cerr << errorStr << endl
00579                      << "    Failed to find the master registry. The database was not properly" << endl
00580                      << "    initialized/loaded." << endl;
00581                 return CdbStatus::Error;
00582             }
00583         }
00584         _isOpen = true;
00585     }
00586     return CdbStatus::Success;
00587 }
00588 
00589 CdbStatus
00590 CdbRooRoDatabase::close( )
00591 {
00592     if( _isOpen ) {
00593         _isOpen = false;
00594 
00595         _masterRegistryPtr = 0;
00596         _localRegistryPtr  = 0;
00597     }
00598     return CdbStatus::Success;
00599 }
00600 
00601 BdbTime
00602 CdbRooRoDatabase::id( )
00603 {
00604   // Make sure the database is open
00605 
00606     if( CdbStatus::Success != open( )) {
00607         assert( 0 );
00608         return BdbTime::plusInfinity;
00609     }
00610     return _localRegistryPtr->id( );
00611 }
00612 
00613 BdbTime
00614 CdbRooRoDatabase::created( )
00615 {
00616   // Make sure the database is open
00617 
00618     if( CdbStatus::Success != open( )) {
00619         assert( 0 );
00620         return BdbTime::plusInfinity;
00621     }
00622     return _localRegistryPtr->created( );
00623 }
00624 
00625 std::string
00626 CdbRooRoDatabase::description( )
00627 {
00628   // Make sure the database is open
00629 
00630     if( CdbStatus::Success != open( )) {
00631         assert( 0 );
00632         return std::string( );
00633     }
00634     return std::string( _localRegistryPtr->description( ));
00635 }
00636 
00637 std::string
00638 CdbRooRoDatabase::defaultView( ) const
00639 {
00640     return CdbEnvironment::defaultView( parent( )->technologyName( ),
00641                                         parent( )->implementationName( ),
00642                                         name( ));
00643 }
00644 
00645 CdbStatus
00646 CdbRooRoDatabase::findView( CdbViewPtr& thePtr,
00647                             const char* theName )
00648 {
00649     const char* errorStr = "CdbRooRoDatabase::findView(name) -- ERROR" ;
00650 
00651   // Verify and correct parameters if 0 pointer is passed to indicate
00652   // that default database is needed.
00653 
00654     std::string viewName = defaultView( );
00655     if( 0 != theName ) viewName = theName;
00656 
00657     CdbCompositeName compositeViewName( viewName.c_str( ));
00658     if( !compositeViewName.isValid( )) {
00659         cerr << errorStr << endl
00660              << "    The view name passed to the procedure has invalid" << endl
00661              << "    format: \"" << viewName << "\"" << endl;
00662 
00663         return CdbStatus::IllegalParameters;
00664     }
00665 
00666   // Extract origin name and local view names
00667 
00668     std::string originName    = compositeViewName.first( );
00669     std::string localViewName = compositeViewName.last( );
00670 
00671   // Make sure the database is open
00672 
00673     if( CdbStatus::Success != open( )) return CdbStatus::Error;
00674 
00675   // Find the registry where the specified view is supposed to belong to
00676   //
00677   // NOTE: Watch for the simple optimizations in case of local or master
00678   //       origins.
00679 
00680     CdbCPtr< CdbRooRoRegistry > registryPtr;
00681     if(      "<master>" == originName ) registryPtr = _masterRegistryPtr;
00682     else if( "<local>"  == originName ) registryPtr = _localRegistryPtr;
00683     else {
00684         if( CdbStatus::Success != CdbRooRoRegistry::findByOrigin( registryPtr,
00685                                                                   originName )) {
00686             cerr << errorStr << endl
00687                  << "    Registry for specified origin was not found." << endl;
00688 
00689             return CdbStatus::Error;
00690         }
00691     }
00692 
00693   // Find the view by its name at the collection of the found registry.
00694   //
00695   // NOTE: Watch for "short cut" in case if view nicknames are used.
00696 
00697     CdbCPtr< CdbRooRoViewR > persistentViewPtr;
00698     if( "<recent>" == localViewName ) {
00699 
00700         CdbStatus result = registryPtr->viewCollection( )->newest( persistentViewPtr );
00701         if( CdbStatus::Success != result ) return result;
00702 
00703     } else {
00704 
00705         CdbStatus result = registryPtr->viewCollection( )->find( localViewName,
00706                                                                  persistentViewPtr );
00707         if( CdbStatus::Success != result ) return result;
00708     }
00709 
00710   // Construct the extended identifier of the view (nneded to construct
00711   // the transient API object).
00712 
00713     CdbId viewId( registryPtr->originId( ),
00714                   persistentViewPtr->id( ));
00715 
00716   // DESIGN NOTE: We need to construct a smart pointer against a clone since
00717   //              we don't know a smart pointer pointing to the current
00718   //              instance, therefore we can't guarantee the lifetime
00719   //              of the current instance.
00720   //
00721   // NOTE: The above corrected parameters object is used.
00722 
00723     thePtr = new CdbRooRoView( CdbDatabasePtr( this->clone( )),
00724                                viewName.c_str( ),
00725                                viewId,
00726                                persistentViewPtr,
00727                                _masterRegistryPtr,
00728                                _localRegistryPtr );
00729 
00730     return CdbStatus::Success;
00731 }
00732 
00733 CdbStatus
00734 CdbRooRoDatabase::findView( CdbViewPtr&  thePtr,
00735                             const CdbId& theId )
00736 {
00737     const char* errorStr = "CdbRooRoDatabase::findView(id) -- ERROR" ;
00738 
00739   // Make sure the database is open
00740 
00741     if( CdbStatus::Success != open( )) return CdbStatus::Error;
00742 
00743   // Find the registry where the specified view is supposed to belong to
00744   //
00745   // NOTE: Watch for the simple optimizations in case of local or master
00746   //       origins.
00747 
00748     CdbCPtr< CdbRooRoRegistry > registryPtr;
00749     if(      theId.origin == _masterRegistryPtr->originId( )) registryPtr = _masterRegistryPtr;
00750     else if( theId.origin == _localRegistryPtr->originId( ))  registryPtr = _localRegistryPtr;
00751     else {
00752         if( CdbStatus::Success != CdbRooRoRegistry::findByOrigin( registryPtr,
00753                                                                   theId.origin )) {
00754             cerr << errorStr << endl
00755                  << "    Registry for specified origin was not found." << endl;
00756 
00757             return CdbStatus::Error;
00758         }
00759     }
00760 
00761   // Find the view by its name at the collection of the found registry.
00762 
00763     CdbCPtr< CdbRooRoViewR > persistentViewPtr;
00764     CdbStatus                result = registryPtr->viewCollection( )->find( theId.local,
00765                                                                             persistentViewPtr );
00766     if( CdbStatus::Success != result ) return result;
00767 
00768   // Build the full name of the view
00769 
00770     std::string viewName( "" );
00771     {
00772         CdbCPtr< CdbRooRoOriginR > persistentOriginPtr;
00773         if( CdbStatus::Success != _masterRegistryPtr->originCollection( )->find( theId.origin,
00774                                                                                  persistentOriginPtr )) {
00775             cerr << errorStr << endl
00776                  << "    The origin with ID: " << theId.origin << " not found in the master." << endl;
00777 
00778             return CdbStatus::Error;
00779         }
00780         CdbCompositeName compositeViewName( persistentOriginPtr->name( ).c_str( ),
00781                                             persistentViewPtr->name( ).c_str( ));
00782         assert( compositeViewName.isValid( ));
00783 
00784         viewName = compositeViewName.getName( );
00785     }
00786 
00787   // DESIGN NOTE: We need to construct a smart pointer against a clone since
00788   //              we don't know a smart pointer pointing to the current
00789   //              instance, therefore we can't guarantee the lifetime
00790   //              of the current instance.
00791   //
00792   // NOTE: The above corrected parameters object is used.
00793 
00794     thePtr = new CdbRooRoView( CdbDatabasePtr( this->clone( )),
00795                                viewName.c_str( ),
00796                                theId,
00797                                persistentViewPtr,
00798                                _masterRegistryPtr,
00799                                _localRegistryPtr );
00800 
00801     return CdbStatus::Success;
00802 }
00803 
00804 CdbStatus
00805 CdbRooRoDatabase::viewIterator( CdbViewItr& theItr )
00806 {
00807   // Make sure the database is open
00808 
00809     if( CdbStatus::Success != open( )) return CdbStatus::Error;
00810 
00811   // ATTENTION: This is not a memory leak - the created object
00812   //            will be destroyed by the iterator.
00813 
00814     theItr = CdbViewItr( new CdbRooRoViewItr( _masterRegistryPtr ));
00815 
00816     return CdbStatus::Success;
00817 }
00818 
00819 CdbStatus
00820 CdbRooRoDatabase::physicalConditionIterator( CdbItr<CdbId>& theItr )
00821 {
00822     const char* errorStr = "CdbRooRoDatabase::physicalConditionIterator() -- ERROR" ;
00823 
00824     CdbStatus result = CdbStatus::Error;
00825 
00826   // Make sure the database is open
00827 
00828     if( CdbStatus::Success != open( )) return CdbStatus::Error;
00829 
00830   // Find all physical conditions and put their 'global physical identifiers'
00831   // into this vector.
00832 
00833     std::vector<CdbId> vectorOfIds;
00834 
00835     CdbItr<UShort_t> originItr = _masterRegistryPtr->originCollection( )->iterator_identifiers( );
00836     while( originItr.next( )) {
00837 
00838         UShort_t originId = originItr.value( );
00839 
00840       // Try to get the corresponding registry. If it doesn't exist (not instantiated) then we
00841       // won't look for conditions of that registry.
00842 
00843         CdbCPtr< CdbRooRoRegistry > registryPtr;
00844         {
00845             if( CdbStatus::Success != ( result = CdbRooRoRegistry::findByOrigin( registryPtr,
00846                                                                                  originId ))) {
00847                 if( CdbStatus::NotFound == result ) {
00848 
00849                   // The origin is not currently instantiated in the input database. This may happen
00850                   // when the origin's data are yet to be imported.
00851 
00852                     continue;
00853 
00854                 } else {
00855                     cerr << errorStr << endl
00856                          << "    Failed to find a registry for origin ID = " << originId << "." << endl;
00857                     return result;
00858                 }
00859             }
00860         }
00861 
00862       // Get a collection of physical conditions from the registry
00863       //
00864       // NOTE; Some registries may not have local collections.. So we just skip them.
00865 
00866         CdbCPtr< CdbRooRoConditionCollectionR > conditionCollectionPtr = registryPtr->conditionCollection( );
00867         if( !conditionCollectionPtr.isNull( )) {
00868 
00869             CdbItr<UShort_t>  pConditionItr = conditionCollectionPtr->iterator_identifiers( );
00870             while( pConditionItr.next( )) {
00871                 vectorOfIds.push_back( CdbId( originId,
00872                                               pConditionItr.value( )));
00873             }
00874         }
00875     }
00876 
00877   // Build an iterator out of the vector
00878 
00879     theItr = CdbItr<CdbId>( new CdbSimpleVectorAdapterItr<CdbId>( vectorOfIds ));
00880 
00881     return CdbStatus::Success;
00882 }
00883 
00884 CdbStatus
00885 CdbRooRoDatabase::findCondition( CdbConditionPtr& thePtr,
00886                                  const CdbId&     theId )
00887 {
00888     const char* errorStr = "CdbRooRoDatabase::findCondition('physical address') -- ERROR" ;
00889 
00890   // Make sure the database is open
00891 
00892     if( CdbStatus::Success != open( )) return CdbStatus::Error;
00893 
00894   // Find the registry where the specified physical condition is supposed to belong to
00895   //
00896   // NOTE: Watch for the simple optimizations in case of local or master
00897   //       origins.
00898 
00899     CdbCPtr< CdbRooRoRegistry > registryPtr;
00900     if(      theId.origin == _masterRegistryPtr->originId( )) registryPtr = _masterRegistryPtr;
00901     else if( theId.origin == _localRegistryPtr->originId( ))  registryPtr = _localRegistryPtr;
00902     else {
00903         if( CdbStatus::Success != CdbRooRoRegistry::findByOrigin( registryPtr,
00904                                                                   theId.origin )) {
00905             cerr << errorStr << endl
00906                  << "    Registry for specified origin " << theId.origin << " was not found." << endl;
00907 
00908             return CdbStatus::Error;
00909         }
00910     }
00911 
00912   // Find the condition by its identifier at the 'physical' collection.
00913 
00914     CdbCPtr< CdbRooRoConditionR > persistentConditionPtr;
00915     CdbStatus                     result = registryPtr->conditionCollection( )->find( theId.local,
00916                                                                                       persistentConditionPtr );
00917     if( CdbStatus::Success != result ) return result;
00918 
00919   // Build the full name of the condition
00920 
00921     std::string conditionName( "" );
00922     {
00923         CdbCPtr< CdbRooRoOriginR > persistentOriginPtr;
00924         if( CdbStatus::Success != _masterRegistryPtr->originCollection( )->find( theId.origin,
00925                                                                                  persistentOriginPtr )) {
00926             cerr << errorStr << endl
00927                  << "    The origin with ID: " << theId.origin << " not found in the master." << endl;
00928 
00929             return CdbStatus::Error;
00930         }
00931         conditionName = persistentOriginPtr->name( ) + std::string( "::" ) + persistentConditionPtr->name( );
00932     }
00933 
00934   // DESIGN NOTE: The condition API component is going to be disjoined from
00935   //              any view or a folder. The direct database pointer will be added instead.
00936 
00937     CdbFolderPtr                               parentFolderPtr = 0;
00938     CdbRooRoConditionAtFolderR* persistentConditionAtFolderPtr = 0;
00939 
00940   // DESIGN NOTE: We need to construct a smart pointer against a clone since
00941   //              we don't know a smart pointer pointing to the current
00942   //              instance, therefore we can't guarantee the lifetime
00943   //              of the current instance.
00944 
00945     thePtr = new CdbRooRoCondition( parentFolderPtr,
00946                                     CdbDatabasePtr( this->clone( )),
00947                                     conditionName.c_str( ),
00948                                     theId,
00949                                     persistentConditionAtFolderPtr,
00950                                     persistentConditionPtr,
00951                                     _masterRegistryPtr,
00952                                     _localRegistryPtr );
00953 
00954     return CdbStatus::Success;
00955 }
00956 
00957 CdbStatus
00958 CdbRooRoDatabase::findCondition( CdbConditionPtr&        thePtr,
00959                                  const CdbCompositeName& thePhysicalName )
00960 {
00961     const char* errorStr = "CdbRooRoDatabase::findCondition('physical name') -- ERROR" ;
00962 
00963   // Make sure the database is open
00964 
00965     if( CdbStatus::Success != open( )) return CdbStatus::Error;
00966 
00967   // Verify parameters
00968 
00969     if( !thePhysicalName.isValid( )) {
00970 
00971         cerr << errorStr << endl
00972              << "    The 'physical name' name passed to the procedure has invalid" << endl
00973              << "    format: \"" << thePhysicalName.getName( ) << "\"" << endl;
00974 
00975         return CdbStatus::IllegalParameters;
00976     }
00977 
00978 
00979   // Extract origin name and local condition names
00980 
00981     std::string originName         = thePhysicalName.first( );
00982     std::string localConditionName = thePhysicalName.last( );
00983 
00984   // Find the registry where the specified physical condition is supposed to belong to
00985   //
00986   // NOTE: Watch for the simple optimizations in case of local or master
00987   //       origins.
00988 
00989     CdbCPtr< CdbRooRoRegistry > registryPtr;
00990     if     ( "<master>" == originName ) registryPtr = _masterRegistryPtr;
00991     else if(  "<local>" == originName ) registryPtr =  _localRegistryPtr;
00992     else {
00993         if( CdbStatus::Success != CdbRooRoRegistry::findByOrigin( registryPtr,
00994                                                                   originName )) {
00995             cerr << errorStr << endl
00996                  << "    Registry for specified origin \"" << originName << "\" was not found." << endl;
00997 
00998             return CdbStatus::Error;
00999         }
01000     }
01001 
01002   // Find the condition by its 'physical' name at the collection.
01003 
01004     CdbCPtr< CdbRooRoConditionR > persistentConditionPtr;
01005     CdbStatus                     result = registryPtr->conditionCollection( )->find( localConditionName,
01006                                                                                       persistentConditionPtr );
01007     if( CdbStatus::Success != result ) return result;
01008 
01009   // DESIGN NOTE: The condition API component is going to be disjoined from
01010   //              any view or a folder. The direct database pointer will be added instead.
01011 
01012     CdbFolderPtr                               parentFolderPtr = 0;
01013     CdbRooRoConditionAtFolderR* persistentConditionAtFolderPtr = 0;
01014 
01015   // DESIGN NOTE: We need to construct a smart pointer against a clone since
01016   //              we don't know a smart pointer pointing to the current
01017   //              instance, therefore we can't guarantee the lifetime
01018   //              of the current instance.
01019 
01020     thePtr = new CdbRooRoCondition( parentFolderPtr,
01021                                     CdbDatabasePtr( this->clone( )),
01022                                     thePhysicalName.getName( ).c_str( ),
01023                                     CdbId( registryPtr->originId( ),
01024                                            persistentConditionPtr->id( )),
01025                                     persistentConditionAtFolderPtr,
01026                                     persistentConditionPtr,
01027                                     _masterRegistryPtr,
01028                                     _localRegistryPtr );
01029 
01030     return CdbStatus::Success;
01031 }
01032 
01033 CdbStatus
01034 CdbRooRoDatabase::historyEventIterator( CdbHistoryEventItr& theItr,
01035                                         const BdbTime&      theBeginTime,
01036                                         const BdbTime&      theEndTime,
01037                                         const char**        theEventsToSelect )
01038 {
01039     return CdbStatus::NotImplemented;
01040 }
01041 
01042 CdbStatus
01043 CdbRooRoDatabase::historyEventTypeIterator( CdbHistoryEventTypeItr& theItr )
01044 {
01045     return CdbStatus::NotImplemented;
01046 }
01047 
01048 CdbStatus
01049 CdbRooRoDatabase::partitionIterator( CdbItr<unsigned short>& theItr )
01050 {
01051   // Make sure the database is open
01052 
01053     if( CdbStatus::Success != open( )) return CdbStatus::Error;
01054 
01055   // ATTENTION: This is not a memory leak - the created object
01056   //            will be destroyed by the iterator.
01057 
01058     theItr = CdbItr<unsigned short>( new CdbRooRoPartitionItr( _masterRegistryPtr->partitionsLayout( )->iterator( )));
01059 
01060     return CdbStatus::Success;
01061 }
01062 
01063 CdbStatus
01064 CdbRooRoDatabase::partitionIterator( CdbItr<unsigned short>& theItr,
01065                                      unsigned int            theOriginId )
01066 {
01067     const char* errorStr = "CdbRooRoDatabase::partitionIterator(by origin id) - ERROR.";
01068 
01069   // Make sure the database is open
01070 
01071     if( CdbStatus::Success != open( )) return CdbStatus::Error;
01072 
01073   // Find the corresponding registry
01074 
01075     CdbCPtr< CdbRooRoRegistry > registryPtr;
01076     CdbStatus                   result = CdbRooRoRegistry::findByOrigin( registryPtr,
01077                                                                          theOriginId );
01078     if( CdbStatus::Success != result ) {
01079         if( CdbStatus::NotFound == result ) {
01080             cerr << errorStr << endl
01081                  << "    The specified origin identifier " << theOriginId << " does not correspond to any" << endl
01082                  << "    known origin in the current database. Please check the logic of your application." << endl;
01083         } else {
01084             cerr << errorStr << endl
01085                  << "    Failed to find the registry for specified origin identifier " << theOriginId << "." << endl
01086                  << "    Perhaps the database was not properly initialized/loaded." << endl;
01087         }
01088         return result;
01089     }
01090 
01091   // Try to get the P-Layout. Some origins may not have it. Silently return
01092   // the CdbStatus::NotFound if this is going to be the case.
01093 
01094     CdbCPtr< CdbRooRoPartitionsLayoutR > pLayoutPtr = registryPtr->partitionsLayout( );
01095     if( pLayoutPtr.isNull( )) return CdbStatus::NotFound;
01096 
01097   // ATTENTION: This is not a memory leak - the created object
01098   //            will be destroyed by the iterator.
01099 
01100     theItr = CdbItr<unsigned short>( new CdbRooRoPartitionItr( pLayoutPtr->iterator( )));
01101 
01102     return CdbStatus::Success;
01103 }
01104 
01105 CdbStatus
01106 CdbRooRoDatabase::partitionIterator( CdbItr<unsigned short>& theItr,
01107                                      const char*             theOriginName )
01108 {
01109     const char* errorStr = "CdbRooRoDatabase::partitionIterator(by origin name) - ERROR.";
01110 
01111   // Make sure the database is open
01112 
01113     if( CdbStatus::Success != open( )) return CdbStatus::Error;
01114 
01115   // Find the corresponding registry
01116 
01117     CdbCPtr< CdbRooRoRegistry > registryPtr;
01118     CdbStatus                   result = CdbRooRoRegistry::findByOrigin( registryPtr,
01119                                                                          theOriginName );
01120     if( CdbStatus::Success != result ) {
01121         if( CdbStatus::NotFound == result ) {
01122             cerr << errorStr << endl
01123                  << "    The specified origin name \"" << theOriginName << "\" does not correspond to any" << endl
01124                  << "    known origin in the current database. Please check the logic of your application." << endl;
01125         } else {
01126             cerr << errorStr << endl
01127                  << "    Failed to find the registry for specified origin name \"" << theOriginName << "\"." << endl
01128                  << "    Perhaps the database was not properly initialized/loaded." << endl;
01129         }
01130         return result;
01131     }
01132 
01133   // Try to get the P-Layout. Some origins may not have it. Silently return
01134   // the CdbStatus::NotFound if this is going to be the case.
01135 
01136     CdbCPtr< CdbRooRoPartitionsLayoutR > pLayoutPtr = registryPtr->partitionsLayout( );
01137     if( pLayoutPtr.isNull( )) return CdbStatus::NotFound;
01138 
01139   // ATTENTION: This is not a memory leak - the created object
01140   //            will be destroyed by the iterator.
01141 
01142     theItr = CdbItr<unsigned short>( new CdbRooRoPartitionItr( pLayoutPtr->iterator( )));
01143 
01144     return CdbStatus::Success;
01145 }
01146 
01147 CdbStatus
01148 CdbRooRoDatabase::findPartition( CdbPartitionPtr& thePtr,
01149                                  unsigned short   thePartition )
01150 {
01151     const char* errorStr = "CdbRooRoDatabase::findPartition() -- ERROR" ;
01152 
01153   // Make sure the database is open
01154 
01155     if( CdbStatus::Success != open( )) return CdbStatus::Error;
01156 
01157   // Find specified partition
01158   //
01159   // NOTE: This algorithm will use partition object from the local
01160   //       P-Layout if it will discover that the partition belongs to the current
01161   //       database. This is a typical scenario for the SLAVE type databases.
01162 
01163     CdbCPtr< CdbRooRoPartitionR > partitionPtr;
01164     {
01165         CdbStatus result = _masterRegistryPtr->partitionsLayout( )->find( thePartition,
01166                                                                           partitionPtr );
01167         if( CdbStatus::Success != result ) return result;
01168 
01169         if( partitionPtr->originId( ) != _masterRegistryPtr->originId( )) {
01170             if( partitionPtr->originId( ) == _localRegistryPtr->originId( )) {
01171 
01172                 CdbStatus result = _localRegistryPtr->partitionsLayout( )->find( thePartition,
01173                                                                                  partitionPtr );
01174                 if( CdbStatus::Success != result ) {
01175                     cerr << errorStr << endl
01176                          << "    Failed to find partition with ID=" << thePartition << " at the current" << endl
01177                          << "    database to whom the partition is supposed to belong to. The database" << endl
01178                          << "    may not be properly initialized/loaded." << endl;
01179                     return result;
01180                 }
01181             }
01182         }
01183     }
01184 
01185   // Get the owner's origin name of this partition.
01186 
01187     std::string ownerOriginName;
01188     {
01189         CdbCPtr< CdbRooRoOriginR > persistentOriginPtr;
01190         if( CdbStatus::Success != _masterRegistryPtr->originCollection( )->find( partitionPtr->originId( ),
01191                                                                                  persistentOriginPtr )) {
01192             cerr << errorStr << endl
01193                  << "    There is no information on the origin ID=" << partitionPtr->originId( ) << endl
01194                  << "    in the corresponding collection of the MASTER's registry." << endl
01195                  << "    The database may be corrupted or in an inconsistent state." << endl;
01196 
01197             return CdbStatus::Error;
01198         }
01199         ownerOriginName = persistentOriginPtr->name( );
01200     }
01201 
01202   // DESIGN NOTE: We need to construct a smart pointer against a clone since
01203   //              we don't know a smart pointer pointing to the current
01204   //              instance, therefore we can't guarantee the lifetime
01205   //              of the current instance.
01206   //
01207   // NOTE: The above corrected parameters object is used.
01208 
01209     thePtr = new CdbRooRoPartition( CdbDatabasePtr( this->clone( )),
01210                                     partitionPtr,
01211                                     partitionPtr->originId( ),
01212                                     ownerOriginName.c_str( ));
01213 
01214     return CdbStatus::Success;
01215 }
01216 
01217 CdbStatus
01218 CdbRooRoDatabase::findPartition( CdbPartitionPtr& thePtr,
01219                                  unsigned short   thePartition,
01220                                  unsigned int     theOriginId )
01221 {
01222     const char* errorStr = "CdbRooRoDatabase::findPartition(by origin id) -- ERROR" ;
01223 
01224   // Make sure the database is open
01225 
01226     if( CdbStatus::Success != open( )) return CdbStatus::Error;
01227 
01228   // Find the corresponding registry
01229 
01230     CdbCPtr< CdbRooRoRegistry > registryPtr;
01231     {
01232         CdbStatus  result = CdbRooRoRegistry::findByOrigin( registryPtr,
01233                                                             theOriginId );
01234         if( CdbStatus::Success != result ) {
01235             if( CdbStatus::NotFound == result ) {
01236                 cerr << errorStr << endl
01237                      << "    The specified origin identifier " << theOriginId << " does not correspond to any" << endl
01238                      << "    known origin in the current database. Please check the logic of your application." << endl;
01239             } else {
01240                 cerr << errorStr << endl
01241                      << "    Failed to find the registry for specified origin identifier " << theOriginId << "." << endl
01242                      << "    Perhaps the database was not properly initialized/loaded." << endl;
01243             }
01244             return result;
01245         }
01246     }
01247 
01248   // Try to get the P-Layout. Some origins may not have it.
01249 
01250     CdbCPtr< CdbRooRoPartitionsLayoutR > pLayoutPtr = registryPtr->partitionsLayout( );
01251     if( pLayoutPtr.isNull( )) {
01252 
01253         cerr << errorStr << endl
01254              << "    The origin for specified origin identifier " << theOriginId << " is not allowed" << endl
01255              << "    to have partitions. Please check the logic of your application." << endl;
01256 
01257         return CdbStatus::Error;
01258     }
01259 
01260   // Find the specified partition
01261 
01262     CdbCPtr< CdbRooRoPartitionR > partitionPtr;
01263     {
01264         CdbStatus result = pLayoutPtr->find( thePartition,
01265                                              partitionPtr );
01266         if( CdbStatus::Success != result ) return result;
01267     }
01268 
01269   // Get the owner's origin name of this partition.
01270 
01271     std::string ownerOriginName;
01272     {
01273         CdbCPtr< CdbRooRoOriginR > persistentOriginPtr;
01274         if( CdbStatus::Success != _masterRegistryPtr->originCollection( )->find( partitionPtr->originId( ),
01275                                                                                  persistentOriginPtr )) {
01276             cerr << errorStr << endl
01277                  << "    There is no information on the origin ID=" << partitionPtr->originId( ) << endl
01278                  << "    in the corresponding collection of the MASTER's registry." << endl
01279                  << "    The database may be corrupted or in an inconsistent state." << endl;
01280 
01281             return CdbStatus::Error;
01282         }
01283         ownerOriginName = persistentOriginPtr->name( );
01284     }
01285 
01286   // DESIGN NOTE: We need to construct a smart pointer against a clone since
01287   //              we don't know a smart pointer pointing to the current
01288   //              instance, therefore we can't guarantee the lifetime
01289   //              of the current instance.
01290   //
01291   // NOTE: The above corrected parameters object is used.
01292 
01293     thePtr = new CdbRooRoPartition( CdbDatabasePtr( this->clone( )),
01294                                     partitionPtr,
01295                                     partitionPtr->originId( ),
01296                                     ownerOriginName.c_str( ));
01297 
01298     return CdbStatus::Success;
01299 }
01300 
01301 CdbStatus
01302 CdbRooRoDatabase::findPartition( CdbPartitionPtr& thePtr,
01303                                  unsigned short   thePartition,
01304                                  const char*      theOriginName )
01305 {
01306     const char* errorStr = "CdbRooRoDatabase::findPartition(by origin name) -- ERROR" ;
01307 
01308   // Make sure the database is open
01309 
01310     if( CdbStatus::Success != open( )) return CdbStatus::Error;
01311 
01312   // Find the corresponding registry
01313 
01314     CdbCPtr< CdbRooRoRegistry > registryPtr;
01315     {
01316         CdbStatus result = CdbRooRoRegistry::findByOrigin( registryPtr,
01317                                                            theOriginName );
01318         if( CdbStatus::Success != result ) {
01319             if( CdbStatus::NotFound == result ) {
01320                 cerr << errorStr << endl
01321                      << "    The specified origin name \"" << theOriginName << "\" does not correspond to any" << endl
01322                      << "    known origin in the current database. Please check the logic of your application." << endl;
01323             } else {
01324                 cerr << errorStr << endl
01325                      << "    Failed to find the registry for specified origin name \"" << theOriginName << "\"." << endl
01326                      << "    Perhaps the database was not properly initialized/loaded." << endl;
01327             }
01328             return result;
01329         }
01330     }
01331 
01332   // Try to get the P-Layout. Some origins may not have it.
01333 
01334     CdbCPtr< CdbRooRoPartitionsLayoutR > pLayoutPtr = registryPtr->partitionsLayout( );
01335     if( pLayoutPtr.isNull( )) {
01336 
01337         cerr << errorStr << endl
01338              << "    The origin for specified origin name \"" << theOriginName << "\" is not allowed" << endl
01339              << "    to have partitions. Please check the logic of your application." << endl;
01340 
01341         return CdbStatus::Error;
01342     }
01343 
01344   // Find the specified partition
01345 
01346     CdbCPtr< CdbRooRoPartitionR > partitionPtr;
01347     {
01348         CdbStatus result = pLayoutPtr->find( thePartition,
01349                                              partitionPtr );
01350         if( CdbStatus::Success != result ) return result;
01351     }
01352 
01353   // Get the owner's origin name of this partition.
01354 
01355     std::string ownerOriginName;
01356     {
01357         CdbCPtr< CdbRooRoOriginR > persistentOriginPtr;
01358         if( CdbStatus::Success != _masterRegistryPtr->originCollection( )->find( partitionPtr->originId( ),
01359                                                                                  persistentOriginPtr )) {
01360             cerr << errorStr << endl
01361                  << "    There is no information on the origin ID=" << partitionPtr->originId( ) << endl
01362                  << "    in the corresponding collection of the MASTER's registry." << endl
01363                  << "    The database may be corrupted or in an inconsistent state." << endl;
01364 
01365             return CdbStatus::Error;
01366         }
01367         ownerOriginName = persistentOriginPtr->name( );
01368     }
01369 
01370   // DESIGN NOTE: We need to construct a smart pointer against a clone since
01371   //              we don't know a smart pointer pointing to the current
01372   //              instance, therefore we can't guarantee the lifetime
01373   //              of the current instance.
01374   //
01375   // NOTE: The above corrected parameters object is used.
01376 
01377     thePtr = new CdbRooRoPartition( CdbDatabasePtr( this->clone( )),
01378                                     partitionPtr,
01379                                     partitionPtr->originId( ),
01380                                     ownerOriginName.c_str( ));
01381 
01382     return CdbStatus::Success;
01383 }
01384 
01385 CdbOriginPtr
01386 CdbRooRoDatabase::localOrigin( )
01387 {
01388   // Make sure the database is open
01389 
01390     if( CdbStatus::Success != open( )) {
01391         assert( 0 );
01392         return 0;
01393     }
01394 
01395   // Use cached object pointer if possible
01396 
01397     if( _localOriginPtr.isNull( )) {
01398         if( CdbStatus::Success != findOrigin( _localOriginPtr,
01399                                               _localRegistryPtr->originId( ))) {
01400             assert( 0 );
01401             return 0;
01402         }
01403     }
01404     return _localOriginPtr;
01405 }
01406 
01407 CdbStatus
01408 CdbRooRoDatabase::originIterator( CdbItr<unsigned short>& theItr )
01409 {
01410   // Make sure the database is open
01411 
01412     if( CdbStatus::Success != open( )) return CdbStatus::Error;
01413 
01414   // Set up an iterator of persistent origin identifiers. We're going
01415   // to retranslate this iterator to the corresponding transient one.
01416   //
01417   // ATTENTION: This is not a memory leak - the created object
01418   //            will be destroyed by the iterator.
01419 
01420     theItr = CdbItr<unsigned short>( new CdbRooRoOriginItr( _masterRegistryPtr->originCollection( )->iterator_identifiers( )));
01421 
01422     return CdbStatus::Success;
01423 }
01424 
01425 CdbStatus
01426 CdbRooRoDatabase::findOrigin( CdbOriginPtr& thePtr,
01427                               const char*   theName )
01428 {
01429     assert( 0 != theName );
01430 
01431   // Make sure the database is open
01432 
01433     if( CdbStatus::Success != open( )) return CdbStatus::Error;
01434 
01435   // Try to find a persistent object for specified origin. If not found then
01436   // return the whatever status is obtained.
01437 
01438     CdbCPtr< CdbRooRoOriginR > persistentOriginPtr;
01439     CdbStatus                  result = _masterRegistryPtr->originCollection( )->find( theName,
01440                                                                                        persistentOriginPtr );
01441     if( CdbStatus::Success != result ) return result;
01442 
01443   // DESIGN NOTE: We need to construct a smart pointer against a clone since
01444   //              we don't know a smart pointer pointing to the current
01445   //              instance, therefore we can't guarantee the lifetime
01446   //              of the current instance.
01447   //
01448   // NOTE: The above corrected parameters object is used.
01449 
01450     thePtr = new CdbRooRoOrigin( CdbDatabasePtr( this->clone( )),
01451                                  persistentOriginPtr );
01452 
01453     return CdbStatus::Success;
01454 }
01455 
01456 CdbStatus
01457 CdbRooRoDatabase::findOrigin( CdbOriginPtr&  thePtr,
01458                               unsigned short theId )
01459 {
01460   // Make sure the database is open
01461 
01462     if( CdbStatus::Success != open( )) return CdbStatus::Error;
01463 
01464   // Try to find a persistent object for specified origin. If not found then
01465   // return the whatever status is obtained.
01466 
01467     CdbCPtr< CdbRooRoOriginR > persistentOriginPtr;
01468     CdbStatus                  result = _masterRegistryPtr->originCollection( )->find( theId,
01469                                                                                        persistentOriginPtr );
01470     if( CdbStatus::Success != result ) return result;
01471 
01472   // DESIGN NOTE: We need to construct a smart pointer against a clone since
01473   //              we don't know a smart pointer pointing to the current
01474   //              instance, therefore we can't guarantee the lifetime
01475   //              of the current instance.
01476   //
01477   // NOTE: The above corrected parameters object is used.
01478 
01479     thePtr = new CdbRooRoOrigin( CdbDatabasePtr( this->clone( )),
01480                                  persistentOriginPtr );
01481 
01482     return CdbStatus::Success;
01483 }
01484 
01485 /////////////////
01486 // End Of File //
01487 /////////////////

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