00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbBdbShared/CdbBdbSRegistryP.hh"
00012 #include "CdbBdbShared/CdbBdbSUtils.hh"
00013 #include "CdbBdbShared/CdbBdbSOriginP.hh"
00014 #include "CdbBdbShared/CdbBdbSSimpleClusterP.hh"
00015 #include "CdbBdbShared/CdbBdbSViewP.hh"
00016 #include "CdbBdbShared/CdbBdbSFolderP.hh"
00017 #include "CdbBdbShared/CdbBdbSConditionAtFolderP.hh"
00018 #include "CdbBdbShared/CdbBdbSConditionP.hh"
00019
00020 #include "CdbBase/CdbPathName.hh"
00021
00022 #include "BdbClustering/BdbCondIndexClusteringHint.hh"
00023
00024 #include <assert.h>
00025 #include <stdio.h>
00026
00027 #include <string>
00028 #include <vector>
00029 using std::cout;
00030 using std::endl;
00031 using std::ostream;
00032
00033 static const char* databaseCoreName = "con_cdb_database_";
00034 static const char* masterDatabaseName = "con_cdb_database";
00035 static const char* systemContainerName = "System";
00036 static const char* systemRegistryName = "Registry";
00037
00038 static const char* mainViewName = "main";
00039
00040 CdbBdbSRegistryP::CdbBdbSRegistryP( d_UShort theOriginId,
00041 const char* theDescription,
00042 const BdbTime& theCreationTime,
00043 const BdbTime& theId,
00044 bool hasLocalCollectionsFlag ) :
00045 _originId(theOriginId),
00046 _description(theDescription),
00047 _created(theCreationTime),
00048 _id(theId),
00049 _hasLocalCollections(hasLocalCollectionsFlag),
00050 _conditionCollectionRef(0),
00051 _viewCollectionRef(0),
00052 _clusterCollectionRef(0),
00053 _conditionRallocatorRef(0),
00054 _viewRallocatorRef(0),
00055 _clusterRallocatorRef(0)
00056 {
00057 assert( 0 != theDescription );
00058 assert(( BdbTime::minusInfinity != theCreationTime ) && ( BdbTime::plusInfinity != theCreationTime ));
00059 assert(( BdbTime::minusInfinity != theId ) && ( BdbTime::plusInfinity != theId ));
00060
00061
00062
00063
00064
00065
00066 if( _hasLocalCollections ) {
00067
00068 _conditionCollectionRef = new( ooThis( )) CdbBdbSConditionCollectionP( );
00069 _viewCollectionRef = new( ooThis( )) CdbBdbSViewCollectionP ( );
00070 _clusterCollectionRef = new( ooThis( )) CdbBdbSClusterCollectionP ( );
00071
00072 _conditionRallocatorRef = new( ooThis( )) CdbBdbSRallocatorP< d_UShort >( );
00073 _viewRallocatorRef = new( ooThis( )) CdbBdbSRallocatorP< d_UShort >( );
00074 _clusterRallocatorRef = new( ooThis( )) CdbBdbSRallocatorP< d_UShort >( );
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 {
00134 CdbStatus result;
00135
00136 const d_UShort vId = 0;
00137
00138 result = _viewRallocatorRef->force( vId );
00139 assert( CdbStatus::Success == result );
00140
00141
00142
00143 BdbRef(CdbBdbSViewP) viewRef =
00144 new( _viewCollectionRef ) CdbBdbSViewP( mainViewName,
00145 vId,
00146 "This is a special view. It was created automatically when initializing the current database",
00147 theCreationTime,
00148 BdbTime::minusInfinity,
00149 BdbTime::plusInfinity,
00150 0 );
00151 assert( ! BdbIsNull(viewRef));
00152
00153
00154
00155 result = _viewCollectionRef->insert( viewRef );
00156 assert( CdbStatus::Success == result );
00157 }
00158 }
00159
00160
00161
00162 BdbHandle(BdbContObj) cH;
00163 ooThis( ).containedIn( cH );
00164
00165 BdbStatus status;
00166 status = ooThis( ).nameObj( cH,
00167 systemRegistryName );
00168 assert( BdbcSuccess == status );
00169 }
00170
00171 CdbBdbSRegistryP::~CdbBdbSRegistryP( )
00172 {
00173 if( ! BdbIsNull(_conditionCollectionRef)) BdbDelete(_conditionCollectionRef);
00174 if( ! BdbIsNull(_viewCollectionRef)) BdbDelete(_viewCollectionRef);
00175 if( ! BdbIsNull(_clusterCollectionRef)) BdbDelete(_clusterCollectionRef);
00176
00177 if( ! BdbIsNull(_conditionRallocatorRef)) BdbDelete(_conditionRallocatorRef);
00178 if( ! BdbIsNull(_viewRallocatorRef)) BdbDelete(_viewRallocatorRef);
00179 if( ! BdbIsNull(_clusterRallocatorRef)) BdbDelete(_clusterRallocatorRef);
00180 }
00181
00182 const char*
00183 CdbBdbSRegistryP::defaultDbIdRange( )
00184 {
00185 return "default";
00186 }
00187
00188 d_UShort
00189 CdbBdbSRegistryP::originId( ) const
00190 {
00191 return _originId;
00192 }
00193
00194 ooString(32)
00195 CdbBdbSRegistryP::description( ) const
00196 {
00197 return _description;
00198 }
00199
00200 BdbTime
00201 CdbBdbSRegistryP::created( ) const
00202 {
00203 return _created;
00204 }
00205
00206 BdbTime
00207 CdbBdbSRegistryP::id( ) const
00208 {
00209 return _id;
00210 }
00211
00212 bool
00213 CdbBdbSRegistryP::hasLocalCollections( ) const
00214 {
00215 return _hasLocalCollections;
00216 }
00217
00218 BdbRef(CdbBdbSConditionCollectionP)
00219 CdbBdbSRegistryP::conditionCollection( ) const
00220 {
00221 return _conditionCollectionRef;
00222 }
00223
00224 BdbRef(CdbBdbSViewCollectionP)
00225 CdbBdbSRegistryP::viewCollection( ) const
00226 {
00227 return _viewCollectionRef;
00228 }
00229
00230 BdbRef(CdbBdbSClusterCollectionP)
00231 CdbBdbSRegistryP::clusterCollection( ) const
00232 {
00233 return _clusterCollectionRef;
00234 }
00235
00236 BdbRef(CdbBdbSRallocatorP< d_UShort >)
00237 CdbBdbSRegistryP::conditionRallocator( ) const
00238 {
00239 return _conditionRallocatorRef;
00240 }
00241
00242 BdbRef(CdbBdbSRallocatorP< d_UShort >)
00243 CdbBdbSRegistryP::viewRallocator( ) const
00244 {
00245 return _viewRallocatorRef;
00246 }
00247
00248 BdbRef(CdbBdbSRallocatorP< d_UShort >)
00249 CdbBdbSRegistryP::clusterRallocator( ) const
00250 {
00251 return _clusterRallocatorRef;
00252 }
00253
00254 void
00255 CdbBdbSRegistryP::dump( ostream& o ) const
00256 {
00257 o << " ORIGIN ID: " << _originId << endl
00258 << " DESCRIPTION: " << _description.head( ) << endl
00259 << " CREATED: " << _created << endl
00260 << " ID: " << _id << endl
00261 << " IS MASTER: " << ( isMaster( ) ? "Yes" : "No" ) << endl
00262 << "HAS LOCAL COLLECTIONS: " << ( _hasLocalCollections ? "Yes" : "No" ) << endl;
00263 }
00264
00265 CdbStatus
00266 CdbBdbSRegistryP::updateMainView( )
00267 {
00268 const char* errorStr = "CdbBdbSRegistryP::updateMainView() - ERROR.";
00269
00270 CdbStatus result = CdbStatus::Error;
00271 do {
00272
00273
00274
00275 BdbRef(CdbBdbSViewP) viewRef;
00276 {
00277 if( BdbIsNull(_viewCollectionRef)) {
00278 result = CdbStatus::NotFound;
00279 break;
00280 }
00281 if( CdbStatus::Success != _viewCollectionRef->find( mainViewName, viewRef )) {
00282 cout << errorStr << endl
00283 << " The main view does not exist in the local database." << endl
00284 << " The database may not be properly initialized/loaded." << endl;
00285 break;
00286 }
00287 }
00288 assert( !BdbIsNull(viewRef));
00289
00290
00291
00292 if( viewRef->isFrozen( )) {
00293 cout << errorStr << endl
00294 << " The main view is found to be in the 'frozen' state. This should never happen." << endl
00295 << " The database may not be properly initialized/loaded." << endl;
00296 break;
00297 }
00298
00299
00300
00301 if( CdbStatus::Success != viewRef->setDefaultConfig( 0 )) {
00302 cout << errorStr << endl
00303 << " Failed to reset the default configuration at the main view." << endl;
00304 break;
00305 }
00306
00307
00308
00309
00310
00311
00312
00313 BdbRef(CdbBdbSFolderP) rootFolderRef = viewRef->rootFolder( );
00314 assert( !BdbIsNull(rootFolderRef));
00315 {
00316 CdbItr<const char*> fItr;
00317 if( CdbStatus::Success != rootFolderRef->folderIterator( fItr )) {
00318 cout << errorStr << endl
00319 << " Failed to set up an iterator of subfolders at the level of the 'root' folder." << endl;
00320 break;
00321 }
00322 std::vector<std::string> folders;
00323 while( fItr.next( )) {
00324 std::string fPathName = std::string( rootFolderRef->name( )) + std::string( fItr.value( ));
00325 folders.push_back( fPathName.c_str( ));
00326 }
00327 bool failed = false;
00328 for( std::vector<std::string>::iterator i = folders.begin( ); i != folders.end( ); ++i ) {
00329
00330 bool forceRecursiveRemovalFlag = true;
00331 const char* f = (*i).c_str( );
00332 if( CdbStatus::Success != viewRef->removeFolder( f, forceRecursiveRemovalFlag )) {
00333 cout << errorStr << endl
00334 << " Failed to remove folder: \"" << f << "\"" << endl;
00335 failed = true;
00336 break;
00337 }
00338 }
00339 if( failed ) break;
00340 }
00341 {
00342 CdbItr<const char*> cItr;
00343 if( CdbStatus::Success != rootFolderRef->conditionIterator( cItr )) {
00344 cout << errorStr << endl
00345 << " Failed to set up an iterator of conditions at the level of the 'root' folder." << endl;
00346 break;
00347 }
00348 std::vector<std::string> conditions;
00349 while( cItr.next( )) {
00350 const char* cName = cItr.value( );
00351 std::string cPathName = std::string( rootFolderRef->name( )) + std::string( cName );
00352 conditions.push_back( cPathName.c_str( ));
00353 }
00354 bool failed = false;
00355 for( std::vector<std::string>::iterator i = conditions.begin( ); i != conditions.end( ); ++i ) {
00356
00357 const char* c = (*i).c_str( );
00358 if( CdbStatus::Success != viewRef->removeCondition( c )) {
00359 cout << errorStr << endl
00360 << " Failed to remove condition: \"" << c << "\"" << endl;
00361 failed = true;
00362 break;
00363 }
00364 }
00365 if( failed ) break;
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 BdbTime creationTime( BdbTime::now( ));
00384
00385 if( CdbStatus::Success != viewRef->createFolder( rootFolderRef->name( ),
00386 "NAMES_ONLY",
00387 "This folder begins a branch of names of persistent components only.",
00388 creationTime )) {
00389 cout << errorStr << endl
00390 << " Failed to create new folder." << endl;
00391 break;
00392 }
00393 if( CdbStatus::Success != viewRef->createFolder( rootFolderRef->name( ),
00394 "NAMES_AND_IDS",
00395 "This folder begins a branch of both names and identifiers of persistent components.",
00396 creationTime )) {
00397 cout << errorStr << endl
00398 << " Failed to create new folder." << endl;
00399 break;
00400 }
00401 std::string namesOnlyPath = std::string( rootFolderRef->name( )) + std::string( "NAMES_ONLY" );
00402 std::string namesAndIdsPath = std::string( rootFolderRef->name( )) + std::string( "NAMES_AND_IDS" );
00403
00404 BdbHandle(CdbBdbSRegistryP) masterRegistryH;
00405 if( CdbStatus::Success != findMaster( masterRegistryH )) {
00406 cout << errorStr << endl
00407 << " Failed to find the master registry." << endl
00408 << " The database may not be properly initialized/loaded." << endl;
00409 break;
00410 }
00411
00412 BdbHandle(CdbBdbSOriginCollectionP) originCollectionH;
00413 originCollectionH = masterRegistryH->originCollection( );
00414 if( BdbIsNull(originCollectionH)) {
00415 cout << errorStr << endl
00416 << " Failed to find the collection of origins at the master registry." << endl
00417 << " The database may not be properly initialized/loaded." << endl;
00418 break;
00419 }
00420
00421 bool failed = false;
00422
00423 CdbBdbSOriginCollectionP::IteratorOfIdentifiers originIdItr = originCollectionH->iterator_identifiers( );
00424 while( originIdItr.next( )) {
00425
00426 d_UShort originId = originIdItr.value( );
00427
00428
00429
00430
00431
00432 BdbRef(CdbBdbSOriginP) originRef;
00433 {
00434 CdbStatus s = originCollectionH->find( originId, originRef );
00435 if( CdbStatus::NotFound == s ) {
00436
00437
00438
00439
00440 continue;
00441
00442 } else if( CdbStatus::Success == s ) {
00443
00444
00445
00446
00447 ;
00448
00449 } else {
00450 cout << errorStr << endl
00451 << " Failed to find the origin for origin ID=" << originId << endl
00452 << " The database may not be properly initialized/loaded." << endl;
00453 failed = true;
00454 break;
00455 }
00456 }
00457
00458
00459
00460
00461
00462 BdbHandle(CdbBdbSRegistryP) registryH;
00463 {
00464 CdbStatus s = findByOrigin( registryH, originId );
00465 if( CdbStatus::NotFound == s ) {
00466
00467
00468
00469
00470 continue;
00471
00472 } else if( CdbStatus::Success == s ) {
00473
00474
00475
00476
00477 ;
00478
00479 } else {
00480 cout << errorStr << endl
00481 << " Failed to find the registry for the origin ID=" << originId << endl
00482 << " The database may not be properly initialized/loaded." << endl;
00483 failed = true;
00484 break;
00485 }
00486 }
00487
00488
00489
00490 char originIdStr[12];
00491 sprintf( originIdStr, "%u", originId );
00492
00493 std::string originNameOnly = originRef->name( ).head( );
00494 std::string originNameAndId = std::string( originIdStr ) + std::string( ":" ) + originNameOnly;
00495
00496 if( CdbStatus::Success != viewRef->createFolder( namesOnlyPath.c_str( ),
00497 originNameOnly.c_str( ),
00498 "This folder corresponds to an origin.",
00499 creationTime )) {
00500 cout << errorStr << endl
00501 << " Failed to create new folder." << endl;
00502 failed = true;
00503 break;
00504 }
00505 if( CdbStatus::Success != viewRef->createFolder( namesAndIdsPath.c_str( ),
00506 originNameAndId.c_str( ),
00507 "This folder corresponds to an origin.",
00508 creationTime )) {
00509 cout << errorStr << endl
00510 << " Failed to create new folder." << endl;
00511 failed = true;
00512 break;
00513 }
00514 std::string originNamesOnlyPath = namesOnlyPath + std::string( CdbPathName::separator( )) + originNameOnly;
00515 std::string originNamesAndIdsPath = namesAndIdsPath + std::string( CdbPathName::separator( )) + originNameAndId;
00516
00517
00518
00519 const char* conditionTypeName[2] = { "REGULAR", "PARTITIONABLE" };
00520 bool isPartitionable [2] = { false, true };
00521
00522 for( int i = 0; i < 2; ++i ) {
00523
00524
00525
00526
00527 BdbRef(CdbBdbSClusterCollectionP) clusterCollectionRef;
00528 {
00529 if( isPartitionable[i] ) {
00530 clusterCollectionRef = registryH->pClusterCollection( );
00531 } else {
00532 clusterCollectionRef = registryH->clusterCollection( );
00533 }
00534 if( BdbIsNull( clusterCollectionRef )) {
00535
00536
00537
00538
00539 continue;
00540 }
00541 }
00542
00543
00544
00545 if( CdbStatus::Success != viewRef->createFolder( originNamesOnlyPath.c_str( ),
00546 conditionTypeName[i],
00547 "This folder corresponds to a certain type of conditions.",
00548 creationTime )) {
00549 cout << errorStr << endl
00550 << " Failed to create new folder." << endl;
00551 failed = true;
00552 break;
00553 }
00554 if( CdbStatus::Success != viewRef->createFolder( originNamesAndIdsPath.c_str( ),
00555 conditionTypeName[i],
00556 "This folder corresponds to a certain type of conditions.",
00557 creationTime )) {
00558 cout << errorStr << endl
00559 << " Failed to create new folder." << endl;
00560 failed = true;
00561 break;
00562 }
00563 std::string typeNamesOnlyPath = originNamesOnlyPath + std::string( CdbPathName::separator( )) + std::string( conditionTypeName[i] );
00564 std::string typeNamesAndIdsPath = originNamesAndIdsPath + std::string( CdbPathName::separator( )) + std::string( conditionTypeName[i] );
00565
00566
00567
00568
00569 CdbBdbSClusterCollectionP::IteratorOfIdentifiers clusterItr = clusterCollectionRef->iterator_identifiers( );
00570 while( clusterItr.next( )) {
00571
00572 d_UShort clusterId = clusterItr.value( );
00573
00574 BdbRef(CdbBdbSClusterP) clusterRef;
00575 if( CdbStatus::Success != clusterCollectionRef->find( clusterId, clusterRef )) {
00576 cout << errorStr << endl
00577 << " Failed to create new folder." << endl;
00578 failed = true;
00579 break;
00580 }
00581
00582
00583
00584 char clusterIdStr[12];
00585 sprintf( clusterIdStr, "%u", clusterId );
00586
00587 std::string clusterNameOnly = clusterRef->name( ).head( );
00588 std::string clusterNameAndId = std::string( clusterIdStr ) + std::string( ":" ) + clusterNameOnly;
00589
00590 if( CdbStatus::Success != viewRef->createFolder( typeNamesOnlyPath.c_str( ),
00591 clusterNameOnly.c_str( ),
00592 "This folder corresponds to a cluster of conditions.",
00593 creationTime )) {
00594 cout << errorStr << endl
00595 << " Failed to create new folder." << endl;
00596 failed = true;
00597 break;
00598 }
00599 if( CdbStatus::Success != viewRef->createFolder( typeNamesAndIdsPath.c_str( ),
00600 clusterNameAndId.c_str( ),
00601 "This folder corresponds to a cluster of conditions.",
00602 creationTime )) {
00603 cout << errorStr << endl
00604 << " Failed to create new folder." << endl;
00605 failed = true;
00606 break;
00607 }
00608 std::string clusterNamesOnlyPath = typeNamesOnlyPath + std::string( CdbPathName::separator( )) + clusterNameOnly;
00609 std::string clusterNamesAndIdsPath = typeNamesAndIdsPath + std::string( CdbPathName::separator( )) + clusterNameAndId;
00610
00611
00612
00613
00614 CdbItr< BdbRef(CdbBdbSConditionP)> conditionItr;
00615 if( CdbStatus::Success != clusterRef->iterator( conditionItr )) {
00616 cout << errorStr << endl
00617 << " Failed to set up an iterator of conditions at the current cluster." << endl;
00618 failed = true;
00619 break;
00620 }
00621 while( conditionItr.next( )) {
00622
00623 BdbRef(CdbBdbSConditionP) conditionRef = conditionItr.value( );
00624
00625 d_UShort conditionId = conditionRef->id( );
00626
00627 char conditionIdStr[12];
00628 sprintf( conditionIdStr, "%u", conditionId );
00629
00630 std::string conditionNameOnly = conditionRef->name( ).head( );
00631 std::string conditionNameAndId = std::string( conditionIdStr ) + std::string( ":" ) + conditionNameOnly;
00632
00633 CdbBdbSId extendedConditionId( registryH->originId( ), conditionId );
00634
00635 if( CdbStatus::Success != viewRef->createCondition( clusterNamesOnlyPath.c_str( ),
00636 conditionNameOnly.c_str( ),
00637 "This condition was created automatically.",
00638 creationTime,
00639 extendedConditionId )) {
00640 cout << errorStr << endl
00641 << " Failed to create new condition." << endl;
00642 failed = true;
00643 break;
00644 }
00645 if( CdbStatus::Success != viewRef->createCondition( clusterNamesAndIdsPath.c_str( ),
00646 conditionNameAndId.c_str( ),
00647 "This condition was created automatically.",
00648 creationTime,
00649 extendedConditionId )) {
00650 cout << errorStr << endl
00651 << " Failed to create new condition." << endl;
00652 failed = true;
00653 break;
00654 }
00655
00656
00657 }
00658 if( failed ) break;
00659
00660
00661 }
00662 if( failed ) break;
00663
00664
00665 }
00666 if( failed ) break;
00667
00668
00669 }
00670 if( failed ) break;
00671
00672
00673
00674 result = CdbStatus::Success;
00675
00676 } while( false );
00677
00678 return result;
00679 }
00680
00681 CdbStatus
00682 CdbBdbSRegistryP::findMaster( BdbHandle(CdbBdbSRegistryP)& theRegistryH,
00683 const BdbMode theOpenMode )
00684 {
00685 CdbStatus result = CdbStatus::NotFound;
00686 do {
00687
00688
00689
00690 BdbHandle(BdbContObj) cH;
00691
00692 if( CdbStatus::Success != CdbBdbSUtils::findContainer( cH,
00693 masterDatabaseName,
00694 systemContainerName,
00695 theOpenMode )) {
00696 break;
00697 }
00698
00699
00700
00701 BdbHandle(CdbBdbSRegistryP) registryH;
00702
00703 BdbStatus status = registryH.lookupObj( cH,
00704 systemRegistryName,
00705 theOpenMode );
00706 if(( BdbcSuccess != status ) || BdbIsNull(registryH)) {
00707 break;
00708 }
00709
00710
00711
00712 theRegistryH = registryH;
00713
00714 result = CdbStatus::Success;
00715
00716 } while( false );
00717
00718 return result;
00719 }
00720
00721 CdbStatus
00722 CdbBdbSRegistryP::findLocal( BdbHandle(CdbBdbSRegistryP)& theRegistryH,
00723 const BdbMode theOpenMode )
00724 {
00725 const char* errorStr = "CdbBdbSRegistryP::findLocal() - ERROR.";
00726
00727 CdbStatus result = CdbStatus::NotFound;
00728 do {
00729
00730
00731
00732 BdbHandle(CdbBdbSRegistryP) masterRegistryH;
00733 if( CdbStatus::Success != findMaster( masterRegistryH )) {
00734 break;
00735 }
00736
00737
00738
00739 BdbRef(CdbBdbSOriginCollectionP) originCollRef;
00740 originCollRef = masterRegistryH->originCollection( );
00741 assert( ! BdbIsNull(originCollRef));
00742
00743 BdbRef( CdbBdbSOriginP ) originRef;
00744 if( CdbStatus::Success != originCollRef->find( masterRegistryH->originId( ),
00745 originRef )) {
00746 cout << errorStr << endl
00747 << " Failed to obtain the origin information for the master registry." << endl
00748 << " The Condition/DB might be inproperly initialized or broken." << endl;
00749 result = CdbStatus::Error;
00750 break;
00751 }
00752 std::string masterRangeName;
00753 {
00754 ooString(32) dbidrange = originRef->dbidrange( );
00755 assert( 0 != dbidrange.head( ));
00756 masterRangeName = dbidrange.head( );
00757 }
00758
00759
00760
00761 std::string localRangeName;
00762
00763 if( CdbStatus::Success != CdbBdbSUtils::getLocalDbIdRange( localRangeName )) {
00764 cout << errorStr << endl
00765 << " Failed to determine the local DBID range. This may be an indication" << endl
00766 << " that the Condition/DB federation has not been properly initialized." << endl;
00767 result = CdbStatus::Error;
00768 break;
00769 }
00770
00771
00772
00773
00774 if( masterRangeName == localRangeName ) {
00775 theRegistryH = masterRegistryH;
00776 } else {
00777
00778
00779
00780
00781
00782 std::string localDatabaseName = databaseCoreName + localRangeName;
00783
00784 BdbHandle(BdbContObj) cH;
00785
00786 if( CdbStatus::Success != CdbBdbSUtils::findContainer( cH,
00787 localDatabaseName.c_str( ),
00788 systemContainerName,
00789 theOpenMode )) {
00790 break;
00791 }
00792
00793
00794
00795 BdbHandle(CdbBdbSRegistryP) localRegistryH;
00796
00797 BdbStatus status = localRegistryH.lookupObj( cH,
00798 systemRegistryName,
00799 theOpenMode );
00800 if(( BdbcSuccess != status ) || BdbIsNull(localRegistryH)) {
00801 break;
00802 }
00803 theRegistryH = localRegistryH;
00804 }
00805
00806
00807
00808 result = CdbStatus::Success;
00809
00810 } while( false );
00811
00812 return result;
00813 }
00814
00815 CdbStatus
00816 CdbBdbSRegistryP::findByOrigin( BdbHandle(CdbBdbSRegistryP)& theRegistryH,
00817 d_UShort theOriginId,
00818 const BdbMode theOpenMode )
00819 {
00820 const char* errorStr = "CdbBdbSRegistryP::findByOrigin(id) - ERROR.";
00821
00822 CdbStatus result = CdbStatus::NotFound;
00823 do {
00824
00825
00826
00827 BdbHandle(CdbBdbSRegistryP) masterRegistryH;
00828 if( CdbStatus::Success != findMaster( masterRegistryH )) {
00829 break;
00830 }
00831
00832
00833
00834 if( theOriginId == masterRegistryH->originId( )) {
00835 theRegistryH = masterRegistryH;
00836 } else {
00837
00838
00839
00840
00841 BdbRef(CdbBdbSOriginCollectionP) originCollRef;
00842 originCollRef = masterRegistryH->originCollection( );
00843 assert( ! BdbIsNull(originCollRef));
00844
00845 BdbRef( CdbBdbSOriginP ) originRef;
00846 if( CdbStatus::Success != originCollRef->find( theOriginId,
00847 originRef )) {
00848 cout << errorStr << endl
00849 << " Failed to obtain the origin information for the registry." << endl
00850 << " The Condition/DB might be inproperly initialized or broken." << endl;
00851 result = CdbStatus::Error;
00852 break;
00853 }
00854 std::string rangeName;
00855 {
00856 ooString(32) dbidrange = originRef->dbidrange( );
00857 assert( 0 != dbidrange.head( ));
00858 rangeName = dbidrange.head( );
00859 }
00860
00861
00862
00863 std::string databaseName = databaseCoreName + rangeName;
00864
00865 BdbHandle(BdbContObj) cH;
00866
00867 if( CdbStatus::Success != CdbBdbSUtils::findContainer( cH,
00868 databaseName.c_str( ),
00869 systemContainerName,
00870 theOpenMode )) {
00871 break;
00872 }
00873
00874
00875
00876 BdbHandle(CdbBdbSRegistryP) localRegistryH;
00877
00878 BdbStatus status = localRegistryH.lookupObj( cH,
00879 systemRegistryName,
00880 theOpenMode );
00881 if(( BdbcSuccess != status ) || BdbIsNull(localRegistryH)) {
00882 break;
00883 }
00884 theRegistryH = localRegistryH;
00885 }
00886
00887
00888
00889 result = CdbStatus::Success;
00890
00891 } while( false );
00892
00893 return result;
00894 }
00895
00896 CdbStatus
00897 CdbBdbSRegistryP::findByOrigin( BdbHandle(CdbBdbSRegistryP)& theRegistryH,
00898 const char* theOriginName,
00899 const BdbMode theOpenMode )
00900 {
00901 const char* errorStr = "CdbBdbSRegistryP::findByOrigin(name) - ERROR.";
00902
00903 CdbStatus result = CdbStatus::NotFound;
00904 do {
00905
00906
00907
00908 if( 0 == theOriginName ) {
00909 cout << " Null pointer passed where the origin name was expected." << endl;
00910 break;
00911 }
00912
00913
00914
00915 BdbHandle(CdbBdbSRegistryP) masterRegistryH;
00916 if( CdbStatus::Success != findMaster( masterRegistryH )) {
00917 break;
00918 }
00919
00920
00921
00922
00923 if( 0 == strcmp( theOriginName, CdbBdbSOriginP::type2name( CdbBdbSOriginP::MASTER ))) {
00924 theRegistryH = masterRegistryH;
00925 } else {
00926
00927
00928
00929
00930 BdbRef(CdbBdbSOriginCollectionP) originCollRef;
00931 originCollRef = masterRegistryH->originCollection( );
00932 assert( ! BdbIsNull(originCollRef));
00933
00934 BdbRef( CdbBdbSOriginP ) originRef;
00935 if( CdbStatus::Success != originCollRef->find( theOriginName,
00936 originRef )) {
00937 cout << errorStr << endl
00938 << " Failed to obtain the origin information for the registry." << endl
00939 << " The Condition/DB might be inproperly initialized or broken." << endl;
00940 result = CdbStatus::Error;
00941 break;
00942 }
00943 std::string rangeName;
00944 {
00945 ooString(32) dbidrange = originRef->dbidrange( );
00946 assert( 0 != dbidrange.head( ));
00947 rangeName = dbidrange.head( );
00948 }
00949
00950
00951
00952 std::string databaseName = databaseCoreName + rangeName;
00953
00954 BdbHandle(BdbContObj) cH;
00955
00956 if( CdbStatus::Success != CdbBdbSUtils::findContainer( cH,
00957 databaseName.c_str( ),
00958 systemContainerName,
00959 theOpenMode )) {
00960 break;
00961 }
00962
00963
00964
00965 BdbHandle(CdbBdbSRegistryP) localRegistryH;
00966
00967 BdbStatus status = localRegistryH.lookupObj( cH,
00968 systemRegistryName,
00969 theOpenMode );
00970 if(( BdbcSuccess != status ) || BdbIsNull(localRegistryH)) {
00971 break;
00972 }
00973 theRegistryH = localRegistryH;
00974 }
00975
00976
00977
00978 result = CdbStatus::Success;
00979
00980 } while( false );
00981
00982 return result;
00983 }
00984
00985
00986
00987