00001
00002
00003
00004
00005
00006
00007
00008 #include "BaBar/BaBar.hh"
00009
00010 #include "CdbBdbWrapper/CdbBdbWDatabase.hh"
00011
00012 #include "CdbBase/Cdb.hh"
00013 #include "CdbBase/CdbView.hh"
00014 #include "CdbBase/CdbId.hh"
00015 #include "CdbBase/CdbCompositeName.hh"
00016 #include "CdbBase/CdbEnvironment.hh"
00017 #include "CdbBase/CdbPartition.hh"
00018 #include "CdbBase/CdbProperty.hh"
00019 #include "CdbBase/CdbOrigin.hh"
00020
00021 #include "CdbBdbWrapper/CdbBdbWView.hh"
00022 #include "CdbBdbWrapper/CdbBdbWViewItr.hh"
00023
00024 #include "ErrLogger/ErrLog.hh"
00025
00026 #include <string.h>
00027 using std::endl;
00028
00029 namespace {
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class CdbBdbWPartitionItr : public CdbIItr<unsigned short> {
00041
00042 public:
00043
00044
00045
00046
00047 CdbBdbWPartitionItr( );
00048
00049
00050
00051
00052
00053 CdbBdbWPartitionItr( const CdbBdbWPartitionItr& theItr );
00054
00055
00056
00057
00058
00059 CdbBdbWPartitionItr& operator=( const CdbBdbWPartitionItr& theItr );
00060
00061
00062
00063
00064
00065 virtual ~CdbBdbWPartitionItr( );
00066
00067
00068
00069
00070
00071
00072
00073
00074 virtual CdbStatus reset( );
00075
00076
00077
00078
00079
00080
00081
00082 virtual bool next( );
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 virtual unsigned short value( );
00093
00094
00095
00096
00097
00098
00099
00100 virtual bool isValid( );
00101
00102
00103
00104
00105
00106 virtual CdbIItr<unsigned short>* clone( ) const;
00107 };
00108
00109 CdbBdbWPartitionItr::CdbBdbWPartitionItr( )
00110 { }
00111
00112 CdbBdbWPartitionItr::CdbBdbWPartitionItr( const CdbBdbWPartitionItr& theItr )
00113 { }
00114
00115 CdbBdbWPartitionItr::~CdbBdbWPartitionItr( )
00116 { }
00117
00118 CdbBdbWPartitionItr&
00119 CdbBdbWPartitionItr::operator=( const CdbBdbWPartitionItr& theItr )
00120 {
00121 return *this;
00122 }
00123
00124 CdbStatus
00125 CdbBdbWPartitionItr::reset( )
00126 {
00127 return CdbStatus::Success;
00128 }
00129
00130 bool
00131 CdbBdbWPartitionItr::next( )
00132 {
00133
00134
00135 return false;
00136 }
00137
00138 unsigned short
00139 CdbBdbWPartitionItr::value( )
00140 {
00141 ErrMsg(fatal) << "this function should never been called." << endmsg;
00142 return 0;
00143 }
00144
00145 bool
00146 CdbBdbWPartitionItr::isValid( )
00147 {
00148 return false;
00149 }
00150
00151 CdbIItr<unsigned short>*
00152 CdbBdbWPartitionItr::clone( ) const
00153 {
00154 return new CdbBdbWPartitionItr( *this );
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 class CdbBdbWOriginItr : public CdbIItr<unsigned short> {
00168
00169 public:
00170
00171
00172
00173
00174 CdbBdbWOriginItr( );
00175
00176
00177
00178
00179
00180 CdbBdbWOriginItr( const CdbBdbWOriginItr& theItr );
00181
00182
00183
00184
00185
00186 CdbBdbWOriginItr& operator=( const CdbBdbWOriginItr& theItr );
00187
00188
00189
00190
00191
00192 virtual ~CdbBdbWOriginItr( );
00193
00194
00195
00196
00197
00198
00199
00200
00201 virtual CdbStatus reset( );
00202
00203
00204
00205
00206
00207
00208
00209 virtual bool next( );
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 virtual unsigned short value( );
00220
00221
00222
00223
00224
00225
00226
00227 virtual bool isValid( );
00228
00229
00230
00231
00232
00233 virtual CdbIItr<unsigned short>* clone( ) const;
00234
00235 private:
00236
00237 bool _isValid;
00238 bool _hasEverBeenAdvanced;
00239 };
00240
00241 CdbBdbWOriginItr::CdbBdbWOriginItr( ) :
00242 _isValid(false),
00243 _hasEverBeenAdvanced(false)
00244 { }
00245
00246 CdbBdbWOriginItr::CdbBdbWOriginItr( const CdbBdbWOriginItr& theItr ) :
00247 _isValid(theItr._isValid),
00248 _hasEverBeenAdvanced(theItr._hasEverBeenAdvanced)
00249 { }
00250
00251 CdbBdbWOriginItr::~CdbBdbWOriginItr( )
00252 { }
00253
00254 CdbBdbWOriginItr&
00255 CdbBdbWOriginItr::operator=( const CdbBdbWOriginItr& theItr )
00256 {
00257 if( &theItr != this ) {
00258 _isValid = theItr._isValid;
00259 _hasEverBeenAdvanced = theItr._hasEverBeenAdvanced;
00260 }
00261 return *this;
00262 }
00263
00264 CdbStatus
00265 CdbBdbWOriginItr::reset( )
00266 {
00267 _isValid = false;
00268 _hasEverBeenAdvanced = false;
00269
00270 return CdbStatus::Success;
00271 }
00272
00273 bool
00274 CdbBdbWOriginItr::next( )
00275 {
00276 if( _isValid ) {
00277 _isValid = false;
00278 } else {
00279 _isValid = true;
00280 _hasEverBeenAdvanced = true;
00281 }
00282 return _isValid;
00283 }
00284
00285 unsigned short
00286 CdbBdbWOriginItr::value( )
00287 {
00288 if( !isValid( )) ErrMsg(fatal) << "attempting to use a non-initialized iterator." << endmsg;
00289 return 0;
00290 }
00291
00292 bool
00293 CdbBdbWOriginItr::isValid( )
00294 {
00295 return _isValid;
00296 }
00297
00298 CdbIItr<unsigned short>*
00299 CdbBdbWOriginItr::clone( ) const
00300 {
00301 return new CdbBdbWOriginItr( *this );
00302 }
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 class CdbBdbWOriginPropertyItr : public CdbIItr<CdbProperty> {
00314
00315 public:
00316
00317
00318
00319
00320 CdbBdbWOriginPropertyItr( );
00321
00322
00323
00324
00325
00326 CdbBdbWOriginPropertyItr( const CdbBdbWOriginPropertyItr& theItr );
00327
00328
00329
00330
00331
00332 CdbBdbWOriginPropertyItr& operator=( const CdbBdbWOriginPropertyItr& theItr );
00333
00334
00335
00336
00337
00338 virtual ~CdbBdbWOriginPropertyItr( );
00339
00340
00341
00342
00343
00344
00345
00346
00347 virtual CdbStatus reset( );
00348
00349
00350
00351
00352
00353
00354
00355 virtual bool next( );
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365 virtual CdbProperty value( );
00366
00367
00368
00369
00370
00371
00372
00373 virtual bool isValid( );
00374
00375
00376
00377
00378
00379 virtual CdbIItr<CdbProperty>* clone( ) const;
00380 };
00381
00382 CdbBdbWOriginPropertyItr::CdbBdbWOriginPropertyItr( )
00383 { }
00384
00385 CdbBdbWOriginPropertyItr::CdbBdbWOriginPropertyItr( const CdbBdbWOriginPropertyItr& theItr )
00386 { }
00387
00388 CdbBdbWOriginPropertyItr::~CdbBdbWOriginPropertyItr( )
00389 { }
00390
00391 CdbBdbWOriginPropertyItr&
00392 CdbBdbWOriginPropertyItr::operator=( const CdbBdbWOriginPropertyItr& theItr )
00393 {
00394 return *this;
00395 }
00396
00397 CdbStatus
00398 CdbBdbWOriginPropertyItr::reset( )
00399 {
00400 return CdbStatus::Success;
00401 }
00402
00403 bool
00404 CdbBdbWOriginPropertyItr::next( )
00405 {
00406
00407
00408 return false;
00409 }
00410
00411 CdbProperty
00412 CdbBdbWOriginPropertyItr::value( )
00413 {
00414 ErrMsg(fatal) << "this function should never been called." << endmsg;
00415 return CdbProperty( );
00416 }
00417
00418 bool
00419 CdbBdbWOriginPropertyItr::isValid( )
00420 {
00421 return false;
00422 }
00423
00424 CdbIItr<CdbProperty>*
00425 CdbBdbWOriginPropertyItr::clone( ) const
00426 {
00427 return new CdbBdbWOriginPropertyItr( *this );
00428 }
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 class CdbBdbWOrigin : public CdbOrigin {
00439
00440 public:
00441
00442 private:
00443
00444
00445
00446
00447
00448 CdbBdbWOrigin( );
00449
00450
00451
00452
00453
00454 CdbBdbWOrigin( const CdbBdbWOrigin& theOrigin );
00455
00456
00457
00458
00459
00460 CdbBdbWOrigin& operator=( const CdbBdbWOrigin& theOrigin );
00461
00462 public:
00463
00464
00465
00466
00467
00468
00469
00470
00471 CdbBdbWOrigin( const CdbDatabasePtr& theDatabasePtr
00472 );
00473
00474
00475
00476
00477
00478 virtual ~CdbBdbWOrigin( );
00479
00480
00481
00482
00483
00484
00485
00486 virtual BdbTime created( );
00487
00488
00489
00490
00491
00492
00493
00494 virtual std::string description( );
00495
00496
00497
00498
00499
00500
00501
00502 virtual bool isLocal( ) const;
00503
00504
00505
00506
00507
00508
00509
00510 virtual bool isInstantiated( ) const;
00511
00512
00513
00514
00515
00516
00517
00518 virtual bool isMaster( ) const;
00519
00520
00521
00522
00523
00524
00525
00526 virtual bool isSlave( ) const;
00527
00528
00529
00530
00531
00532
00533
00534 virtual bool isTest( ) const;
00535
00536
00537
00538
00539
00540
00541
00542 virtual CdbStatus propertyIterator( CdbItr<CdbProperty>& theItr );
00543 };
00544
00545 CdbBdbWOrigin::CdbBdbWOrigin( const CdbDatabasePtr& theDatabasePtr ) :
00546 CdbOrigin( theDatabasePtr,
00547 "<local>",
00548 0 )
00549 { }
00550
00551 CdbBdbWOrigin::~CdbBdbWOrigin( )
00552 { }
00553
00554 BdbTime
00555 CdbBdbWOrigin::created( )
00556 {
00557 return BdbTime::minusInfinity;
00558 }
00559
00560 std::string
00561 CdbBdbWOrigin::description( )
00562 {
00563 return std::string( "<not available in current implementation>" );
00564 }
00565
00566 bool
00567 CdbBdbWOrigin::isLocal( ) const
00568 {
00569 return true;
00570 }
00571
00572 bool
00573 CdbBdbWOrigin::isInstantiated( ) const
00574 {
00575 return true;
00576 }
00577
00578 bool
00579 CdbBdbWOrigin::isMaster( ) const
00580 {
00581 return true;
00582 }
00583
00584 bool
00585 CdbBdbWOrigin::isSlave( ) const
00586 {
00587 return false;
00588 }
00589
00590 bool
00591 CdbBdbWOrigin::isTest( ) const
00592 {
00593 return false;
00594 }
00595
00596 CdbStatus
00597 CdbBdbWOrigin::propertyIterator( CdbItr<CdbProperty>& theItr )
00598 {
00599
00600
00601
00602 theItr = CdbItr<CdbProperty>( new CdbBdbWOriginPropertyItr( ));
00603
00604 return CdbStatus::Success;
00605 }
00606
00607 };
00608
00609
00610
00611
00612
00613 CdbDatabase*
00614 CdbBdbWDatabase::clone( ) const
00615 {
00616
00617
00618 CdbBdbWDatabase* mySelf = const_cast<CdbBdbWDatabase*>( this );
00619 return new CdbBdbWDatabase( mySelf->parent( ),
00620 mySelf->name( ));
00621 }
00622
00623 CdbBdbWDatabase::CdbBdbWDatabase( const CdbPtr& theCdbPtr,
00624 const char* theName ) :
00625 CdbDatabase( theCdbPtr,
00626 theName )
00627 { }
00628
00629 CdbBdbWDatabase::~CdbBdbWDatabase( )
00630 { }
00631
00632 bool
00633 CdbBdbWDatabase::isValid( )
00634 {
00635 return true;
00636 }
00637
00638 bool
00639 CdbBdbWDatabase::isOpen( )
00640 {
00641 return true;
00642 }
00643
00644 CdbStatus
00645 CdbBdbWDatabase::open( )
00646 {
00647 return CdbStatus::Success;
00648 }
00649
00650 CdbStatus
00651 CdbBdbWDatabase::close( )
00652 {
00653 return CdbStatus::Success;
00654 }
00655
00656 BdbTime
00657 CdbBdbWDatabase::id( )
00658 {
00659 return BdbTime::minusInfinity;
00660 }
00661
00662
00663 BdbTime
00664 CdbBdbWDatabase::created( )
00665 {
00666 return BdbTime::minusInfinity;
00667 }
00668
00669 std::string
00670 CdbBdbWDatabase::description( )
00671 {
00672 return std::string( "<not available in current implementation>" );
00673 }
00674
00675 std::string
00676 CdbBdbWDatabase::defaultView( ) const
00677 {
00678 return CdbEnvironment::defaultView( parent( )->technologyName( ),
00679 parent( )->implementationName( ),
00680 name( ));
00681 }
00682
00683 CdbStatus
00684 CdbBdbWDatabase::findView( CdbViewPtr& thePtr,
00685 const char* theName )
00686 {
00687 CdbStatus result = CdbStatus::Error;
00688
00689 thePtr = 0;
00690
00691 do {
00692
00693
00694
00695
00696 std::string viewName = defaultView( );
00697 if( 0 != theName ) viewName = theName;
00698
00699 if( viewName != defaultView( )) {
00700
00701 ErrMsg(error) << "no such view in this implementation: \"" << viewName << "\"" << endl
00702 << "The only name allowed is the default one: \"" << defaultView( ) << "\"" << endmsg;
00703
00704 break;
00705 }
00706
00707
00708
00709
00710
00711
00712
00713
00714 CdbDatabasePtr myPtr( this->clone( ));
00715
00716 thePtr = new CdbBdbWView( myPtr,
00717 viewName.c_str( ));
00718
00719 result = CdbStatus::Success;
00720
00721 } while( false );
00722
00723 return result;
00724 }
00725
00726 CdbStatus
00727 CdbBdbWDatabase::findView( CdbViewPtr& thePtr,
00728 const CdbId& theId )
00729 {
00730
00731
00732
00733
00734 return findView( thePtr,
00735 defaultView( ).c_str( ));
00736 }
00737
00738 CdbStatus
00739 CdbBdbWDatabase::viewIterator( CdbViewItr& theItr )
00740 {
00741 CdbDatabasePtr myPtr = this->clone( );
00742
00743
00744
00745
00746 theItr = CdbViewItr( new CdbBdbWViewItr( myPtr ));
00747
00748 return CdbStatus::Success;
00749 }
00750
00751 CdbStatus
00752 CdbBdbWDatabase::physicalConditionIterator( CdbItr<CdbId>& theItr )
00753 {
00754 return CdbStatus::NotImplemented;
00755 }
00756
00757 CdbStatus
00758 CdbBdbWDatabase::findCondition( CdbConditionPtr& thePtr,
00759 const CdbId& theId )
00760 {
00761 return CdbStatus::NotImplemented;
00762 }
00763
00764 CdbStatus
00765 CdbBdbWDatabase::findCondition( CdbConditionPtr& thePtr,
00766 const CdbCompositeName& thePhysicalName )
00767 {
00768 return CdbStatus::NotImplemented;
00769 }
00770
00771 CdbStatus
00772 CdbBdbWDatabase::historyEventIterator( CdbHistoryEventItr& theItr,
00773 const BdbTime& theBeginTime,
00774 const BdbTime& theEndTime,
00775 const char** theEventsToSelect )
00776 {
00777 return CdbStatus::Error;
00778 }
00779
00780 CdbStatus
00781 CdbBdbWDatabase::historyEventTypeIterator( CdbHistoryEventTypeItr& theItr )
00782 {
00783 return CdbStatus::Error;
00784 }
00785
00786 CdbStatus
00787 CdbBdbWDatabase::partitionIterator( CdbItr<unsigned short>& theItr )
00788 {
00789
00790
00791
00792 theItr = CdbItr<unsigned short>( new CdbBdbWPartitionItr( ));
00793
00794 return CdbStatus::Success;
00795 }
00796
00797 CdbStatus
00798 CdbBdbWDatabase::partitionIterator( CdbItr<unsigned short>& theItr,
00799 unsigned int theOriginId )
00800 {
00801
00802
00803
00804 theItr = CdbItr<unsigned short>( new CdbBdbWPartitionItr( ));
00805
00806 return CdbStatus::Success;
00807 }
00808
00809 CdbStatus
00810 CdbBdbWDatabase::partitionIterator( CdbItr<unsigned short>& theItr,
00811 const char* theOriginName )
00812 {
00813
00814
00815
00816 theItr = CdbItr<unsigned short>( new CdbBdbWPartitionItr( ));
00817
00818 return CdbStatus::Success;
00819 }
00820
00821 CdbStatus
00822 CdbBdbWDatabase::findPartition( CdbPartitionPtr& thePtr,
00823 unsigned short thePartition )
00824 {
00825
00826
00827 return CdbStatus::NotFound;
00828 }
00829
00830 CdbStatus
00831 CdbBdbWDatabase::findPartition( CdbPartitionPtr& thePtr,
00832 unsigned short thePartition,
00833 unsigned int theOriginId )
00834 {
00835
00836
00837 return CdbStatus::NotFound;
00838 }
00839
00840 CdbStatus
00841 CdbBdbWDatabase::findPartition( CdbPartitionPtr& thePtr,
00842 unsigned short thePartition,
00843 const char* theOriginName )
00844 {
00845
00846
00847 return CdbStatus::NotFound;
00848 }
00849
00850 CdbOriginPtr
00851 CdbBdbWDatabase::localOrigin( )
00852 {
00853
00854
00855
00856
00857
00858
00859
00860 CdbDatabasePtr myPtr( this->clone( ));
00861
00862 return new CdbBdbWOrigin( myPtr );
00863 }
00864
00865 CdbStatus
00866 CdbBdbWDatabase::originIterator( CdbItr<unsigned short>& theItr )
00867 {
00868
00869
00870
00871 theItr = CdbItr<unsigned short>( new CdbBdbWOriginItr( ));
00872
00873 return CdbStatus::Success;
00874 }
00875
00876 CdbStatus
00877 CdbBdbWDatabase::findOrigin( CdbOriginPtr& thePtr,
00878 const char* theName )
00879 {
00880 CdbStatus result = CdbStatus::NotFound;
00881 do {
00882
00883
00884
00885 if( 0 != strcmp( "<local>", theName )) break;
00886
00887
00888
00889
00890
00891
00892
00893
00894 CdbDatabasePtr myPtr( this->clone( ));
00895
00896 thePtr = new CdbBdbWOrigin( myPtr );
00897
00898
00899
00900 result = CdbStatus::Success;
00901
00902 } while( false );
00903
00904 return result;
00905 }
00906
00907 CdbStatus
00908 CdbBdbWDatabase::findOrigin( CdbOriginPtr& thePtr,
00909 unsigned short theId )
00910 {
00911 CdbStatus result = CdbStatus::NotFound;
00912 do {
00913
00914
00915
00916 if( 0 != theId ) break;
00917
00918
00919
00920
00921
00922
00923
00924
00925 CdbDatabasePtr myPtr( this->clone( ));
00926
00927 thePtr = new CdbBdbWOrigin( myPtr );
00928
00929
00930
00931 result = CdbStatus::Success;
00932
00933 } while( false );
00934
00935 return result;
00936 }
00937
00938
00939
00940