00001 #ifndef CDB_CONDITION_HH 00002 #define CDB_CONDITION_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbCondition.hh,v 1.25 2005/09/15 05:04:11 gapon Exp $ 00006 00007 #include "BdbTime/BdbTime.hh" 00008 00009 #include "CdbBase/CdbCommon.hh" 00010 00011 #include "CdbBase/CdbStateControl.hh" 00012 #include "CdbBase/CdbHistoryProvider.hh" 00013 #include "CdbBase/CdbCloneable.hh" 00014 00015 #include "CdbBase/CdbCPtrBase.hh" 00016 #include "CdbBase/CdbObjectPtrFwd.hh" 00017 #include "CdbBase/CdbRevisionPtrFwd.hh" 00018 #include "CdbBase/CdbConditionPtrFwd.hh" 00019 #include "CdbBase/CdbFolderPtrFwd.hh" 00020 #include "CdbBase/CdbDatabasePtrFwd.hh" 00021 00022 #include "CdbBase/CdbItr.hh" 00023 #include "CdbBase/CdbObjectItr.hh" 00024 00025 #include "CdbBase/CdbPathName.hh" 00026 00027 #include <string> 00028 00029 class CdbObjectFactoryBase; 00030 class CdbRevisionPolicy; 00031 class CdbId; 00032 class CdbCompositeName; 00033 00034 /// The transient representation for the persistent Condition. 00035 /** 00036 * Note, that this is an abstract class specifying the interface to the condition. 00037 * It also maintains the general status of the Condition object as it's seen to its 00038 * clients through the API. 00039 * 00040 * This class also includes the CdbStateControl, CdbHistoryProvider 00041 * and CdbCloneable interfaces. 00042 * 00043 * @see CdbStateControl 00044 * @see CdbHistoryProvider 00045 */ 00046 class CdbCondition : public CdbStateControl, 00047 public CdbHistoryProvider, 00048 protected CdbCloneable< CdbCondition > { 00049 00050 friend class CdbCPtrBase< CdbCondition >; // Who destroys me. 00051 00052 public: 00053 00054 /// Static locator for a condition 00055 /** 00056 * Locates specified condition object and returns a smart pointer to the transient 00057 * object of the current class. This "shortcut" allows to avoid the complicated 00058 * multi-staged process of the object location, which is useless when 00059 * the intermediate objects are not needed. 00060 * 00061 * The last parameter (a pointer to the top-level Cdb singleton) is optional. If 0 is 00062 * passed then a default instance is used. 00063 * 00064 * Note, that if specified object is not found then a smart pointer is initialized 00065 * to point to 0. 00066 * 00067 * @see Cdb 00068 * @see CdbConditionPtr 00069 * @see CdbStatus 00070 * 00071 * @return a completion status 00072 */ 00073 static CdbStatus instance( CdbConditionPtr& theConditionPtr, /**< the smart pointer to be initialized */ 00074 const char* theFullPathName, /**< the full path name of the condition */ 00075 const char* theViewName = 0, /**< the view name */ 00076 const char* theDatabaseName = 0, /**< the database name */ 00077 const char* theImplementationName = 0, /**< the implementation name */ 00078 const char* theTechnologyName = 0 /**< the technology name */ 00079 ); 00080 00081 /// Static locator for a condition 00082 /** 00083 * Unlike the previous method, this one uses "extended" identifier of a view 00084 * instead of its name. 00085 * 00086 * @see CdbId 00087 */ 00088 static CdbStatus instance( CdbConditionPtr& theConditionPtr, /**< the smart pointer to be initialized */ 00089 const char* theFullPathName, /**< the full path name of the condition */ 00090 const CdbId& theViewId, /**< the view identifier */ 00091 const char* theDatabaseName = 0, /**< the database name */ 00092 const char* theImplementationName = 0, /**< the implementation name */ 00093 const char* theTechnologyName = 0 /**< the technology name */ 00094 ); 00095 00096 /// Static locator for a condition 00097 /** 00098 * Unlike the previous methods, this one uses "physical address" of a condition. 00099 * 00100 * @see CdbId 00101 */ 00102 static CdbStatus instance( CdbConditionPtr& theConditionPtr, /**< the smart pointer to be initialized */ 00103 const CdbId& thePhysicalAddress, /**< the 'physical address' of a condition */ 00104 const char* theDatabaseName = 0, /**< the database name */ 00105 const char* theImplementationName = 0, /**< the implementation name */ 00106 const char* theTechnologyName = 0 /**< the technology name */ 00107 ); 00108 00109 /// Static locator for a condition 00110 /** 00111 * Unlike the previous methods, this one uses "physical name" of a condition. 00112 * 00113 * @see CdbCompositeName 00114 */ 00115 static CdbStatus instance( CdbConditionPtr& theConditionPtr, /**< the smart pointer to be initialized */ 00116 const CdbCompositeName& thePhysicalName, /**< the 'physical name' of a condition */ 00117 const char* theDatabaseName = 0, /**< the database name */ 00118 const char* theImplementationName = 0, /**< the implementation name */ 00119 const char* theTechnologyName = 0 /**< the technology name */ 00120 ); 00121 00122 /// Static locator for a condition 00123 /** 00124 * The method is able to deal with multiple formats of the condition name, including 00125 * the above mentioned: 00126 * 00127 * <path> - a full path to the condition in a view: "/emc/EmcFooClassP" 00128 * <physical address> - a 'physical' address of the condition in the Distributed CDB: "0::112" 00129 * <physical name> - a 'physical' name of the condition in the Distributed CDB: "MASTER::EmcFooClassP" 00130 * 00131 * @see CdbCompositeName 00132 */ 00133 static CdbStatus instanceFromAny( CdbConditionPtr& theConditionPtr, /**< the smart pointer to be initialized */ 00134 const char* theConditionName, /**< the 'any' name of a condition */ 00135 const char* theDatabaseName = 0, /**< the database name */ 00136 const char* theImplementationName = 0, /**< the implementation name */ 00137 const char* theTechnologyName = 0 /**< the technology name */ 00138 ); 00139 00140 /// Calculate the full path for the condition 00141 /** 00142 * The path would include all preceeding folders and the specified condition 00143 * itself. 00144 * 00145 * The method will return an empty path containing "" in case of any problem met 00146 * while calculating the path. 00147 * 00148 * NOTE: For conditions found via their 'physical' names or addresses the nethod 00149 * will return that empty path since their (CdbCondition) API objects 00150 * do not have any parent folders or views. 00151 * 00152 * @see class CdbCondition 00153 */ 00154 static std::string fullPathName( const CdbConditionPtr& theConditionPtr ); 00155 00156 private: 00157 00158 /// The default constructor (IS NOT IMPLEMENTED) 00159 /** 00160 * Is disabled... 00161 */ 00162 CdbCondition( ); 00163 00164 protected: 00165 00166 /// The normally used constructor will set the internal parameters of an object. 00167 /** 00168 * Initialize the context of the CdbCondition with specified set of fixed parameters. 00169 * This will also validate the internal state of the object. 00170 * 00171 * The condition name must be non 0 pointer. 00172 * 00173 * This API component has two parameters to specify its "parent" API objects. Their values 00174 * would vary depending on how the Condition API object was created: 00175 * 00176 * - for conditions found through views the parent folder must be a non zero 00177 * pointer. The database pointer must always have a non zero value. 00178 * 00179 * - for conditions located by their 'physical address' or 'physical name' the only valid 00180 * connection to a hierarchy of API components is through the non zero database pointer. 00181 * The folder pointer must be zero in this case. 00182 * 00183 * The value of the folder pointer can also be used as flags to determine 00184 * how the condition was created. 00185 * 00186 * @see CdbFolder 00187 * @see CdbFolderPtr 00188 * @see CdbDatabase 00189 * @see CdbDatabasePtr 00190 * @see CdbCompositeName 00191 * @see CdbId 00192 */ 00193 CdbCondition( const CdbFolderPtr& theFolderPtr, /**< the parent folder object (view conditions only) */ 00194 const CdbDatabasePtr& theDatabasePtr, /**< the parent database object */ 00195 const char* theName /**< the name in its folder's namespace */ 00196 ); 00197 00198 /// The copy constructor 00199 /** 00200 * Details... 00201 */ 00202 CdbCondition( const CdbCondition& theCondition ); 00203 00204 /// The destructor. 00205 /** 00206 * Is only available for the derived classes and friends to prevent accidental 00207 * deletion of objects. 00208 */ 00209 virtual ~CdbCondition( ); 00210 00211 /// The assignment operator 00212 /** 00213 * Details... 00214 */ 00215 CdbCondition& operator=( const CdbCondition& theCondition ); 00216 00217 public: 00218 00219 /// Return a smart pointer to the parent CdbFolder object. 00220 /** 00221 * This is a folder where this condition is directly connected to. Note, that for conditions 00222 * found through their 'physical' names or addresses the returned pointer would always 00223 * be equal to 0. 00224 * 00225 * @see CdbFolder 00226 * @see CdbFolderPtr 00227 * 00228 * @return a smart pointer to the parent object 00229 */ 00230 const CdbFolderPtr& parent( ) const; 00231 00232 /// Return a smart pointer to the parent CdbDatabase object. 00233 /** 00234 * This is a database where this condition is directly connected to. 00235 * 00236 * @see CdbDatabase 00237 * @see CdbDatabasePtr 00238 * 00239 * @return a smart pointer to the parent object 00240 */ 00241 const CdbDatabasePtr& parentDatabase( ) const; 00242 00243 /// Obtain the name of the condition in its folder. 00244 /** 00245 * It's guaranteed that a non 0 pointer will be returned. 00246 * 00247 * @return a const pointer onto to the object's name 00248 */ 00249 const char* name( ) const; 00250 00251 /// Obtain the condition description 00252 /** 00253 * This method is supposed to be implemented by the corresponding subclass. 00254 * 00255 * @return a string with the object's description 00256 */ 00257 virtual std::string description( ) const = 0; 00258 00259 /// Obtain the condition type. 00260 /** 00261 * This method is supposed to be implemented by the corresponding subclass. 00262 * 00263 * @return TRUE for 'partitionable conditions and FALSE for 'regular' ones. 00264 */ 00265 virtual bool isPartitionable( ) const = 0; 00266 00267 /// Obtain the full condition name in the 'physical' namespace. 00268 /** 00269 * This method is supposed to be implemented by the corresponding subclass. 00270 * 00271 * @return a value of the composite 'physical' name. 00272 */ 00273 virtual CdbCompositeName physicalName( ) const = 0; 00274 00275 /// Obtain the full condition identifier in the 'physical' namespace. 00276 /** 00277 * This method is supposed to be implemented by the corresponding subclass. 00278 * 00279 * @return a value of the 'physical' identifier. 00280 */ 00281 virtual CdbId physicalId( ) const = 0; 00282 00283 /// Get the condition creation time. 00284 /** 00285 * This is the time when the corresponding 'physical' condition was created. 00286 * Note the difference of this time between the condition registration time. 00287 * 00288 * @see CdbCondition::registered() 00289 * 00290 * @return a value of the creation time. 00291 */ 00292 virtual BdbTime created( ) const = 0; 00293 00294 /// Get the condition registration time. 00295 /** 00296 * This is a time when the condition entry was put into the folder (view). 00297 * Note the difference of this time from the corresponding 'physical' condition 00298 * creation time. 00299 * 00300 * @see CdbCondition::created() 00301 * 00302 * @return a value of the registration time. 00303 */ 00304 virtual BdbTime registered( ) const = 0; 00305 00306 /// Get the last time when the condition was modified. 00307 /** 00308 * This method is supposed to be implemented by the corresponding subclass. 00309 * 00310 * @return a value of the modification time. 00311 */ 00312 virtual BdbTime modified( ) const = 0; 00313 00314 /// Find a condition object 00315 /** 00316 * This method will initialize a smart pointer to point onto a transient object 00317 * representing an object of the CdbObject class. It may also initialize the smart pointer to point 00318 * onto 0 object in case of failure. The corresponding error status will be 00319 * returned in this case. 00320 * 00321 * The resulting object will be valid at given validity time point 00322 * and optional insertion time point, assuming that other parameters 00323 * of this operation are taken from a view the current condition belongs to. 00324 * 00325 * NOTE: The use or not use of the optional insertion time depends on two factors: 00326 * (a) the kind of the condition and (b) the current revision policy 00327 * for thsi condition. 00328 * 00329 * @see BdbTime 00330 * @see CdbObject 00331 * @see CdbObjectPtr 00332 * @see CdbRevisionPolicy 00333 * @see CdbStatus 00334 * 00335 * @return the completion status 00336 */ 00337 virtual CdbStatus findObject( CdbObjectPtr& theObjectPtr, /**< the smart pointer to an object to be initialized */ 00338 const BdbTime& theValidityTime, /**< the point in the validity dimension */ 00339 const BdbTime& theInsertionTime = BdbTime::plusInfinity /**< the point in the insertion time dimension */ 00340 ) = 0; 00341 00342 /// Find a condition object 00343 /** 00344 * Unlike the previous method, this one expects an explicit value 00345 * of the "revision policy" to be used when looking for a condition object. 00346 */ 00347 virtual CdbStatus findObject( CdbObjectPtr& theObjectPtr, 00348 const CdbRevisionPolicy& thePolicy, 00349 const BdbTime& theValidityTime, 00350 const BdbTime& theInsertionTime = BdbTime::plusInfinity 00351 ) = 0; 00352 00353 /// An iterator for the objects 00354 /** 00355 * Initializes an iterator to find all Objects at a given scope of a condition. 00356 * The iterator when advanced will return an CdbObjectPtr smart pointer. It may also 00357 * initialize the iterator to be in the non-valid state in case of failure. 00358 * he corresponding error status will be returned in this case. 00359 * 00360 * The scope is defined by an interval at the validity dimension and the current 00361 * configuration of a view. 00362 * 00363 * @see BdbTime 00364 * @see CdbObject 00365 * @see CdbObjectPtr 00366 * @see CdbStatus 00367 * 00368 * @return the completion status 00369 */ 00370 virtual CdbStatus objectIterator( CdbObjectItr& theItr, /**< the iterator to be initialized */ 00371 const BdbTime& theBeginValidity = BdbTime::minusInfinity, /**< the begin point for iteration */ 00372 const BdbTime& theEndValidity = BdbTime::plusInfinity /**< the end point for iteration */ 00373 ) = 0; 00374 00375 /// An iterator for the objects 00376 /** 00377 * Unlike the previous method, this one expects an explicit value 00378 * of the "revision policy" to be used when looking for condition objects. 00379 * 00380 * Note, that for partitionable conditions the specified validity interval 00381 * would be reduced to the width of the specified (by the policy) partition. 00382 * No error status would be reported if these intervals won't intersect. 00383 */ 00384 virtual CdbStatus objectIterator( CdbObjectItr& theItr, /**< the iterator to be initialized */ 00385 const CdbRevisionPolicy& thePolicy, /**< the policy to be used to iterate for objects */ 00386 const BdbTime& theBeginValidity = BdbTime::minusInfinity, /**< the begin point for iteration */ 00387 const BdbTime& theEndValidity = BdbTime::plusInfinity /**< the end point for iteration */ 00388 ) = 0; 00389 00390 /// An iterator for the 'original' objects 00391 /** 00392 * Initializes an iterator to find all Objects at a given scope of a condition. 00393 * The iterator when advanced will return an CdbObjectPtr smart pointer. It may also 00394 * initialize the iterator to be in the non-valid state in case of failure. 00395 * he corresponding error status will be returned in this case. 00396 * 00397 * The scope is defined by an interval at the insertion dimension, a partition identifier 00398 * and the corresponding 'physical' condition as it's defined by the current configuration 00399 * of a view. 00400 * 00401 * @see BdbTime 00402 * @see CdbObject 00403 * @see CdbObjectPtr 00404 * @see CdbStatus 00405 * 00406 * @return the completion status 00407 */ 00408 virtual CdbStatus originalObjectIterator( CdbObjectItr& theItr, /**< the iterator to be initialized */ 00409 const BdbTime& theBeginInsertion = BdbTime::minusInfinity, /**< the begin point for iteration */ 00410 const BdbTime& theEndInsertion = BdbTime::plusInfinity, /**< the end point for iteration */ 00411 const unsigned short thePartitionId = 0 /**< the partition identifier */ 00412 ) = 0; 00413 00414 /// Create and store a new condition object in the database. 00415 /** 00416 * The new object is created via a special factory passed by a reference onto 00417 * its (factory's) base class. It's expected that a client of this API is responsible 00418 * for preparing these factories creating concrete persistent objects on the base 00419 * of a particular technology. If the creation and verification of this objects succeeds 00420 * then a new object is registered in the database with specified interval of validity. 00421 * 00422 * @see BdbTime 00423 * @see CdbObject 00424 * @see CdbObjectFactoryBase 00425 * @see CdbStatus 00426 * 00427 * @return the completion status 00428 */ 00429 CdbStatus storeObject( CdbObjectFactoryBase& theObjectFactory, /**< a factory implementing an object creation */ 00430 const BdbTime& theBegin, /**< the begin point for a stored object */ 00431 const BdbTime& theEnd /**< the end point for a stored object */ 00432 ); 00433 00434 /// Create and store a new condition object in the database. 00435 /** 00436 * This is an extended form of the previous method returning a smart pointer 00437 * corresponding to the newely created object. 00438 * 00439 * IMPORTANT: The validity interval of the returned object could be shorter 00440 * than the original intention if the corresponding restrictions 00441 * are imposed by the current view. 00442 */ 00443 virtual CdbStatus storeObject( CdbObjectFactoryBase& theObjectFactory, /**< a factory implementing an object creation */ 00444 const BdbTime& theBegin, /**< the begin point for a stored object */ 00445 const BdbTime& theEnd, /**< the end point for a stored object */ 00446 CdbObjectPtr& theObjectPtr /**< the object pointer to be filled out */ 00447 ) = 0; 00448 00449 /// Create and store a new condition object in the database. 00450 /** 00451 * This method is here for backward compatibility with the corresponding feature 00452 * of the old Condition/DB. 00453 */ 00454 CdbStatus storeAndTruncateObject( CdbObjectFactoryBase& theObjectFactory, /**< a factory implementing an object creation */ 00455 const BdbTime& theStoreTime, /**< the begin point for a stored object */ 00456 const BdbTime& theTruncateTime /**< the end point for a stored object */ 00457 ); 00458 00459 /// Create and store a new condition object in the database. 00460 /** 00461 * This is an extended form of the previous method returning a smart pointer 00462 * corresponding to the newely created object. 00463 * 00464 * IMPORTANT: The validity interval of the returned object could be shorter 00465 * than the original intention if the corresponding restrictions 00466 * are imposed by the current view. 00467 */ 00468 virtual CdbStatus storeAndTruncateObject( CdbObjectFactoryBase& theObjectFactory, /**< a factory implementing an object creation */ 00469 const BdbTime& theStoreTime, /**< the begin point for a stored object */ 00470 const BdbTime& theTruncateTime, /**< the end point for a stored object */ 00471 CdbObjectPtr& theObjectPtr /**< the object pointer to be filled out */ 00472 ) = 0; 00473 00474 /// Split the validity timeline at specified point. 00475 /** 00476 * ATTENTION: This is a temporary method for backward compatibility 00477 * with the old API introduced on a period of migration. 00478 */ 00479 virtual CdbStatus split( const BdbTime& theTime /**< a point of split */ 00480 ) = 0; 00481 00482 /// Find a revision by its identifier 00483 /** 00484 * This command if succeeded will initialize specified smart pointer 00485 * to point onto a revision description object with required characteristics. 00486 * 00487 * NOTE: The "partition identifier" parameter is only required for so called 00488 * "partitionable" conditions. 00489 * 00490 * @see CdbRevision 00491 * @see CdbRevisionPtr 00492 * @see CdbStatus 00493 * 00494 * @return a completion status 00495 */ 00496 virtual CdbStatus findRevision( CdbRevisionPtr& thePtr, /**< the smart pointer to be initialized */ 00497 const BdbTime& theId, /**< the revision identifier */ 00498 unsigned short thePartitionId = 0 /**< the partition identifier */ 00499 ) = 0; 00500 00501 /// Find a revision by its name 00502 /** 00503 * This command if succeeded will initialize specified smart pointer 00504 * to point onto a revision description object with required characteristics. 00505 * 00506 * NOTE: The "partition identifier" parameter is only required for so called 00507 * "partitionable" conditions. 00508 * 00509 * @see CdbRevision 00510 * @see CdbRevisionPtr 00511 * @see CdbStatus 00512 * 00513 * @return a completion status 00514 */ 00515 virtual CdbStatus findRevision( CdbRevisionPtr& thePtr, /**< the smart pointer to be initialized */ 00516 const char* theName, /**< the revision name */ 00517 unsigned short thePartitionId = 0 /**< the partition identifier */ 00518 ) = 0; 00519 00520 /// An iterator for the known revision identifiers 00521 /** 00522 * Initializes an iterator to find all revision identifiers at a scope of 00523 * the current condition/partition. The iterator when advanced will return an object 00524 * of BdbTime class. These objects can be turned into revision description 00525 * objects by calling CdbConditionMgr::findRevision() method described above. 00526 * 00527 * The iterator will be set into a "valid" state upon successfull completion. 00528 * 00529 * NOTE: The "partition identifier" parameter is only required for so called 00530 * "partitionable" conditions. 00531 * 00532 * @see CdbIItr::isValid() 00533 * @see CdbStatus 00534 * 00535 * @return completion status 00536 */ 00537 virtual CdbStatus revisionIdIterator( CdbItr<BdbTime>& theItr, /**< an iterator to be initialized */ 00538 unsigned short thePartitionId = 0 /**< the partition identifier */ 00539 ) = 0; 00540 00541 /// An iterator for the known revision names 00542 /** 00543 * Initializes an iterator to find all revision names at a scope of 00544 * the current condition/partition. The iterator when advanced will return 00545 * (pointers to) strings. These objects can be turned into revision description 00546 * objects by calling CdbConditionMgr::findRevision() method described above. 00547 * 00548 * The iterator will be set into a "valid" state upon successfull completion. 00549 * 00550 * NOTE: The "partition identifier" parameter is only required for so called 00551 * "partitionable" conditions. 00552 * 00553 * @see CdbIItr::isValid() 00554 * @see CdbStatus 00555 * 00556 * @return completion status 00557 */ 00558 virtual CdbStatus revisionNameIterator( CdbItr<const char*>& theItr, /**< an iterator to be initialized */ 00559 unsigned short thePartitionId = 0 /**< the partition identifier */ 00560 ) = 0; 00561 00562 /// Create a new revision 00563 /** 00564 * This command if succeeded will create a new revision with specified parameters 00565 * in a s cope of a condition (and partition for 'PARTTIONABLE' conditions). 00566 * It will also initialize a smart pointer onto a transient API object 00567 * representing a newely created revision. 00568 * 00569 * The operation would check if the revision can be created for a condition 00570 * it (the operation) is being used at. 00571 * 00572 * @see CdbRevision 00573 * @see CdbStatus 00574 * 00575 * @return a completion status 00576 */ 00577 virtual CdbStatus createRevision( CdbRevisionPtr& thePtr, /**< the smart pointer to be initialized */ 00578 const BdbTime& theId, /**< the revision identifier */ 00579 const char* theName, /**< the revision name */ 00580 const char* theDescription, /**< the revision description */ 00581 unsigned short thePartitionId = 0 /**< the partition identifier */ 00582 ) = 0; 00583 private: 00584 00585 // Fixed parameters of the condition 00586 00587 CdbFolderPtr _myParent; 00588 CdbDatabasePtr _myParentDatabase; 00589 std::string _myName; 00590 }; 00591 00592 #endif // CDB_CONDITION_HH
1.3-rc3