00001
00002
00003
00004
00005
00006
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
00046
00047
00048
00049
00050
00051
00052
00053 class CdbRooRoPartitionItr : public CdbItr<unsigned short>::InterfaceType {
00054
00055 private:
00056
00057
00058
00059 CdbRooRoPartitionItr( );
00060
00061 public:
00062
00063
00064
00065 CdbRooRoPartitionItr( const CdbItr<UShort_t>& theInputItr ) : _itr(theInputItr) { }
00066
00067
00068
00069 CdbRooRoPartitionItr( const CdbRooRoPartitionItr& theItr ) : _itr(theItr._itr) { }
00070
00071
00072
00073 CdbRooRoPartitionItr& operator=( const CdbRooRoPartitionItr& theItr )
00074 {
00075 if( this != &theItr ) {
00076 _itr = theItr._itr;
00077 }
00078 return *this;
00079 }
00080
00081
00082
00083 virtual ~CdbRooRoPartitionItr( ) { }
00084
00085
00086
00087
00088
00089
00090
00091
00092 virtual CdbStatus reset( ) { return _itr.reset( ); }
00093
00094
00095
00096
00097
00098
00099
00100 virtual bool next( ) { return _itr.next( ); }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 virtual ValueType value( ) { return _itr.value( ); }
00112
00113
00114
00115
00116
00117
00118
00119 virtual bool isValid( ) { return _itr.isValid( ); }
00120
00121
00122
00123
00124
00125 virtual InterfaceType* clone( ) const { return new CdbRooRoPartitionItr( *this ); }
00126
00127 private:
00128
00129 CdbItr<UShort_t> _itr;
00130 };
00131
00132
00133
00134
00135
00136
00137
00138 class CdbRooRoPartition : public CdbPartition {
00139
00140 private:
00141
00142
00143
00144 CdbRooRoPartition( );
00145
00146
00147
00148 CdbRooRoPartition( const CdbRooRoPartition& thePartition );
00149
00150
00151
00152 CdbRooRoPartition& operator=( const CdbRooRoPartition& thePartition );
00153
00154 public:
00155
00156
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
00175
00176 virtual ~CdbRooRoPartition( ) { }
00177
00178
00179
00180
00181
00182
00183
00184 virtual BdbTime endInsertion( ) const { return _partitionPtr->cell( ).endInsertion( ); }
00185
00186
00187
00188
00189
00190
00191
00192 virtual BdbTime modified( ) const { return _partitionPtr->modified( ); }
00193
00194
00195
00196
00197
00198
00199
00200 virtual bool isClosed( ) const { return _partitionPtr->isClosed( ); }
00201
00202
00203
00204
00205
00206
00207
00208 virtual bool isInstantiated( ) const { return _partitionPtr->isInstantiated( ); }
00209
00210 private:
00211
00212 CdbCPtr< CdbRooRoPartitionR > _partitionPtr;
00213 };
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 class CdbRooRoOriginItr : public CdbItr<unsigned short>::InterfaceType {
00225
00226 private:
00227
00228
00229
00230 CdbRooRoOriginItr( );
00231
00232 public:
00233
00234
00235
00236 CdbRooRoOriginItr( const CdbItr<UShort_t>& theInputItr ) : _itr(theInputItr) { }
00237
00238
00239
00240 CdbRooRoOriginItr( const CdbRooRoOriginItr& theItr ) : _itr(theItr._itr) { }
00241
00242
00243
00244 CdbRooRoOriginItr& operator=( const CdbRooRoOriginItr& theItr )
00245 {
00246 if( this != &theItr ) {
00247 _itr = theItr._itr;
00248 }
00249 return *this;
00250 }
00251
00252
00253
00254 virtual ~CdbRooRoOriginItr( ) { }
00255
00256
00257
00258
00259
00260
00261
00262
00263 virtual CdbStatus reset( ) { return _itr.reset( ); }
00264
00265
00266
00267
00268
00269
00270
00271 virtual bool next( ) { return _itr.next( ); }
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 virtual ValueType value( ) { return _itr.value( ); }
00283
00284
00285
00286
00287
00288
00289
00290 virtual bool isValid( ) { return _itr.isValid( ); }
00291
00292
00293
00294
00295
00296 virtual InterfaceType* clone( ) const { return new CdbRooRoOriginItr( *this ); }
00297
00298 private:
00299
00300 CdbItr<UShort_t> _itr;
00301 };
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 class CdbRooRoOriginPropertyItr : public CdbItr<CdbProperty>::InterfaceType {
00313
00314 public:
00315
00316
00317
00318 CdbRooRoOriginPropertyItr( ) { }
00319
00320
00321
00322 CdbRooRoOriginPropertyItr( const CdbRooRoOriginPropertyItr& theItr ) { }
00323
00324
00325
00326 CdbRooRoOriginPropertyItr& operator=( const CdbRooRoOriginPropertyItr& theItr ) { return *this; }
00327
00328
00329
00330 virtual ~CdbRooRoOriginPropertyItr( ) { }
00331
00332
00333
00334
00335
00336
00337
00338
00339 virtual CdbStatus reset( ) { return CdbStatus::Success; }
00340
00341
00342
00343
00344
00345
00346
00347 virtual bool next( ) { return false; }
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 virtual ValueType value( )
00359 {
00360 assert( 0 );
00361 return CdbProperty( );
00362 }
00363
00364
00365
00366
00367
00368
00369
00370 virtual bool isValid( ) { return false; }
00371
00372
00373
00374
00375
00376 virtual InterfaceType* clone( ) const { return new CdbRooRoOriginPropertyItr( *this ); }
00377 };
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387 class CdbRooRoOrigin : public CdbOrigin {
00388
00389 private:
00390
00391
00392
00393 CdbRooRoOrigin( );
00394
00395
00396
00397 CdbRooRoOrigin( const CdbRooRoOrigin& theOrigin );
00398
00399
00400
00401 CdbRooRoOrigin& operator=( const CdbRooRoOrigin& theOrigin );
00402
00403 public:
00404
00405
00406
00407
00408
00409
00410
00411
00412 CdbRooRoOrigin( const CdbDatabasePtr& theDatabasePtr,
00413 const CdbCPtr< CdbRooRoOriginR >& thePersistentOriginPtr
00414 ) :
00415 CdbOrigin( theDatabasePtr,
00416 thePersistentOriginPtr->name( ).c_str( ),
00417 thePersistentOriginPtr->id( )),
00418 _persistentOriginPtr(thePersistentOriginPtr)
00419 { }
00420
00421
00422
00423
00424
00425 virtual ~CdbRooRoOrigin( ) { }
00426
00427
00428
00429
00430
00431
00432
00433 virtual BdbTime created( ) { return _persistentOriginPtr->created( ); }
00434
00435
00436
00437
00438
00439
00440
00441 virtual std::string description( ) { return _persistentOriginPtr->description( ); }
00442
00443
00444
00445
00446
00447
00448
00449 virtual bool isLocal( ) const
00450 {
00451
00452
00453 return parent( )->localOrigin( )->id( ) == _persistentOriginPtr->id( );
00454 }
00455
00456
00457
00458
00459
00460
00461
00462 virtual bool isInstantiated( ) const
00463 {
00464
00465
00466
00467
00468
00469 CdbCPtr< CdbRooRoRegistry > ptr;
00470 return CdbStatus::Success == CdbRooRoRegistry::findByOrigin( ptr,
00471 _persistentOriginPtr->id( ));
00472 }
00473
00474
00475
00476
00477
00478
00479
00480 virtual bool isMaster( ) const { return _persistentOriginPtr->type( ) == CdbRooRoOriginR::MASTER; }
00481
00482
00483
00484
00485
00486
00487
00488 virtual bool isSlave( ) const { return _persistentOriginPtr->type( ) == CdbRooRoOriginR::SLAVE; }
00489
00490
00491
00492
00493
00494
00495
00496 virtual bool isTest( ) const { return _persistentOriginPtr->type( ) == CdbRooRoOriginR::TEST; }
00497
00498
00499
00500
00501
00502
00503
00504 virtual CdbStatus propertyIterator( CdbItr<CdbProperty>& theItr )
00505 {
00506
00507
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
00522
00523
00524 CdbDatabase*
00525 CdbRooRoDatabase::clone( ) const
00526 {
00527
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
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
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
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
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
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
00652
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
00667
00668 std::string originName = compositeViewName.first( );
00669 std::string localViewName = compositeViewName.last( );
00670
00671
00672
00673 if( CdbStatus::Success != open( )) return CdbStatus::Error;
00674
00675
00676
00677
00678
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
00694
00695
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
00711
00712
00713 CdbId viewId( registryPtr->originId( ),
00714 persistentViewPtr->id( ));
00715
00716
00717
00718
00719
00720
00721
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
00740
00741 if( CdbStatus::Success != open( )) return CdbStatus::Error;
00742
00743
00744
00745
00746
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
00762
00763 CdbCPtr< CdbRooRoViewR > persistentViewPtr;
00764 CdbStatus result = registryPtr->viewCollection( )->find( theId.local,
00765 persistentViewPtr );
00766 if( CdbStatus::Success != result ) return result;
00767
00768
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
00788
00789
00790
00791
00792
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
00808
00809 if( CdbStatus::Success != open( )) return CdbStatus::Error;
00810
00811
00812
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
00827
00828 if( CdbStatus::Success != open( )) return CdbStatus::Error;
00829
00830
00831
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
00841
00842
00843 CdbCPtr< CdbRooRoRegistry > registryPtr;
00844 {
00845 if( CdbStatus::Success != ( result = CdbRooRoRegistry::findByOrigin( registryPtr,
00846 originId ))) {
00847 if( CdbStatus::NotFound == result ) {
00848
00849
00850
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
00863
00864
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
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
00891
00892 if( CdbStatus::Success != open( )) return CdbStatus::Error;
00893
00894
00895
00896
00897
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
00913
00914 CdbCPtr< CdbRooRoConditionR > persistentConditionPtr;
00915 CdbStatus result = registryPtr->conditionCollection( )->find( theId.local,
00916 persistentConditionPtr );
00917 if( CdbStatus::Success != result ) return result;
00918
00919
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
00935
00936
00937 CdbFolderPtr parentFolderPtr = 0;
00938 CdbRooRoConditionAtFolderR* persistentConditionAtFolderPtr = 0;
00939
00940
00941
00942
00943
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
00964
00965 if( CdbStatus::Success != open( )) return CdbStatus::Error;
00966
00967
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
00980
00981 std::string originName = thePhysicalName.first( );
00982 std::string localConditionName = thePhysicalName.last( );
00983
00984
00985
00986
00987
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
01003
01004 CdbCPtr< CdbRooRoConditionR > persistentConditionPtr;
01005 CdbStatus result = registryPtr->conditionCollection( )->find( localConditionName,
01006 persistentConditionPtr );
01007 if( CdbStatus::Success != result ) return result;
01008
01009
01010
01011
01012 CdbFolderPtr parentFolderPtr = 0;
01013 CdbRooRoConditionAtFolderR* persistentConditionAtFolderPtr = 0;
01014
01015
01016
01017
01018
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
01052
01053 if( CdbStatus::Success != open( )) return CdbStatus::Error;
01054
01055
01056
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
01070
01071 if( CdbStatus::Success != open( )) return CdbStatus::Error;
01072
01073
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
01092
01093
01094 CdbCPtr< CdbRooRoPartitionsLayoutR > pLayoutPtr = registryPtr->partitionsLayout( );
01095 if( pLayoutPtr.isNull( )) return CdbStatus::NotFound;
01096
01097
01098
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
01112
01113 if( CdbStatus::Success != open( )) return CdbStatus::Error;
01114
01115
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
01134
01135
01136 CdbCPtr< CdbRooRoPartitionsLayoutR > pLayoutPtr = registryPtr->partitionsLayout( );
01137 if( pLayoutPtr.isNull( )) return CdbStatus::NotFound;
01138
01139
01140
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
01154
01155 if( CdbStatus::Success != open( )) return CdbStatus::Error;
01156
01157
01158
01159
01160
01161
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
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
01203
01204
01205
01206
01207
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
01225
01226 if( CdbStatus::Success != open( )) return CdbStatus::Error;
01227
01228
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
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
01261
01262 CdbCPtr< CdbRooRoPartitionR > partitionPtr;
01263 {
01264 CdbStatus result = pLayoutPtr->find( thePartition,
01265 partitionPtr );
01266 if( CdbStatus::Success != result ) return result;
01267 }
01268
01269
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
01287
01288
01289
01290
01291
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
01309
01310 if( CdbStatus::Success != open( )) return CdbStatus::Error;
01311
01312
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
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
01345
01346 CdbCPtr< CdbRooRoPartitionR > partitionPtr;
01347 {
01348 CdbStatus result = pLayoutPtr->find( thePartition,
01349 partitionPtr );
01350 if( CdbStatus::Success != result ) return result;
01351 }
01352
01353
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
01371
01372
01373
01374
01375
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
01389
01390 if( CdbStatus::Success != open( )) {
01391 assert( 0 );
01392 return 0;
01393 }
01394
01395
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
01411
01412 if( CdbStatus::Success != open( )) return CdbStatus::Error;
01413
01414
01415
01416
01417
01418
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
01432
01433 if( CdbStatus::Success != open( )) return CdbStatus::Error;
01434
01435
01436
01437
01438 CdbCPtr< CdbRooRoOriginR > persistentOriginPtr;
01439 CdbStatus result = _masterRegistryPtr->originCollection( )->find( theName,
01440 persistentOriginPtr );
01441 if( CdbStatus::Success != result ) return result;
01442
01443
01444
01445
01446
01447
01448
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
01461
01462 if( CdbStatus::Success != open( )) return CdbStatus::Error;
01463
01464
01465
01466
01467 CdbCPtr< CdbRooRoOriginR > persistentOriginPtr;
01468 CdbStatus result = _masterRegistryPtr->originCollection( )->find( theId,
01469 persistentOriginPtr );
01470 if( CdbStatus::Success != result ) return result;
01471
01472
01473
01474
01475
01476
01477
01478
01479 thePtr = new CdbRooRoOrigin( CdbDatabasePtr( this->clone( )),
01480 persistentOriginPtr );
01481
01482 return CdbStatus::Success;
01483 }
01484
01485
01486
01487