00001
00002
00003
00004
00005
00006
00007
00008 #include "CdbSQL/CdbSQLApi.hh"
00009 #include "CdbSQL/CdbSQLApiCondition.hh"
00010 #include "CdbSQL/CdbSQLApiRevision.hh"
00011 #include "CdbSQL/CdbSQLOrigin.hh"
00012 #include "CdbSQL/CdbSQLPartition.hh"
00013 #include "CdbSQL/CdbSQLCondition.hh"
00014 #include "CdbSQL/CdbSQLRevision.hh"
00015 #include "CdbSQL/CdbSQLView.hh"
00016 #include "CdbSQL/CdbSQLFolder.hh"
00017 #include "CdbSQL/CdbSQLConditionAtFolder.hh"
00018 #include "CdbSQL/CdbSQLVisibleObject.hh"
00019 #include "CdbSQL/CdbSQLOriginalObject.hh"
00020
00021 #include "CdbBase/CdbEnvironment.hh"
00022 #include "CdbBase/Cdb.hh"
00023 #include "CdbBase/CdbDatabase.hh"
00024 #include "CdbBase/CdbView.hh"
00025 #include "CdbBase/CdbFolder.hh"
00026 #include "CdbBase/CdbRevision.hh"
00027 #include "CdbBase/CdbRevisionPolicy.hh"
00028 #include "CdbBase/CdbConfigElement.hh"
00029 #include "CdbBase/CdbObject.hh"
00030 #include "CdbBase/CdbObjectFactoryBase.hh"
00031 #include "CdbBase/CdbItr.hh"
00032 #include "CdbBase/CdbId.hh"
00033 #include "CdbBase/CdbCompositeName.hh"
00034 #include "CdbBase/CdbTimeUtils.hh"
00035 #include "CdbBase/CdbDebugStream.hh"
00036 #include "CdbBase/CdbVectorAdapterItr.hh"
00037 #include "CdbBase/CdbSimpleVectorAdapterItr.hh"
00038 #include "CdbBase/CdbCompositeItr.hh"
00039 #include "CdbBase/CdbAdapterItr.hh"
00040 #include "CdbBase/CdbEmptyItr.hh"
00041
00042 #include "BdbTime/BdbTime.hh"
00043
00044 #include "ErrLogger/ErrLog.hh"
00045
00046 #include <stdio.h>
00047 #include <assert.h>
00048
00049 #include <vector>
00050 #include <stack>
00051
00052 #include <iostream>
00053 using std::cout;
00054 using std::endl;
00055
00056 namespace {
00057
00058
00059
00060
00061
00062 class RevisionIdIterator : public CdbVectorAdapterItr< BdbTime, CdbCPtr<CdbSQLRevision> > {
00063
00064 private:
00065
00066 RevisionIdIterator( );
00067
00068 RevisionIdIterator& operator=( const RevisionIdIterator& theItr );
00069
00070 protected:
00071
00072 RevisionIdIterator( const RevisionIdIterator& theItr ) :
00073 CdbVectorAdapterItr< BdbTime, CdbCPtr<CdbSQLRevision> >( theItr )
00074 { }
00075
00076 public:
00077
00078 RevisionIdIterator( const std::vector< CdbCPtr<CdbSQLRevision> >& theVectorOfRevisions ) :
00079 CdbVectorAdapterItr< BdbTime, CdbCPtr<CdbSQLRevision> >( theVectorOfRevisions )
00080 { }
00081
00082 virtual ~RevisionIdIterator( )
00083 { }
00084
00085 virtual CdbIItr< BdbTime >* clone( ) const
00086 {
00087 return new RevisionIdIterator( *this );
00088 }
00089
00090 protected:
00091
00092
00093
00094
00095
00096
00097
00098 virtual BdbTime toValue( const CdbCPtr<CdbSQLRevision>& theRevisionPtr ) const
00099 {
00100 return theRevisionPtr->id( );
00101 }
00102 };
00103
00104
00105
00106
00107
00108 class RevisionNameIterator : public CdbVectorAdapterItr< const char*, CdbCPtr<CdbSQLRevision> > {
00109
00110 private:
00111
00112 RevisionNameIterator( );
00113
00114 RevisionNameIterator& operator=( const RevisionNameIterator& theItr );
00115
00116 protected:
00117
00118 RevisionNameIterator( const RevisionNameIterator& theItr ) :
00119 CdbVectorAdapterItr< const char*, CdbCPtr<CdbSQLRevision> >( theItr ),
00120 _value(theItr._value)
00121 { }
00122
00123 public:
00124
00125 RevisionNameIterator( const std::vector< CdbCPtr<CdbSQLRevision> >& theVectorOfRevisions ) :
00126 CdbVectorAdapterItr< const char*, CdbCPtr<CdbSQLRevision> >( theVectorOfRevisions ),
00127 _value("")
00128 { }
00129
00130 virtual ~RevisionNameIterator( )
00131 { }
00132
00133
00134
00135 virtual CdbIItr< const char* >* clone( ) const
00136 {
00137 return new RevisionNameIterator( *this );
00138 }
00139
00140 protected:
00141
00142
00143
00144
00145
00146
00147
00148 virtual const char* toValue( const CdbCPtr<CdbSQLRevision>& theRevisionPtr ) const
00149 {
00150 _value = theRevisionPtr->name( );
00151 return _value.c_str( );
00152 }
00153
00154 private:
00155
00156
00157
00158
00159
00160
00161
00162 mutable std::string _value;
00163 };
00164
00165
00166
00167
00168 //
00169
00170
00171 class PersistentToTransientIteratorAdapter : public CdbAdapterItr< CdbObjectPtr,
00172 CdbCPtr<CdbSQLVisibleObject> > {
00173 private:
00174
00175 PersistentToTransientIteratorAdapter( );
00176
00177 PersistentToTransientIteratorAdapter& operator=( const PersistentToTransientIteratorAdapter& theItr );
00178
00179 protected:
00180
00181 PersistentToTransientIteratorAdapter( const PersistentToTransientIteratorAdapter& theItr ) :
00182 CdbAdapterItr< CdbObjectPtr,
00183 CdbCPtr<CdbSQLVisibleObject> >( theItr ),
00184 _myParentPtr(theItr._myParentPtr)
00185 { }
00186
00187 public:
00188
00189
00190
00191
00192 PersistentToTransientIteratorAdapter( CdbIItr< CdbCPtr<CdbSQLVisibleObject> >* theInputItrPtr,
00193 const CdbConditionPtr& theParentPtr ) :
00194 CdbAdapterItr< CdbObjectPtr,
00195 CdbCPtr<CdbSQLVisibleObject> >( theInputItrPtr ),
00196 _myParentPtr(theParentPtr)
00197 { }
00198
00199 virtual ~PersistentToTransientIteratorAdapter( )
00200 { }
00201
00202 virtual CdbIItr< CdbObjectPtr >* clone( ) const
00203 {
00204 return new PersistentToTransientIteratorAdapter( *this );
00205 }
00206
00207 protected:
00208
00209 virtual CdbObjectPtr toValue( const CdbCPtr<CdbSQLVisibleObject>& thePersistentObjectPtr ) const
00210 {
00211 const char* fatalStr = "CdbSQLApiCondition::<anonymous>::PersistentToTransientIteratorAdapter::toValue() -- FATAL ERROR.";
00212
00213 assert( !thePersistentObjectPtr.isNull( ));
00214
00215
00216
00217
00218
00219
00220 CdbCPtr<CdbSQLApi> ptr = (const CdbCPtr<CdbSQLApi>&)_myParentPtr->parentDatabase( )->parent( );
00221
00222
00223
00224 CdbObjectPtr result;
00225 CdbStatus status = ptr->createObject( result,
00226 _myParentPtr,
00227 thePersistentObjectPtr->begin( ),
00228 thePersistentObjectPtr->end( ),
00229 thePersistentObjectPtr->begin( ),
00230 thePersistentObjectPtr->end( ),
00231 thePersistentObjectPtr->stored( ),
00232 BdbTime::plusInfinity,
00233 thePersistentObjectPtr->stored( ),
00234 thePersistentObjectPtr->id( ));
00235 if( CdbStatus::Success != status ) {
00236 ErrMsg(fatal) << fatalStr << endl
00237 << " Failed to produce a metadata object for the found persistent object because" << endl
00238 << " of the following status: " << status << " returned by an object creator." << endmsg;
00239 }
00240 return result;
00241 }
00242
00243 virtual bool isAccepted( const CdbCPtr<CdbSQLVisibleObject>& thePersistentObjectPtr ) const
00244 {
00245 assert( !thePersistentObjectPtr.isNull( ));
00246
00247
00248
00249 return thePersistentObjectPtr->isValid( );
00250 }
00251
00252 private:
00253
00254 CdbConditionPtr _myParentPtr;
00255 };
00256
00257
00258
00259
00260 //
00261
00262
00263
00264 class VisibleObjectIteratorAdapter : public CdbAdapterItr< CdbObjectItr,
00265 CdbConfigElement > {
00266 private:
00267
00268 VisibleObjectIteratorAdapter( );
00269
00270 VisibleObjectIteratorAdapter& operator=( const VisibleObjectIteratorAdapter& theItr );
00271
00272 protected:
00273
00274 VisibleObjectIteratorAdapter( const VisibleObjectIteratorAdapter& theItr ) :
00275 CdbAdapterItr< CdbObjectItr,
00276 CdbConfigElement >( theItr ),
00277 _myConditionPtr(theItr._myConditionPtr),
00278 _myParentPtr (theItr._myParentPtr),
00279 _beginTime (theItr._beginTime),
00280 _endTime (theItr._endTime)
00281 { }
00282
00283 public:
00284
00285
00286
00287
00288 VisibleObjectIteratorAdapter( CdbIItr<CdbConfigElement>* theInputItrPtr,
00289 const CdbCPtr<CdbSQLCondition>& theConditionPtr,
00290 const CdbConditionPtr& theParentPtr,
00291 const BdbTime& theBeginTime = BdbTime::minusInfinity,
00292 const BdbTime& theEndTime = BdbTime::plusInfinity ) :
00293 CdbAdapterItr< CdbObjectItr,
00294 CdbConfigElement >( theInputItrPtr ),
00295 _myConditionPtr(theConditionPtr),
00296 _myParentPtr (theParentPtr),
00297 _beginTime (theBeginTime),
00298 _endTime (theEndTime)
00299 { }
00300
00301 virtual ~VisibleObjectIteratorAdapter( )
00302 { }
00303
00304
00305
00306 virtual CdbIItr< CdbObjectItr >* clone( ) const
00307 {
00308 return new VisibleObjectIteratorAdapter( *this );
00309 }
00310
00311 protected:
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 virtual CdbObjectItr toValue( const CdbConfigElement& theConfigElement ) const
00341 {
00342 const char* fatalStr = "<anonymous>::VisibleObjectIteratorAdapter::toValue() -- FATAL ERROR";
00343
00344
00345
00346
00347
00348
00349
00350 if( !theConfigElement.policy.useRevision( ))
00351 ErrMsg(fatal) << fatalStr << endl
00352 << " Unsupported revision policy has been detected in the current configuration" << endl
00353 << " of the condition." << endl
00354 << " CONDITION PATH: \"" << CdbCondition::fullPathName( _myParentPtr ) << "\"" << endmsg;
00355
00356
00357
00358
00359
00360 if( !theConfigElement.accessIsAllowed ||
00361 theConfigElement.begin >= _endTime ||
00362 theConfigElement.end <= _beginTime ) {
00363
00364 return CdbObjectItr( new CdbEmptyItr< CdbObjectPtr >( ));
00365 }
00366
00367
00368
00369
00370 const BdbTime adjustedBeginTime = ( theConfigElement.begin > _beginTime ? theConfigElement.begin : _beginTime );
00371 const BdbTime adjustedEndTime = ( theConfigElement.end < _endTime ? theConfigElement.end : _endTime );
00372
00373 assert( adjustedBeginTime != adjustedEndTime );
00374
00375
00376
00377
00378 std::vector< CdbCPtr<CdbSQLVisibleObject> > objects;
00379
00380 if( CdbStatus::Success != _myConditionPtr->visible_objects( objects,
00381 theConfigElement.policy.partitionId( ),
00382 theConfigElement.policy.revisionId( ),
00383 adjustedBeginTime,
00384 adjustedEndTime ))
00385 ErrMsg(fatal) << fatalStr << endl
00386 << " Failed to obtain a list of visible object from the condition." << endl
00387 << " CONDITION PATH: \"" << CdbCondition::fullPathName( _myParentPtr ) << "\"" << endl
00388 << " PARTITION : " << theConfigElement.policy.partitionId( ) << endl
00389 << " REVISION : " << CdbTimeUtils::time2string( theConfigElement.policy.revisionId( )) << " : " << theConfigElement.policy.revisionId( ) << endl
00390 << " BEGIN TIME : " << CdbTimeUtils::time2string( adjustedBeginTime ) << " : " << adjustedBeginTime << endl
00391 << " END TIME : " << CdbTimeUtils::time2string( adjustedEndTime ) << " : " << adjustedEndTime << endmsg;
00392
00393
00394
00395
00396
00397
00398
00399
00400 return CdbObjectItr( new PersistentToTransientIteratorAdapter( new CdbSimpleVectorAdapterItr< CdbCPtr<CdbSQLVisibleObject> >( objects ),
00401 _myParentPtr ));
00402 }
00403
00404 private:
00405
00406 CdbCPtr<CdbSQLCondition> _myConditionPtr;
00407 CdbConditionPtr _myParentPtr;
00408
00409 BdbTime _beginTime;
00410 BdbTime _endTime;
00411 };
00412
00413
00414
00415
00416 //
00417
00418
00419 class OriginalObjectIterator : public CdbAdapterItr< CdbObjectPtr,
00420 CdbCPtr<CdbSQLOriginalObject> > {
00421 private:
00422
00423 OriginalObjectIterator( );
00424
00425 OriginalObjectIterator& operator=( const OriginalObjectIterator& theItr );
00426
00427 protected:
00428
00429 OriginalObjectIterator( const OriginalObjectIterator& theItr ) :
00430 CdbAdapterItr< CdbObjectPtr,
00431 CdbCPtr<CdbSQLOriginalObject> >( theItr ),
00432 _myParentPtr(theItr._myParentPtr)
00433 { }
00434
00435 public:
00436
00437
00438
00439 OriginalObjectIterator( CdbIItr< CdbCPtr<CdbSQLOriginalObject> >* theInputItrPtr,
00440 const CdbConditionPtr& theParentPtr ) :
00441 CdbAdapterItr< CdbObjectPtr,
00442 CdbCPtr<CdbSQLOriginalObject> >( theInputItrPtr ),
00443 _myParentPtr(theParentPtr)
00444 { }
00445
00446 virtual ~OriginalObjectIterator( )
00447 { }
00448
00449 virtual CdbIItr< CdbObjectPtr >* clone( ) const
00450 {
00451 return new OriginalObjectIterator( *this );
00452 }
00453
00454 protected:
00455
00456 virtual CdbObjectPtr toValue( const CdbCPtr<CdbSQLOriginalObject>& thePersistentObjectPtr ) const
00457 {
00458 const char* fatalStr = "CdbSQLApiCondition::<anonymous>::OriginalObjectIterator::toValue() -- FATAL ERROR.";
00459
00460 assert( !thePersistentObjectPtr.isNull( ));
00461
00462
00463
00464
00465
00466
00467 CdbCPtr<CdbSQLApi> ptr = (const CdbCPtr<CdbSQLApi>&)_myParentPtr->parentDatabase( )->parent( );
00468
00469
00470
00471 CdbObjectPtr result;
00472 CdbStatus status = ptr->createObject( result,
00473 _myParentPtr,
00474 thePersistentObjectPtr->begin( ),
00475 thePersistentObjectPtr->end( ),
00476 thePersistentObjectPtr->begin( ),
00477 thePersistentObjectPtr->end( ),
00478 thePersistentObjectPtr->stored( ),
00479 BdbTime::plusInfinity,
00480 thePersistentObjectPtr->stored( ),
00481 thePersistentObjectPtr->id( ));
00482 if( CdbStatus::Success != status ) {
00483 ErrMsg(fatal) << fatalStr << endl
00484 << " Failed to produce a metadata object for the found persistent object because" << endl
00485 << " of the following status: " << status << " returned by an object creator." << endmsg;
00486 }
00487 return result;
00488 }
00489
00490 private:
00491
00492 CdbConditionPtr _myParentPtr;
00493 };
00494 }
00495
00496
00497
00498
00499
00500 CdbCondition*
00501 CdbSQLApiCondition::clone( ) const
00502 {
00503 return new CdbSQLApiCondition( *this );
00504 }
00505
00506 CdbSQLApiCondition::CdbSQLApiCondition( const CdbFolderPtr& theFolderPtr,
00507 const CdbDatabasePtr& theDatabasePtr,
00508 const char* theName,
00509 const CdbCPtr<CdbSQLConditionAtFolder>& theConditionAtFolderPtr,
00510 const CdbCPtr<CdbSQLCondition>& theConditionPtr,
00511 const CdbCPtr<CdbSQLOrigin>& theMasterOriginPtr,
00512 const CdbCPtr<CdbSQLOrigin>& theLocalOriginPtr ) :
00513 CdbCondition( theFolderPtr,
00514 theDatabasePtr,
00515 theName ),
00516 _myConditionAtFolderPtr(theConditionAtFolderPtr),
00517 _myConditionPtr (theConditionPtr),
00518 _myMasterSQLOriginPtr (theMasterOriginPtr),
00519 _myLocalSQLOriginPtr (theLocalOriginPtr)
00520 {
00521 const char* fatalStr = "CdbSQLApiCondition::CdbSQLApiCondition() -- FATAL ERROR IN THE CONSTRUCTOR";
00522
00523 if( theConditionPtr.isNull( ))
00524 ErrMsg(fatal) << fatalStr << endl
00525 << " A null pointer onto 'physical' condition object passed as a paremeter." << endmsg;
00526
00527 if( theMasterOriginPtr.isNull( ))
00528 ErrMsg(fatal) << fatalStr << endl
00529 << " A null pointer onto the MASTER origin object passed as a paremeter." << endmsg;
00530
00531 if( theLocalOriginPtr.isNull( ))
00532 ErrMsg(fatal) << fatalStr << endl
00533 << " A null pointer onto the local origin object passed as a paremeter." << endmsg;
00534 }
00535
00536 CdbSQLApiCondition::CdbSQLApiCondition( const CdbSQLApiCondition& theCondition ) :
00537 CdbCondition( theCondition ),
00538 _myConditionAtFolderPtr(theCondition._myConditionAtFolderPtr),
00539 _myConditionPtr (theCondition._myConditionPtr),
00540 _myMasterSQLOriginPtr (theCondition._myMasterSQLOriginPtr),
00541 _myLocalSQLOriginPtr (theCondition._myLocalSQLOriginPtr)
00542 { }
00543
00544 CdbSQLApiCondition::~CdbSQLApiCondition( )
00545 { }
00546
00547 std::string
00548 CdbSQLApiCondition::description( ) const
00549 {
00550 if( _myConditionAtFolderPtr.isNull( )) return _myConditionPtr->description( );
00551 return _myConditionAtFolderPtr->description( );
00552 }
00553
00554 bool
00555 CdbSQLApiCondition::isPartitionable( ) const
00556 {
00557 return _myConditionPtr->isPartitionable( );
00558 }
00559
00560 CdbCompositeName
00561 CdbSQLApiCondition::physicalName( ) const
00562 {
00563 return CdbCompositeName( _myConditionPtr->parent( )->name( ).c_str( ),
00564 _myConditionPtr->name( ).c_str( ));
00565 }
00566
00567 CdbId
00568 CdbSQLApiCondition::physicalId( ) const
00569 {
00570 return CdbId( _myConditionPtr->parent( )->id( ),
00571 _myConditionPtr->id( ));
00572 }
00573
00574 BdbTime
00575 CdbSQLApiCondition::created( ) const
00576 {
00577 return _myConditionPtr->created( );
00578 }
00579
00580 BdbTime
00581 CdbSQLApiCondition::registered( ) const
00582 {
00583 if( _myConditionAtFolderPtr.isNull( )) return _myConditionPtr->created( );
00584 return _myConditionAtFolderPtr->created( );
00585 }
00586
00587 BdbTime
00588 CdbSQLApiCondition::modified( ) const
00589 {
00590 const char* errorStr = "CdbSQLApiCondition::modified() -- ERROR";
00591
00592 BdbTime result = BdbTime::minusInfinity;
00593
00594 do {
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613 if( _myConditionAtFolderPtr.isNull( )) break;
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634 std::vector<CdbConfigElement> config_elements;
00635 if( CdbStatus::Success != _myConditionAtFolderPtr->config_elements( config_elements )) {
00636 ErrMsg(error) << errorStr << endl
00637 << " Failed to get a list of configuration elements for the current condition." << endl
00638 << " CONDITION NAME : \"" << _myConditionAtFolderPtr->name( ) << "\"." << endmsg;
00639 break;
00640 }
00641 unsigned int nElements = config_elements.size( );
00642
00643 for( unsigned int iElement = 0; iElement < nElements; ++iElement ) {
00644
00645 CdbConfigElement configElement = config_elements[iElement];
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659 if( !configElement.accessIsAllowed ) continue;
00660
00661
00662
00663
00664 BdbTime modificationTime = BdbTime::minusInfinity;
00665 if( configElement.policy.useRevision( ) && ( BdbTime::plusInfinity != configElement.policy.revisionId( ))) {
00666 modificationTime = configElement.policy.revisionId( );
00667 } else {
00668
00669
00670
00671
00672 if( CdbStatus::Success != _myConditionPtr->modified( modificationTime,
00673 configElement.policy.partitionId( ))) {
00674
00675 ErrMsg(error) << errorStr << endl
00676 << " Failed to get the modification of configuration elements for the current condition/partition." << endl
00677 << " CONDITION NAME : \"" << _myConditionAtFolderPtr->name( ) << "\"" << endl
00678 << " PARTITION : " << configElement.policy.partitionId( ) << "." << endmsg;
00679 break;
00680 }
00681 }
00682 assert( BdbTime::minusInfinity != modificationTime );
00683 assert( BdbTime::plusInfinity != modificationTime );
00684
00685
00686
00687 if( modificationTime > result ) result = modificationTime;
00688 }
00689
00690
00691
00692 } while( false );
00693
00694 return result;
00695
00696 }
00697
00698 CdbStatus
00699 CdbSQLApiCondition::findObject( CdbObjectPtr& theObjectPtr,
00700 const BdbTime& theValidityTime,
00701 const BdbTime& theInsertionTime )
00702 {
00703 const char* errorStr = "CdbSQLApiCondition::findObject(validity,insertion) -- ERROR";
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731 if( _myConditionAtFolderPtr.isNull( )) {
00732
00733
00734
00735
00736 CdbRevisionPolicy rPolicy;
00737
00738 if( BdbTime::plusInfinity == theInsertionTime ) {
00739
00740
00741
00742 if( _myConditionPtr->isPartitionable( )) {
00743
00744
00745
00746
00747
00748
00749 CdbCPtr<CdbSQLPartition> partitionPtr;
00750
00751 if( CdbStatus::Success != findInitialPartition( partitionPtr,
00752 theValidityTime,
00753 theInsertionTime )) {
00754
00755 ErrMsg(error) << errorStr << endl
00756 << " Failed to find an initial partition for the specified validity and insertion" << endl
00757 << " for a condition found by its 'physical address'." << endl
00758 << " PHYSICAL CONDITION ADDRESS : " << physicalId( ) << endl
00759 << " VALIDITY TIME : " << CdbTimeUtils::time2string( theValidityTime ) << " : " << theValidityTime << endl
00760 << " INSERTION TIME : " << CdbTimeUtils::time2string( theInsertionTime ) << " : " << theInsertionTime << endmsg;
00761
00762 return CdbStatus::Error;
00763 }
00764
00765
00766
00767
00768 BdbTime rId = BdbTime::minusInfinity;
00769
00770 if( CdbStatus::Success != _myConditionPtr->topmost_revision_id( rId,
00771 partitionPtr->id( ))) {
00772
00773 ErrMsg(error) << errorStr << endl
00774 << " Failed to find a topmost revision in the partition #" << partitionPtr->id( ) << " for a condition" << endl
00775 << " found by its 'physical address'." << endl
00776 << " PHYSICAL CONDITION ADDRESS : " << physicalId( ) << endmsg;
00777
00778 return CdbStatus::Error;
00779 }
00780 assert( BdbTime::minusInfinity != rId );
00781
00782
00783
00784 rPolicy = CdbRevisionPolicy( rId, partitionPtr->id( ));
00785
00786 } else {
00787
00788
00789
00790 rPolicy = CdbRevisionPolicy( BdbTime::plusInfinity, 0 );
00791 }
00792 }
00793
00794
00795
00796 return findObject( theObjectPtr,
00797 rPolicy,
00798 theValidityTime,
00799 theInsertionTime );
00800 }
00801
00802
00803
00804
00805
00806
00807
00808 CDB_DEBUG_STREAM
00809 << "CDB_FIND_OBJECT_1: condition=" << name( )
00810 << " validity_time=" << theValidityTime.getGmtSec( ) << "." << theValidityTime.getGmtNsec( )
00811 << " insertion_time=" << theInsertionTime.getGmtSec( ) << "." << theInsertionTime.getGmtNsec( ) << endl;
00812
00813 theObjectPtr = 0;
00814
00815 CdbStatus result = CdbStatus::Error;
00816
00817 do {
00818
00819
00820
00821
00822 CdbCPtr<CdbSQLView> viewPtr = _myConditionAtFolderPtr->parent( )->parentView( );
00823 assert( !viewPtr.isNull( ));
00824
00825 if(( theValidityTime < viewPtr->begin( )) ||
00826 ( theValidityTime >= viewPtr->end ( ))) {
00827
00828 ErrMsg(error) << errorStr << endl
00829 << " Specified validity time does not fit into the validity range" << endl
00830 << " of the current view." << endl
00831 << " VIEW NAME: \"" << viewPtr->name( ) << "\"" << endl
00832 << " PASSED TIME: " << theValidityTime << endmsg;
00833 break;
00834 }
00835
00836
00837
00838
00839 CdbConfigElement rConfigElement;
00840
00841 if( CdbStatus::Success != _myConditionAtFolderPtr->find_config_element( rConfigElement,
00842 theValidityTime )) {
00843
00844 ErrMsg(error) << errorStr << endl
00845 << " Failed to find revision policy information for specified validity time" << endl
00846 << " at the condition description of the the current view." << endl
00847 << " The view may be inproperly configured." << endl
00848 << " PASSED TIME: " << theValidityTime << endl
00849 << " CONDITION NAME: \"" << name( ) << "\"" << endl
00850 << " VIEW NAME: \"" << viewPtr->name( ) << "\"" << endmsg;
00851 break;
00852 }
00853 if( ! rConfigElement.accessIsAllowed ) {
00854 ErrMsg(error) << errorStr << endl
00855 << " The current view prohibits accessing conditions at specified" << endl
00856 << " point of the validity timeline." << endl
00857 << " VIEW NAME: \"" << viewPtr->name( ) << "\"" << endl
00858 << " PASSED TIME: " << theValidityTime << endmsg;
00859 break;
00860 }
00861
00862
00863
00864
00865
00866 CdbCPtr<CdbSQLVisibleObject> visibleObjectPtr;
00867
00868 BdbTime beginOfVisiblePeriod = BdbTime::plusInfinity;
00869 BdbTime endOfVisiblePeriod = BdbTime::plusInfinity;
00870
00871 BdbTime beginOfDurationPeriod = BdbTime::minusInfinity;
00872 BdbTime endOfDurationPeriod = BdbTime::minusInfinity;
00873
00874 if( _myConditionPtr->isPartitionable( )) {
00875
00876 if( CdbStatus::Success != doFindObjectAtPartition( rConfigElement.policy,
00877 theValidityTime,
00878 theInsertionTime,
00879 visibleObjectPtr,
00880 beginOfVisiblePeriod,
00881 endOfVisiblePeriod,
00882 beginOfDurationPeriod,
00883 endOfDurationPeriod )) break;
00884
00885 } else {
00886
00887 if( CdbStatus::Success != doFindObject( rConfigElement.policy,
00888 theValidityTime,
00889 theInsertionTime,
00890 visibleObjectPtr,
00891 beginOfVisiblePeriod,
00892 endOfVisiblePeriod,
00893 beginOfDurationPeriod,
00894 endOfDurationPeriod )) break;
00895 }
00896
00897
00898
00899
00900 if( rConfigElement.begin > beginOfVisiblePeriod ) beginOfVisiblePeriod = rConfigElement.begin;
00901 if( rConfigElement.end < endOfVisiblePeriod ) endOfVisiblePeriod = rConfigElement.end;
00902
00903
00904
00905 CdbObjectPtr transientObjectPtr;
00906 {
00907
00908
00909
00910
00911
00912 CdbCPtr<CdbSQLApi> ptr = (const CdbCPtr<CdbSQLApi>&)parentDatabase( )->parent( );
00913
00914
00915
00916 if( CdbStatus::Success != ptr->createObject( transientObjectPtr,
00917 CdbConditionPtr( this->clone( )),
00918 visibleObjectPtr->original_begin( ),
00919 visibleObjectPtr->original_end( ),
00920 beginOfVisiblePeriod,
00921 endOfVisiblePeriod,
00922 beginOfDurationPeriod,
00923 endOfDurationPeriod,
00924 visibleObjectPtr->stored( ),
00925 visibleObjectPtr->id( ))) {
00926 ErrMsg(error) << errorStr << endl
00927 << " Failed to produce a metadata object for the found persistent object." << endmsg;
00928 break;
00929 }
00930 }
00931 theObjectPtr = transientObjectPtr;
00932
00933
00934
00935 result = CdbStatus::Success;
00936
00937 } while( false );
00938
00939 CDB_DEBUG_STREAM << "CDB_FIND_OBJECT_1: " << (theObjectPtr.isNull( ) ? "" : theObjectPtr->id( )) << endl;
00940
00941 return result;
00942 }
00943
00944 CdbStatus
00945 CdbSQLApiCondition::findObject( CdbObjectPtr& theObjectPtr,
00946 const CdbRevisionPolicy& thePolicy,
00947 const BdbTime& theValidityTime,
00948 const BdbTime& theInsertionTime )
00949 {
00950 const char* errorStr = "CdbSQLApiCondition::findObject(policy,validity,insertion) -- ERROR";
00951
00952 theObjectPtr = 0;
00953
00954 CDB_DEBUG_STREAM
00955 << "CDB_FIND_OBJECT_2: condition=" << name( )
00956 << " validity_time=" << theValidityTime.getGmtSec( ) << "." << theValidityTime.getGmtNsec( )
00957 << " insertion_time=" << theInsertionTime.getGmtSec( ) << "." << theInsertionTime.getGmtNsec( ) << endl;
00958
00959 CdbStatus result = CdbStatus::Error;
00960
00961 do {
00962
00963
00964
00965
00966
00967 CdbCPtr<CdbSQLVisibleObject> visibleObjectPtr;
00968
00969 BdbTime beginOfVisiblePeriod = BdbTime::plusInfinity;
00970 BdbTime endOfVisiblePeriod = BdbTime::plusInfinity;
00971
00972 BdbTime beginOfDurationPeriod = BdbTime::minusInfinity;
00973 BdbTime endOfDurationPeriod = BdbTime::minusInfinity;
00974
00975 if( _myConditionPtr->isPartitionable( )) {
00976
00977 if( CdbStatus::Success != doFindObjectAtPartition( thePolicy,
00978 theValidityTime,
00979 theInsertionTime,
00980 visibleObjectPtr,
00981 beginOfVisiblePeriod,
00982 endOfVisiblePeriod,
00983 beginOfDurationPeriod,
00984 endOfDurationPeriod )) break;
00985
00986 } else {
00987
00988 if( CdbStatus::Success != doFindObject( thePolicy,
00989 theValidityTime,
00990 theInsertionTime,
00991 visibleObjectPtr,
00992 beginOfVisiblePeriod,
00993 endOfVisiblePeriod,
00994 beginOfDurationPeriod,
00995 endOfDurationPeriod )) break;
00996 }
00997
00998
00999
01000
01001
01002 ;
01003
01004
01005
01006 CdbObjectPtr transientObjectPtr;
01007 {
01008
01009
01010
01011
01012
01013 CdbCPtr<CdbSQLApi> ptr = (const CdbCPtr<CdbSQLApi>&)parentDatabase( )->parent( );
01014
01015
01016
01017 if( CdbStatus::Success != ptr->createObject( transientObjectPtr,
01018 CdbConditionPtr( this->clone( )),
01019 visibleObjectPtr->original_begin( ),
01020 visibleObjectPtr->original_end( ),
01021 beginOfVisiblePeriod,
01022 endOfVisiblePeriod,
01023 beginOfDurationPeriod,
01024 endOfDurationPeriod,
01025 visibleObjectPtr->stored( ),
01026 visibleObjectPtr->id( ))) {
01027 ErrMsg(error) << errorStr << endl
01028 << " Failed to produce a metadata object for the found persistent object." << endmsg;
01029 break;
01030 }
01031 }
01032 theObjectPtr = transientObjectPtr;
01033
01034
01035
01036 result = CdbStatus::Success;
01037
01038 } while( false );
01039
01040 CDB_DEBUG_STREAM << "CDB_FIND_OBJECT_2: " << (theObjectPtr.isNull( ) ? "" : theObjectPtr->id( )) << endl;
01041
01042 return result;
01043 }
01044
01045 CdbStatus
01046 CdbSQLApiCondition::objectIterator( CdbObjectItr& theItr,
01047 const BdbTime& theBeginValidity,
01048 const BdbTime& theEndValidity )
01049 {
01050 const char* errorStr = "CdbSQLApiCondition::objectIterator() -- ERROR";
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069 if( _myConditionAtFolderPtr.isNull( )) return CdbStatus::NotImplemented;
01070
01071
01072
01073
01074
01075
01076
01077 CdbStatus result = CdbStatus::Error;
01078
01079
01080
01081 if( theEndValidity <= theBeginValidity ) {
01082
01083 ErrMsg(error) << errorStr << endl
01084 << " Invalid validity interval range passed to the method." << endl
01085 << " The end time should be greater or equal than the begin one." << endl
01086 << " PASSED BEGIN TIME : " << theBeginValidity << endl
01087 << " PASSED END TIME : " << theEndValidity << endl
01088 << " CONDITION : \"" << name( ) << "\"" << endmsg;
01089
01090 return CdbStatus::IllegalParameters;
01091 }
01092
01093 CdbCPtr<CdbSQLView> viewPtr = _myConditionAtFolderPtr->parent( )->parentView( );
01094
01095 BdbTime minValidity = viewPtr->begin( );
01096 BdbTime maxValidity = viewPtr->end( );
01097
01098 if(( theBeginValidity >= maxValidity ) || ( theEndValidity <= minValidity )) {
01099
01100 ErrMsg(error) << errorStr << endl
01101 << " Invalid validity interval range passed to the method." << endl
01102 << " This interval does not fit into the validity range" << endl
01103 << " allowed by the current view." << endl
01104 << " PASSED BEGIN TIME : " << theBeginValidity << endl
01105 << " PASSED END TIME : " << theEndValidity << endl
01106 << " VIEW'S BEGIN TIME : " << minValidity << endl
01107 << " VIEW'S END TIME : " << maxValidity << endl
01108 << " VIEW : \"" << parent( )->parentView( )->name( ) << "\"" << endl
01109 << " CONDITION : \"" << name( ) << "\"" << endmsg;
01110
01111 return CdbStatus::IllegalParameters;
01112 }
01113
01114
01115
01116
01117 if( theBeginValidity > minValidity ) minValidity = theBeginValidity;
01118 if( theEndValidity < maxValidity ) maxValidity = theEndValidity;
01119
01120
01121
01122
01123
01124
01125
01126 std::vector<CdbConfigElement> configElements;
01127
01128 if( CdbStatus::Success == ( result = _myConditionAtFolderPtr->config_elements( configElements ))) {
01129
01130
01131
01132 ;
01133
01134 } else if( CdbStatus::NotFound == result ) {
01135
01136
01137
01138 if( !viewPtr->hasDefaultConfig( )) {
01139
01140 ErrMsg(error) << errorStr << endl
01141 << " No default configuration collection in the view." << endl
01142 << " VIEW : \"" << parent( )->parentView( )->name( ) << "\"" << endl
01143 << " CONDITION : \"" << name( ) << "\"" << endmsg;
01144
01145 return CdbStatus::Error;
01146
01147 }
01148 if( CdbStatus::Success != ( result = viewPtr->config_elements( configElements ))) {
01149
01150 ErrMsg(error) << errorStr << endl
01151 << " Failed to get the default configuration collection from the view." << endl
01152 << " VIEW : \"" << parent( )->parentView( )->name( ) << "\"" << endl
01153 << " CONDITION : \"" << name( ) << "\"" << endmsg;
01154
01155 return CdbStatus::Error;
01156 }
01157
01158 } else {
01159
01160 ErrMsg(error) << errorStr << endl
01161 << " Failed to get a local configuration collection for the condition in the view." << endl
01162 << " VIEW : \"" << parent( )->parentView( )->name( ) << "\"" << endl
01163 << " CONDITION : \"" << name( ) << "\"" << endmsg;
01164
01165 return CdbStatus::Error;
01166 }
01167
01168
01169
01170
01171 theItr = CdbObjectItr( new CdbCompositeItr< CdbObjectItr::ValueType >( new VisibleObjectIteratorAdapter( new CdbSimpleVectorAdapterItr<CdbConfigElement>( configElements ),
01172 _myConditionPtr,
01173 CdbConditionPtr( this->clone( )),
01174 minValidity,
01175 maxValidity )));
01176
01177
01178 return CdbStatus::Success;
01179 }
01180
01181 CdbStatus
01182 CdbSQLApiCondition::objectIterator( CdbObjectItr& theItr,
01183 const CdbRevisionPolicy& thePolicy,
01184 const BdbTime& theBeginValidity,
01185 const BdbTime& theEndValidity )
01186 {
01187 const char* errorStr = "CdbSQLApiCondition::objectIterator(policy) -- ERROR";
01188
01189
01190
01191 if( theEndValidity <= theBeginValidity ) {
01192
01193 ErrMsg(error) << errorStr << endl
01194 << " Invalid validity interval range passed to the method." << endl
01195 << " The end time should be greater or equal than the begin one." << endl
01196 << " PASSED BEGIN TIME : " << theBeginValidity << endl
01197 << " PASSED END TIME : " << theEndValidity << endl
01198 << " CONDITION : \"" << name( ) << "\"" << endmsg;
01199
01200 return CdbStatus::IllegalParameters;
01201 }
01202
01203
01204
01205
01206 std::vector<CdbConfigElement> configElements;
01207
01208 configElements.push_back( CdbConfigElement( thePolicy,
01209 theBeginValidity,
01210 theEndValidity ));
01211
01212
01213
01214
01215 theItr = CdbObjectItr( new CdbCompositeItr< CdbObjectItr::ValueType >( new VisibleObjectIteratorAdapter( new CdbSimpleVectorAdapterItr<CdbConfigElement>( configElements ),
01216 _myConditionPtr,
01217 CdbConditionPtr( this->clone( )),
01218 theBeginValidity,
01219 theEndValidity )));
01220
01221
01222 return CdbStatus::Success;
01223 }
01224
01225 CdbStatus
01226 CdbSQLApiCondition::originalObjectIterator( CdbObjectItr& theItr,
01227 const BdbTime& theBeginInsertion,
01228 const BdbTime& theEndInsertion,
01229 const unsigned short thePartitionId )
01230 {
01231 const char* errorStr = "CdbSQLApiCondition::originalObjectIterator() -- ERROR";
01232
01233
01234
01235 if( theBeginInsertion >= theEndInsertion ) {
01236
01237 ErrMsg(error) << errorStr << endl
01238 << " Invalid 'insertion' interval range passed to the method." << endl
01239 << " The end time should be greater or equal than the begin one." << endl
01240 << " VIEW : \"" << parent( )->parentView( )->name( ) << "\"" << endl
01241 << " CONDITION : \"" << name( ) << "\"" << endl
01242 << " PARTITION : " << thePartitionId << endl
01243 << " BEGIN INSERTIN TIME : " << CdbTimeUtils::time2string( theBeginInsertion ) << " : " << theBeginInsertion << endl
01244 << " END INSERTIONTIME : " << CdbTimeUtils::time2string( theEndInsertion ) << " : " << theEndInsertion << endmsg;
01245
01246 return CdbStatus::IllegalParameters;
01247 }
01248
01249
01250
01251 std::vector< CdbCPtr<CdbSQLOriginalObject> > originalObjects;
01252
01253 if( CdbStatus::Success != _myConditionPtr->original_objects( originalObjects,
01254 thePartitionId,
01255 theBeginInsertion,
01256 theEndInsertion )) {
01257 ErrMsg(error) << errorStr << endl
01258 << " Failed to get a list of original persistent objects for the condition in the view." << endl
01259 << " VIEW : \"" << parent( )->parentView( )->name( ) << "\"" << endl
01260 << " CONDITION : \"" << name( ) << "\"" << endl
01261 << " PARTITION : " << thePartitionId << endl
01262 << " BEGIN INSERTIN TIME : " << CdbTimeUtils::time2string( theBeginInsertion ) << " : " << theBeginInsertion << endl
01263 << " END INSERTIONTIME : " << CdbTimeUtils::time2string( theEndInsertion ) << " : " << theEndInsertion << endmsg;
01264 return CdbStatus::Error;
01265 }
01266
01267
01268
01269 theItr = CdbObjectItr( new OriginalObjectIterator( new CdbSimpleVectorAdapterItr< CdbCPtr<CdbSQLOriginalObject> >( originalObjects ),
01270 CdbConditionPtr( this->clone( ))));
01271
01272
01273
01274 return CdbStatus::Success;
01275 }
01276
01277 CdbStatus
01278 CdbSQLApiCondition::storeObject( CdbObjectFactoryBase& theObjectFactory,
01279 const BdbTime& theBegin,
01280 const BdbTime& theEnd,
01281 CdbObjectPtr& theObjectPtr )
01282 {
01283 const char* errorStr = "CdbSQLApiCondition::storeObject() -- ERROR";
01284
01285 CDB_DEBUG_STREAM
01286 << "CDB_STORE_OBJECT_1: condition=" << name( )
01287 << " begin_time=" << CdbTimeUtils::time2string( theBegin )
01288 << " end_time=" << CdbTimeUtils::time2string( theEnd ) << endl;
01289
01290 CdbStatus result = CdbStatus::Error;
01291
01292 theObjectPtr = 0;
01293
01294 do {
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311 BdbTime truncatedEnd = theEnd;
01312
01313
01314
01315
01316 CdbCPtr<CdbSQLPartition> partitionPtr;
01317
01318 if( _myConditionPtr->isPartitionable( )) {
01319
01320
01321
01322 if( CdbStatus::Success != _myLocalSQLOriginPtr->find_topmost_partition( partitionPtr,
01323 theBegin )) {
01324 ErrMsg(error) << errorStr << "\n"
01325 << " Failed to locate an open partition for the begin time\n"
01326 << " BEGIN VALIDITY TIME: " << CdbTimeUtils::time2string( theBegin ) << " : " << theBegin << "\n"
01327 << " CONDITION NAME: \"" << name( ) << "\"" << endmsg;
01328 break;
01329 }
01330
01331
01332
01333 if( partitionPtr->isClosed( )) {
01334 ErrMsg(error) << errorStr << "\n"
01335 << " The partition is closed for modifications.\n"
01336 << " Storing new objects in the closed partition is not allowed.\n"
01337 << " PARTITION ID: " << partitionPtr->id( ) << "\n"
01338 << " CONDITION NAME: \"" << name( ) << "\"" << endmsg;
01339 break;
01340 }
01341 if( !partitionPtr->isInstantiated( )) {
01342 ErrMsg(error) << errorStr << "\n"
01343 << " The partition is not instantiated yet.\n"
01344 << " Storing new objects into a partition in this state is not allowed.\n"
01345 << " PARTITION ID: " << partitionPtr->id( ) << "\n"
01346 << " CONDITION NAME: \"" << name( ) << "\"" << endmsg;
01347 break;
01348 }
01349
01350
01351
01352 CdbSQLCell cell = partitionPtr->cell( );
01353 if( truncatedEnd > cell.endValidity ) truncatedEnd = cell.endValidity;
01354 }
01355
01356
01357
01358
01359 {
01360 BdbTime truncateTime = CdbEnvironment::getTruncateTime( );
01361 if( truncateTime < truncatedEnd ) {
01362
01363 if( truncateTime <= theBegin ) {
01364 ErrMsg(error) << errorStr << "\n"
01365 << " Wrong value of the truncate time found in the job's environment.\n"
01366 << " This time is not allwed to be less or equal to the begin time\n"
01367 << " of stored objects. The job may be inproperly configured.\n"
01368 << " TRUNCATE TIME: " << CdbTimeUtils::time2string( truncatedEnd ) << " : " << truncatedEnd << endmsg;
01369 break;
01370 }
01371 truncatedEnd = truncateTime;
01372
01373 CDB_DEBUG_STREAM << "CDB_STORE_OBJECT_1: truncated_end_time=" << CdbTimeUtils::time2string( truncatedEnd ) << endl;
01374 }
01375 }
01376
01377
01378
01379 if( _myConditionPtr->isPartitionable( )) {
01380 if( _myLocalSQLOriginPtr->id( ) != partitionPtr->originId( )) {
01381 ErrMsg(error) << errorStr << "\n"
01382 << " The partition does not belong to current database. Therefore it can't\n"
01383 << " be used to store new objects locally.\n"
01384 << " PARTITION ID: " << partitionPtr->id( ) << "\n"
01385 << " CONDITION NAME: \"" << name( ) << "\"" << endmsg;
01386 break;
01387 }
01388 } else {
01389 if( _myLocalSQLOriginPtr->id( ) != _myConditionPtr->parent( )->id( )) {
01390 ErrMsg(error) << errorStr << "\n"
01391 << " The condition does not belong to current database. Therefore it can't\n"
01392 << " be used to store new objects locally.\n"
01393 << " CONDITION NAME: \"" << name( ) << "\"" << endmsg;
01394 break;
01395 }
01396 }
01397
01398
01399
01400
01401
01402
01403 CdbSQLApi* topLevelApiPtr = dynamic_cast< CdbSQLApi* >( parentDatabase( )->parent( ).get( ));
01404 assert( 0 != topLevelApiPtr );
01405
01406 if( CdbStatus::Success != topLevelApiPtr->storeObject( theObjectPtr,
01407 theObjectFactory,
01408 _myConditionPtr,
01409 partitionPtr,
01410 CdbConditionPtr( this->clone( )),
01411 theBegin,
01412 truncatedEnd )) break;
01413 assert( !theObjectPtr.isNull( ));
01414
01415 CDB_DEBUG_STREAM << "CDB_STORE_OBJECT_1: " << theObjectPtr->id( ) << endl;
01416
01417
01418
01419 result = CdbStatus::Success;
01420
01421 } while( false );
01422
01423 return result;
01424 }
01425
01426 CdbStatus
01427 CdbSQLApiCondition::storeAndTruncateObject( CdbObjectFactoryBase& theObjectFactory,
01428 const BdbTime& theStoreTime,
01429 const BdbTime& theTruncateTime,
01430 CdbObjectPtr& theObjectPtr )
01431 {
01432 return storeObject( theObjectFactory,
01433 theStoreTime,
01434 BdbTime::plusInfinity,
01435 theObjectPtr );
01436 }
01437
01438 CdbStatus
01439 CdbSQLApiCondition::split( const BdbTime& theTime )
01440 {
01441 ErrMsg(warning) << "CdbSQLApiCondition::split() -- WARNING.\n"
01442 << " The 'split interval' is the 'noop' operations in this\n"
01443 << " implementation of the API. This operation is only provided for backward\n"
01444 << " compatibility with the old condition database. Eventually it will be phased out." << endmsg;
01445
01446 return CdbStatus::Success;
01447 }
01448
01449 bool
01450 CdbSQLApiCondition::isValid( )
01451 {
01452 return true;
01453 }
01454
01455 bool
01456 CdbSQLApiCondition::isOpen( )
01457 {
01458 return true;
01459 }
01460
01461 CdbStatus
01462 CdbSQLApiCondition::open( )
01463 {
01464 return CdbStatus::Success;
01465 }
01466
01467 CdbStatus
01468 CdbSQLApiCondition::close( )
01469 {
01470 return CdbStatus::Success;
01471 }
01472
01473 CdbStatus
01474 CdbSQLApiCondition::findRevision( CdbRevisionPtr& thePtr,
01475 const BdbTime& theId,
01476 unsigned short thePartitionId )
01477 {
01478 CdbStatus result = CdbStatus::Error;
01479
01480
01481
01482 CdbCPtr<CdbSQLRevision> persistentRevisionPtr;
01483
01484 if( CdbStatus::Success != ( result = _myConditionPtr->find_revision( persistentRevisionPtr,
01485 theId,
01486 thePartitionId ))) {
01487 return result;
01488 }
01489
01490
01491
01492 thePtr = new CdbSQLApiRevision( CdbConditionPtr( this->clone( )),
01493 persistentRevisionPtr );
01494
01495
01496
01497 return CdbStatus::Success;
01498 }
01499
01500 CdbStatus
01501 CdbSQLApiCondition::findRevision( CdbRevisionPtr& thePtr,
01502 const char* theName,
01503 unsigned short thePartitionId )
01504 {
01505 CdbStatus result = CdbStatus::Error;
01506
01507
01508
01509 CdbCPtr<CdbSQLRevision> persistentRevisionPtr;
01510
01511 if( CdbStatus::Success != ( result = _myConditionPtr->find_revision( persistentRevisionPtr,
01512 theName,
01513 thePartitionId ))) {
01514 return result;
01515 }
01516
01517
01518
01519 thePtr = new CdbSQLApiRevision( CdbConditionPtr( this->clone( )),
01520 persistentRevisionPtr );
01521
01522
01523
01524 return CdbStatus::Success;
01525 }
01526
01527 CdbStatus
01528 CdbSQLApiCondition::revisionIdIterator( CdbItr<BdbTime>& theItr,
01529 unsigned short thePartitionId )
01530 {
01531 const char* errorStr = "CdbSQLApiCondition::revisionIdIterator() -- ERROR";
01532
01533 CdbStatus result = CdbStatus::Error;
01534
01535
01536
01537 std::vector< CdbCPtr<CdbSQLRevision> > vectorOfRevisions;
01538
01539 if( CdbStatus::Success != ( result = _myConditionPtr->revisions( vectorOfRevisions,
01540 thePartitionId ))) {
01541 ErrMsg(error) << errorStr << endl
01542 << " Failed to locate the MetaData objects for the current condition/partition." << endmsg;
01543 return result;
01544 }
01545
01546
01547
01548 theItr = CdbItr<BdbTime>( new RevisionIdIterator( vectorOfRevisions ));
01549
01550
01551
01552 return CdbStatus::Success;
01553 }
01554
01555 CdbStatus
01556 CdbSQLApiCondition::revisionNameIterator( CdbItr<const char*>& theItr,
01557 unsigned short thePartitionId )
01558 {
01559 const char* errorStr = "CdbSQLApiCondition::revisionNameIterator() -- ERROR";
01560
01561 CdbStatus result = CdbStatus::Error;
01562
01563
01564
01565 std::vector< CdbCPtr<CdbSQLRevision> > vectorOfRevisions;
01566
01567 if( CdbStatus::Success != ( result = _myConditionPtr->revisions( vectorOfRevisions,
01568 thePartitionId ))) {
01569 ErrMsg(error) << errorStr << endl
01570 << " Failed to locate the MetaData objects for the current condition/partition." << endmsg;
01571 return result;
01572 }
01573
01574
01575
01576 theItr = CdbItr<const char*>( new RevisionNameIterator( vectorOfRevisions ));
01577
01578
01579
01580 return CdbStatus::Success;
01581 }
01582
01583 CdbStatus
01584 CdbSQLApiCondition::createRevision( CdbRevisionPtr& thePtr,
01585 const BdbTime& theId,
01586 const char* theName,
01587 const char* theDescription,
01588 unsigned short thePartitionId )
01589 {
01590 return CdbStatus::NotImplemented;
01591 }
01592
01593 CdbStatus
01594 CdbSQLApiCondition::historyEventIterator( CdbHistoryEventItr& theItr,
01595 const BdbTime& theBeginTime,
01596 const BdbTime& theEndTime,
01597 const char** theEventsToSelect )
01598 {
01599 return CdbStatus::NotImplemented;
01600 }
01601
01602 CdbStatus
01603 CdbSQLApiCondition::historyEventTypeIterator( CdbHistoryEventTypeItr& theItr )
01604 {
01605 return CdbStatus::NotImplemented;
01606 }
01607
01608 CdbStatus
01609 CdbSQLApiCondition::findInitialPartition( CdbCPtr<CdbSQLPartition>& thePartitionPtr,
01610 const BdbTime& theValidityTime,
01611 const BdbTime& theInsertionTime ) const
01612 {
01613 const char* errorStr = "CdbSQLApiCondition::findInitialPartition() -- ERROR";
01614
01615 CdbStatus result = CdbStatus::Error;
01616
01617
01618
01619
01620 if( BdbTime::plusInfinity == theInsertionTime ) {
01621
01622 if( CdbStatus::Success != ( result = _myMasterSQLOriginPtr->find_topmost_partition( thePartitionPtr,
01623 theValidityTime ))) {
01624 ErrMsg(error) << errorStr << endl
01625 << " Failed to find a 'topmost' partition for specified validity time" << endl
01626 << " at the master origin." << endl
01627 << " VALIDITY TIME: " << theValidityTime << endmsg;
01628 return result;
01629 }
01630
01631 } else {
01632
01633 if( CdbStatus::Success != ( result = _myMasterSQLOriginPtr->find_partition( thePartitionPtr,
01634 theValidityTime,
01635 theInsertionTime ))) {
01636 ErrMsg(error) << errorStr << endl
01637 << " Failed to find a partition at specified point of 2-D timespace" << endl
01638 << " at the master origin." << endl
01639 << " VALIDITY TIME: " << theValidityTime << endl
01640 << " INSERTION TIME: " << theInsertionTime << endmsg;
01641 return result;
01642 }
01643 }
01644
01645
01646
01647
01648
01649 if(( _myLocalSQLOriginPtr->id( ) == thePartitionPtr->originId( )) &&
01650 ( _myLocalSQLOriginPtr->id( ) != _myMasterSQLOriginPtr->id( ))) {
01651
01652 unsigned short partitionId = thePartitionPtr->id( );
01653
01654 if( CdbStatus::Success != ( result = _myLocalSQLOriginPtr->find_partition( thePartitionPtr,
01655 partitionId ))) {
01656 ErrMsg(error) << errorStr << endl
01657 << " Failed to locate a final partition with ID=" << partitionId << endl
01658 << " at the local database where it's supposed to belong to." << endl
01659 << " The local database may not be properly initialized/loaded." << endmsg;
01660 return result;
01661 }
01662 }
01663
01664
01665
01666 return CdbStatus::Success;
01667 }
01668
01669 CdbStatus
01670 CdbSQLApiCondition::findNextPartition( CdbCPtr<CdbSQLPartition>& thePartitionPtr,
01671 const BdbTime& theValidityTime ) const
01672 {
01673 const char* fatalStr = "CdbSQLApiCondition::findNextPartition() -- FATAL ERROR";
01674 const char* errorStr = "CdbSQLApiCondition::findNextPartition() -- ERROR";
01675
01676
01677
01678 if( thePartitionPtr.isNull( )) {
01679
01680 ErrMsg(fatal) << fatalStr << endl
01681 << " Null pointer passed into the method where a valid partition" << endl
01682 << " object was expected. This is a fatal internal error indicating" << endl
01683 << " either a memory corruption or an inconsistency in a database." << endmsg;
01684
01685 return CdbStatus::IllegalParameters;
01686 }
01687
01688
01689
01690 CdbStatus result = CdbStatus::Error;
01691
01692
01693
01694
01695 unsigned short prevPartitionId = thePartitionPtr->id( );
01696
01697 if( CdbStatus::Success != ( result = _myMasterSQLOriginPtr->find_next_partition( thePartitionPtr,
01698 theValidityTime ))) {
01699
01700
01701
01702 if( CdbStatus::NotFound != result ) {
01703 ErrMsg(error) << errorStr << endl
01704 << " Failed to find a 'next' partition for specified validity time" << endl
01705 << " at the master registry." << endl
01706 << " VALIDITY TIME: " << theValidityTime << endl
01707 << " PREVIOUS PARTITION: #" << prevPartitionId << endmsg;
01708 }
01709
01710
01711
01712
01713 return result;
01714 }
01715
01716
01717
01718
01719
01720 if(( _myLocalSQLOriginPtr->id( ) == thePartitionPtr->originId( )) &&
01721 ( _myLocalSQLOriginPtr->id( ) != _myMasterSQLOriginPtr->id( ))) {
01722
01723 unsigned short nextPartitionId = thePartitionPtr->id( );
01724
01725 if( CdbStatus::Success != ( result = _myLocalSQLOriginPtr->find_partition( thePartitionPtr,
01726 nextPartitionId ))) {
01727 ErrMsg(error) << errorStr << endl
01728 << " Failed to find a partition #" << nextPartitionId << " at the local registry." << endmsg;
01729 return result;
01730 }
01731 }
01732
01733
01734
01735 return CdbStatus::Success;
01736 }
01737
01738 CdbStatus
01739 CdbSQLApiCondition::doFindObjectAtPartition( const CdbRevisionPolicy& thePolicy,
01740 const BdbTime& theValidityTime,
01741 const BdbTime& theInsertionTime,
01742 CdbCPtr<CdbSQLVisibleObject>& theVisibleObjectPtr,
01743 BdbTime& theBeginOfVisiblePeriod,
01744 BdbTime& theEndOfVisiblePeriod,
01745 BdbTime& theBeginOfDurationPeriod,
01746 BdbTime& theEndOfDurationPeriod ) const
01747 {
01748 const char* debugStr = "CdbSQLApiCondition::doFindObjectAtPartition()";
01749 const char* errorStr = "CdbSQLApiCondition::doFindObjectAtPartition() -- ERROR";
01750 const char* fatalStr = "CdbSQLApiCondition::doFindObjectAtPartition() -- FATAL ERROR";
01751
01752 CdbStatus status = CdbStatus::Error;
01753
01754
01755
01756 assert( _myConditionPtr->isPartitionable( ));
01757
01758
01759
01760 bool useRevisions = thePolicy.useRevision( );
01761 BdbTime rId = thePolicy.revisionId( );
01762
01763 if( useRevisions ) {
01764
01765 ;
01766
01767 } else if( BdbTime::plusInfinity == theInsertionTime ) {
01768
01769 useRevisions = true;
01770 rId = BdbTime::plusInfinity;
01771
01772 } else {
01773
01774 rId = theInsertionTime;
01775 }
01776
01777
01778
01779
01780 BdbTime creationTime = _myConditionPtr->created( );
01781
01782 if( rId < creationTime ) {
01783 ErrMsg(error) << errorStr << endl
01784 << " Specified revision identifier / insertion time is older" << endl
01785 << " than the time when the condition was created." << endl
01786 << " The current view may be inproperly configured for the condition." << endl
01787 << " REVISION ID / INSERTION TIME : " << rId << endl
01788 << " CONDITION CREATION TIME : " << creationTime << endl
01789 << " CONDITION NAME : \"" << name( ) << "\"" << endl
01790 << " PARENT FOLDER NAME : \"" << parent( )->name( ) << "\"" << endl
01791 << " VIEW NAME : \"" << parent( )->parentView( )->name( ) << "\"" << endmsg;
01792
01793 return CdbStatus::Error;
01794 }
01795
01796
01797
01798
01799
01800
01801
01802
01803 CdbCPtr<CdbSQLPartition> partitionPtr;
01804
01805 if( CdbStatus::Success != ( status = findInitialPartition( partitionPtr,
01806 theValidityTime,
01807 rId ))) {
01808 return status;
01809 }
01810
01811
01812 if( CdbEnvironment::getDebugMode( ) != 0 )
01813 cout << debugStr << endl
01814 << "{" << endl
01815 << " Found initial partition ID=" << partitionPtr->id( ) << endl
01816 << "}" << endl;
01817
01818
01819 if( partitionPtr->isClosed( )) {
01820 if( partitionPtr->endInsertion( ) <= creationTime ) {
01821
01822
01823 if( CdbEnvironment::getDebugMode( ) != 0 )
01824 cout << debugStr << endl
01825 << "{" << endl
01826 << " The just found partition is already 'closed' and its upper 'insertion'" << endl
01827 << " time limit is older than the creation time of the current condition." << endl
01828 << " So no object has been found." << endl
01829 << " creationTime : " << creationTime << endl
01830 << " partitionPtr->endInsertion( ) : " << partitionPtr->endInsertion( ) << endl
01831 << "}" << endl;
01832
01833
01834 return CdbStatus::NotFound;
01835 }
01836 }
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905 theBeginOfVisiblePeriod = partitionPtr->beginValidity( );
01906 theEndOfVisiblePeriod = partitionPtr->endValidity( );
01907
01908 assert( theBeginOfVisiblePeriod < theEndOfVisiblePeriod );
01909
01910
01911
01912 bool isFirstPath = true;
01913
01914
01915 do {
01916
01917
01918 if( CdbEnvironment::getDebugMode( ) != 0 )
01919 cout << debugStr << endl
01920 << "{" << endl
01921 << " isFirstPath : " << ( isFirstPath ? "Yes" : "No" ) << endl
01922 << "}" << endl;
01923
01924
01925 if( !isFirstPath ) {
01926
01927
01928
01929
01930
01931
01932
01933
01934 if( CdbStatus::Success != ( status = findNextPartition( partitionPtr,
01935 theValidityTime ))) {
01936 return status;
01937 }
01938
01939
01940 if( CdbEnvironment::getDebugMode( ) != 0 )
01941 cout << debugStr << endl
01942 << "{" << endl
01943 << " Found next partition ID=" << partitionPtr->id( ) << endl
01944 << "}" << endl;
01945
01946
01947 if( partitionPtr->isClosed( )) {
01948 if( partitionPtr->endInsertion( ) <= creationTime ) {
01949
01950
01951 if( CdbEnvironment::getDebugMode( ) != 0 )
01952 cout << debugStr << endl
01953 << "{" << endl
01954 << " The just found partition is already 'closed' and its upper 'insertion'" << endl
01955 << " time limit is older than the creation time of the current condition." << endl
01956 << " So no object has been found." << endl
01957 << " creationTime : " << creationTime << endl
01958 << " partitionPtr->endInsertion( ) : " << partitionPtr->endInsertion( ) << endl
01959 << "}" << endl;
01960
01961
01962 return CdbStatus::NotFound;
01963 }
01964 }
01965
01966
01967
01968 if( partitionPtr->beginValidity( ) > theBeginOfVisiblePeriod ) theBeginOfVisiblePeriod = partitionPtr->beginValidity( );
01969 if( partitionPtr->endValidity( ) < theEndOfVisiblePeriod ) theEndOfVisiblePeriod = partitionPtr->endValidity( );
01970
01971 assert( theBeginOfVisiblePeriod < theEndOfVisiblePeriod );
01972 }
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985 if( isFirstPath ) {
01986 ;
01987 } else {
01988 if( CdbStatus::Success != ( status = _myConditionPtr->topmost_revision_id( rId,
01989 partitionPtr->id( )))) {
01990 ErrMsg(error) << errorStr << endl
01991 << " Failed to find the 'topmost' revision in a scope of the partition." << endl
01992 << " CONDITION NAME : \"" << name( ) << "\"" << endl
01993 << " PARENT FOLDER NAME : \"" << parent( )->name( ) << "\"" << endl
01994 << " VIEW NAME : \"" << parent( )->parentView( )->name( ) << "\"" << endl
01995 << " PARTITION ID : " << partitionPtr->id( ) << endmsg;
01996
01997 return status;
01998 }
01999 }
02000
02001
02002
02003
02004 if( useRevisions ) {
02005
02006
02007 if( CdbEnvironment::getDebugMode( ) != 0 )
02008 cout << debugStr << endl
02009 << "{" << endl
02010 << " Find by revision" << endl
02011 << " next curent partition number : " << partitionPtr->id( ) << endl
02012 << " rId : " << rId << endl
02013 << " theValidityTime : " << CdbTimeUtils::time2string( theValidityTime) << " : " << theValidityTime << endl
02014 << "}" << endl;
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027 status = _myConditionPtr->find_visible_object( theVisibleObjectPtr,
02028 theValidityTime,
02029 partitionPtr->id( ),
02030 rId );
02031
02032
02033 if( CdbEnvironment::getDebugMode( ) != 0 )
02034 cout << debugStr << endl
02035 << "{" << endl
02036 << " status = _myConditionPtr->find_visible_object() : " << status << endl
02037 << "}" << endl;
02038
02039
02040 if(( CdbStatus::Success == status ) ||
02041 ( CdbStatus::NotFound == status )) {
02042
02043
02044
02045
02046
02047 if( theVisibleObjectPtr->begin( ) > theBeginOfVisiblePeriod ) theBeginOfVisiblePeriod = theVisibleObjectPtr->begin( );
02048 if( theVisibleObjectPtr->end( ) < theEndOfVisiblePeriod ) theEndOfVisiblePeriod = theVisibleObjectPtr->end( );
02049
02050 assert( theBeginOfVisiblePeriod < theEndOfVisiblePeriod );
02051
02052 if( CdbStatus::Success == status ) {
02053
02054
02055
02056
02057 theBeginOfDurationPeriod = theVisibleObjectPtr->stored( );
02058 theEndOfDurationPeriod = BdbTime::plusInfinity;
02059
02060 return CdbStatus::Success;
02061 }
02062
02063 } else {
02064
02065 ErrMsg(error) << errorStr << endl
02066 << " Failed to find an object by a revision." << endl
02067 << " CONDITION NAME : \"" << name( ) << "\"" << endl
02068 << " PARENT FOLDER NAME : \"" << parent( )->name( ) << "\"" << endl
02069 << " VIEW NAME : \"" << parent( )->parentView( )->name( ) << "\"" << endl
02070 << " PARTITION ID : " << partitionPtr->id( ) << endl
02071 << " VALIDITY TIME : " << CdbTimeUtils::time2string( theValidityTime ) << " : " << theValidityTime << endl
02072 << " REVISION ID : " << CdbTimeUtils::time2string( rId ) << " : " << rId << endmsg;
02073 return status;
02074 }
02075
02076 } else {
02077
02078 ErrMsg(fatal) << fatalStr << endl
02079 << " Finding objects by an insertion time is not presently implemented." << endl
02080 << " Make sure that you're using an explicitly specified revision in a configuration" << endl
02081 << " of this condition." << endl
02082 << " CONDITION NAME : \"" << name( ) << "\"" << endl
02083 << " PARENT FOLDER NAME : \"" << parent( )->name( ) << "\"" << endl
02084 << " VIEW NAME : \"" << parent( )->parentView( )->name( ) << "\"" << endl
02085 << " PARTITION ID : " << partitionPtr->id( ) << endl
02086 << " INSERTION TIME : " << CdbTimeUtils::time2string( rId ) << " : " << rId << endmsg;
02087
02088 return CdbStatus::Error;
02089 }
02090 isFirstPath = false;
02091
02092 } while( true );
02093
02094 return CdbStatus::Error;
02095 }
02096
02097 CdbStatus
02098 CdbSQLApiCondition::doFindObject( const CdbRevisionPolicy& thePolicy,
02099 const BdbTime& theValidityTime,
02100 const BdbTime& theInsertionTime,
02101 CdbCPtr<CdbSQLVisibleObject>& theVisibleObjectPtr,
02102 BdbTime& theBeginOfVisiblePeriod,
02103 BdbTime& theEndOfVisiblePeriod,
02104 BdbTime& theBeginOfDurationPeriod,
02105 BdbTime& theEndOfDurationPeriod ) const
02106 {
02107 const char* debugStr = "CdbSQLApiCondition::doFindObject()";
02108 const char* errorStr = "CdbSQLApiCondition::doFindObject() -- ERROR";
02109 const char* fatalStr = "CdbSQLApiCondition::doFindObject() -- FATAL ERROR";
02110
02111 CdbStatus status = CdbStatus::Error;
02112
02113
02114
02115 assert( !_myConditionPtr->isPartitionable( ));
02116
02117
02118
02119 bool useRevisions = thePolicy.useRevision( );
02120 BdbTime rId = thePolicy.revisionId( );
02121
02122 if( useRevisions ) {
02123
02124 ;
02125
02126 } else if( BdbTime::plusInfinity == theInsertionTime ) {
02127
02128 useRevisions = true;
02129 rId = BdbTime::plusInfinity;
02130
02131 } else {
02132
02133 rId = theInsertionTime;
02134 }
02135
02136
02137
02138
02139 theBeginOfVisiblePeriod = BdbTime::minusInfinity;
02140 theEndOfVisiblePeriod = BdbTime::plusInfinity;
02141
02142
02143
02144
02145 if( useRevisions ) {
02146
02147
02148 if( CdbEnvironment::getDebugMode( ) != 0 )
02149 cout << debugStr << endl
02150 << "{" << endl
02151 << " Find by revision" << endl
02152 << " rId : " << rId << endl
02153 << " theValidityTime : " << CdbTimeUtils::time2string( theValidityTime) << " : " << theValidityTime << endl
02154 << "}" << endl;
02155
02156
02157
02158
02159 if( CdbStatus::Success != ( status = _myConditionPtr->find_visible_object( theVisibleObjectPtr,
02160 theValidityTime,
02161 0,
02162 rId ))) {
02163 ErrMsg(error) << errorStr << endl
02164 << " Failed to find an object by a revision." << endl
02165 << " CONDITION NAME : \"" << name( ) << "\"" << endl
02166 << " PARENT FOLDER NAME : \"" << parent( )->name( ) << "\"" << endl
02167 << " VIEW NAME : \"" << parent( )->parentView( )->name( ) << "\"" << endl
02168 << " VALIDITY TIME : " << CdbTimeUtils::time2string( theValidityTime ) << " : " << theValidityTime << endl
02169 << " REVISION ID : " << CdbTimeUtils::time2string( rId ) << " : " << rId << endmsg;
02170 return status;
02171 }
02172
02173
02174
02175 if( theVisibleObjectPtr->begin( ) > theBeginOfVisiblePeriod ) theBeginOfVisiblePeriod = theVisibleObjectPtr->begin( );
02176 if( theVisibleObjectPtr->end( ) < theEndOfVisiblePeriod ) theEndOfVisiblePeriod = theVisibleObjectPtr->end( );
02177
02178 assert( theBeginOfVisiblePeriod < theEndOfVisiblePeriod );
02179
02180
02181
02182
02183 theBeginOfDurationPeriod = theVisibleObjectPtr->stored( );
02184 theEndOfDurationPeriod = BdbTime::plusInfinity;
02185
02186 return CdbStatus::Success;
02187
02188 } else {
02189
02190 ErrMsg(fatal) << fatalStr << endl
02191 << " Finding objects by an insertion time is not presently implemented." << endl
02192 << " Make sure that you're using an explicitly specified revision in a configuration" << endl
02193 << " of this condition." << endl
02194 << " CONDITION NAME : \"" << name( ) << "\"" << endl
02195 << " PARENT FOLDER NAME : \"" << parent( )->name( ) << "\"" << endl
02196 << " VIEW NAME : \"" << parent( )->parentView( )->name( ) << "\"" << endl
02197 << " INSERTION TIME : " << CdbTimeUtils::time2string( rId ) << " : " << rId << endmsg;
02198
02199 return CdbStatus::Error;
02200 }
02201 return CdbStatus::Error;
02202 }
02203
02204
02205
02206