Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbDatabase.hh

Go to the documentation of this file.
00001 #ifndef CDB_DATABASE_HH
00002 #define CDB_DATABASE_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbDatabase.hh,v 1.16 2005/08/16 22:23:53 gapon Exp $
00006 
00007 #include "CdbBase/CdbStateControl.hh"
00008 #include "CdbBase/CdbHistoryProvider.hh"
00009 #include "CdbBase/CdbCloneable.hh"
00010 
00011 #include "CdbBase/CdbCPtrBase.hh"
00012 #include "CdbBase/CdbPtrFwd.hh"
00013 #include "CdbBase/CdbOriginPtrFwd.hh"
00014 #include "CdbBase/CdbDatabasePtrFwd.hh"
00015 #include "CdbBase/CdbPartitionPtrFwd.hh"
00016 #include "CdbBase/CdbViewPtrFwd.hh"
00017 #include "CdbBase/CdbViewItr.hh"
00018 #include "CdbBase/CdbConditionPtrFwd.hh"
00019 
00020 #include "CdbBase/CdbItr.hh"
00021 
00022 #include <string>
00023 
00024 class CdbId;
00025 class CdbCompositeName;
00026 
00027 /// The transient representation for the persistent database and its smart pointer type
00028 /**
00029   * Notes:
00030   *
00031   * - this is an abstract class specifying the interface to the databases.
00032   *   It also maintains the general status of the database object as it's seen to its
00033   *   clients through the API.
00034   *
00035   * - this class includes the CdbStateControl,
00036   *   CdbHistoryProvider and CdbCloneable interfaces.
00037   *
00038   * - there is a definition for the smart pointer class CdbDatabasePtr which is meant
00039   *   to be used by the clients of the Database class.
00040   *
00041   * - objects of this class will be destructed automatically by the smart pointer.
00042   *
00043   * @see CdbtateControl
00044   * @see CdbHistoryProvider
00045   * @see CdbCloneable
00046   */
00047 class CdbDatabase : public    CdbStateControl,
00048                     public    CdbHistoryProvider,
00049                     protected CdbCloneable< CdbDatabase > {
00050 
00051 friend class CdbCPtrBase< CdbDatabase >;
00052 
00053 private:
00054 
00055   /// The default constructor (NOT IMPLEMENTED)
00056   /**
00057     * More details...
00058     */
00059     CdbDatabase( );
00060 
00061 protected:
00062 
00063   /// The normally used constructor will set the internal parameters
00064   /// of an object.
00065   /**
00066     * Initialize the context of the database with specified set of parameters. This
00067     * will also validate the internal state of the object.
00068     *
00069     * The database name must not be a 0 pointer.
00070     */
00071     CdbDatabase( const CdbPtr& theCdbPtr,   /**< the back link to the parent object */
00072                  const char*   theName      /**< the database name */
00073                );
00074 
00075   /// The copy constructor
00076   /**
00077     * Details...
00078     */
00079     CdbDatabase( const CdbDatabase& theDatabase );
00080 
00081   /// The destructor.
00082   /**
00083     * Is only available for the derived classes and friends to prevent accidental
00084     * deletion of objects.
00085     */
00086     virtual ~CdbDatabase( );
00087 
00088   /// The assignment operator
00089   /**
00090     * Details...
00091     */
00092     CdbDatabase& operator=( const CdbDatabase& theDatabase );
00093 
00094 public:
00095 
00096   /// Static locator for a database object
00097   /**
00098     * Locates specified database object and returns a smart pointer to the transient
00099     * object of the current class. This "shortcut" allows to avoid the complicated
00100     * multi-staged process of the object location, which is useless when
00101     * the intermediate objects are not needed.
00102     *
00103     * If the database name is omitted then the default one is assumed.
00104     *
00105     * The last parameter (a pointer to the top-level Cdb singleton) is optional. If 0 is
00106     * passed then a default instance is used.
00107     *
00108     * Note, that if specified object is not found then a smart pointer is initialized
00109     * to point to 0.
00110     *
00111     * @see Cdb
00112     * @see CdbatabasePtr
00113     * @see CdbStatus
00114     *
00115     * @return a completion status
00116     */
00117     static CdbStatus instance( CdbDatabasePtr& theDatabasePtr,              /**< the smart pointer to be initialized */
00118                                const char*     theDatabaseName       = 0,   /**< the database name */
00119                                const char*     theImplementationName = 0,   /**< the implementation name */
00120                                const char*     theTechnologyName     = 0    /**< the technology name */
00121                              );
00122 
00123 public:
00124 
00125   /// Return a pointer to the parent object.
00126   /**
00127     * @see Cdb
00128     * @see CdbPtr
00129     */
00130     const CdbPtr& parent( ) const;
00131 
00132   /// Obtain the current name of the database.
00133   /**
00134     * @return a const non 0 pointer onto a database name
00135     */
00136     const char* name( ) const;
00137 
00138   /// Obtain the unique identifier of the database.
00139   /**
00140     * All databases in a distributed installation should have the same identifier
00141     * to distinguish them from other installations.
00142     *
00143     * This method is supposed to be implemented by the corresponding subclass.
00144     *
00145     * @return the value of the identifier
00146     */
00147     virtual BdbTime id( ) = 0;
00148 
00149   /// Obtain the creation time of the database
00150   /**
00151     * This is the actual creation time of this particular instance of the underlying database.
00152     * Note, that this value may differ (in fact it's equal or newer) from the database
00153     * identification timestampt.
00154     *
00155     * This method is supposed to be implemented by the corresponding subclass.
00156     *
00157     * @return a string with the object's description
00158     */
00159     virtual BdbTime created( ) = 0;
00160 
00161   /// Obtain the database description
00162   /**
00163     * This method is supposed to be implemented by the corresponding subclass.
00164     *
00165     * @return a string with the object's description
00166     */
00167     virtual std::string description( ) = 0;
00168 
00169   /// Set up an iterator of partitions at the MASTER
00170   /**
00171     * This method is supposed to be implemented by the corresponding subclass.
00172     *
00173     * @return CdbStatus::Success if the iterator is set up
00174     */
00175     virtual CdbStatus partitionIterator( CdbItr<unsigned short>& theItr     /**< the iterator to set up */
00176                                        ) = 0;
00177 
00178   /// Set up an iterator of partitions at specified (by ID) origin
00179   /**
00180     * This method is supposed to be implemented by the corresponding subclass.
00181     *
00182     * @return CdbStatus::Success if the iterator is set up, CdbStatus::NotFound
00183     *         if the specified origin does not have Partitions Layout.
00184     */
00185     virtual CdbStatus partitionIterator( CdbItr<unsigned short>& theItr,        /**< the iterator to set up */
00186                                          unsigned int            theOriginId    /**< the origin in question */
00187                                        ) = 0;
00188 
00189   /// Set up an iterator of partitions at specified (by NAME) origin
00190   /**
00191     * This method is supposed to be implemented by the corresponding subclass.
00192     *
00193     * @return CdbStatus::Success if the iterator is set up, CdbStatus::NotFound
00194     *         if the specified origin does not have Partitions Layout.
00195     */
00196     virtual CdbStatus partitionIterator( CdbItr<unsigned short>& theItr,        /**< the iterator to set up */
00197                                          const char*             theOriginName  /**< the origin in question */
00198                                        ) = 0;
00199 
00200   /// Find a partition
00201   /**
00202     * IMPORTANT NOTE:
00203     *
00204     *   This algorithm will use partition object from the local
00205     *   P-Layout if it will discover that the partition belongs to the current
00206     *   origin. This is a typical scenario for the SLAVE type origins.
00207     *
00208     * This method is supposed to be implemented by the corresponding subclass.
00209     *
00210     * @return CdbStatus::Success if the partition was found
00211     */
00212     virtual CdbStatus findPartition( CdbPartitionPtr& thePtr,       /**< the smart pointer to set up */
00213                                      unsigned short   thePartition  /**< the partition identifier */
00214                                    ) = 0;
00215 
00216   /// Find a partition at the specified (by ID) origin
00217   /**
00218     * Unlike the default algorithm (when no explicit origin specified) this one
00219     * would use partition directly from the specified origin.
00220     *
00221     * This method is supposed to be implemented by the corresponding subclass.
00222     *
00223     * @return CdbStatus::Success if the partition was found
00224     */
00225     virtual CdbStatus findPartition( CdbPartitionPtr& thePtr,       /**< the smart pointer to set up */
00226                                      unsigned short   thePartition, /**< the partition identifier */
00227                                      unsigned int     theOriginId   /**< the origin in question */
00228                                    ) = 0;
00229 
00230   /// Find a partition at the specified (by NAME) origin
00231   /**
00232     * Unlike the default algorithm (when no explicit origin specified) this one
00233     * would use partition directly from the specified origin.
00234     *
00235     * This method is supposed to be implemented by the corresponding subclass.
00236     *
00237     * @return CdbStatus::Success if the partition was found
00238     */
00239     virtual CdbStatus findPartition( CdbPartitionPtr& thePtr,       /**< the smart pointer to set up */
00240                                      unsigned short   thePartition, /**< the partition identifier */ 
00241                                      const char*      theOriginName /**< the origin in question */ 
00242                                    ) = 0;
00243 
00244   /// Return a pointer to the database's "origin" object.
00245   /**
00246     * This method is supposed to be implemented by the corresponding subclass.
00247     *
00248     * @see CdbOrigin
00249     * @see CdbOriginPtr
00250     */
00251     virtual CdbOriginPtr localOrigin( ) = 0;
00252 
00253   /// Set up an iterator of origins
00254   /**
00255     * This method is supposed to be implemented by the corresponding subclass.
00256     *
00257     * @return CdbStatus::Success if the iterator is set up
00258     */
00259     virtual CdbStatus originIterator( CdbItr<unsigned short>& theItr    /**< the iterator to set up */
00260                                     ) = 0;
00261 
00262   /// Find an origin (by name)
00263   /**
00264     * This method is supposed to be implemented by the corresponding subclass.
00265     *
00266     * @return CdbStatus::Success if the origin was found
00267     */
00268     virtual CdbStatus findOrigin( CdbOriginPtr& thePtr,     /**< the smart pointer to set up */
00269                                   const char*   theName     /**< the name of an origin */
00270                                 ) = 0;
00271 
00272   /// Find an origin (by id)
00273   /**
00274     * This method is supposed to be implemented by the corresponding subclass.
00275     *
00276     * @return CdbStatus::Success if the origin was found
00277     */
00278     virtual CdbStatus findOrigin( CdbOriginPtr&  thePtr,    /**< the smart pointer to set up */
00279                                   unsigned short theId      /**< the identifier of an origin */
00280                                 ) = 0;
00281 
00282   /// Default view name
00283   /**
00284     * This method is supposed to be implemented by the corresponding subclass.
00285     *
00286     * This name is delivered when a client is relying on this default.
00287     */
00288     virtual std::string defaultView( ) const = 0;
00289 
00290   /// Find the specified view
00291   /**
00292     * This method is supposed to be implemented by the corresponding subclass.
00293     *
00294     * This method initializes a smart pointer to a transient object
00295     * of the CdbView class representing the found view. It will initialize
00296     * the smart pointer to point onto 0 and return the corresponding error status
00297     * when specified object is not found or is not awailable for some
00298     * other reason.
00299     *
00300     * The only parameter to be specified when looking for a view is its name. If
00301     * a 0 pointer is passed instead of the name then a default view will be open.
00302     *
00303     * @see CdbView
00304     * @see CdbViewPtr
00305     * @see CdbStatus
00306     *
00307     * @return a completion status of the operation
00308     */
00309     virtual CdbStatus findView( CdbViewPtr& thePtr,         /**< a smart pointer to an object to be initialized */
00310                                 const char* theName = 0     /**< the object specifications */
00311                               ) = 0;
00312 
00313   /// Find the specified view
00314   /**
00315     * This method is supposed to be implemented by the corresponding subclass.
00316     *
00317     * Unlike the previous method, this one uses "extended" identifier of a view
00318     * to find the corresponding object.
00319     *
00320     * @see CdbId
00321     */
00322     virtual CdbStatus findView( CdbViewPtr&  thePtr,        /**< a smart pointer to an object to be initialized */
00323                                 const CdbId& theId          /**< the object specifications */
00324                               ) = 0;
00325 
00326   /// Initialize an instance of an iterator for the known views names
00327   /**
00328     * This method is supposed to be implemented by the corresponding subclass.
00329     *
00330     * The iterator will be set into a "valid" state upon successfull completion.
00331     *
00332     * @see CdbIItr::isValid()
00333     * @see CdbView
00334     * @see CdbViewItr
00335     * @see CdbStatus
00336     *
00337     * @return completion status
00338     */
00339     virtual CdbStatus viewIterator( CdbViewItr& theItr ) = 0;
00340 
00341   /// Initialize an instance of an iterator for the known 'physical' conditions
00342   /**
00343     * The iterator will produce a sequence of 'physical address' of found conditions
00344     * in a scope of all origins of the dataase. Use the "CdbDatabase::findCondition()"
00345     * method defined below to open actual conditions.
00346     *
00347     * This method is supposed to be implemented by the corresponding subclass.
00348     *
00349     * The iterator will be set into a "valid" state upon successfull completion.
00350     *
00351     * @see CdbIItr::isValid()
00352     * @see CdbView
00353     * @see CdbViewItr
00354     * @see CdbStatus
00355     *
00356     * @return completion status
00357     */
00358     virtual CdbStatus physicalConditionIterator( CdbItr<CdbId>& theItr ) = 0;
00359 
00360   /// Translate a string with a name of a 'physical' condition into its identifier
00361   /**
00362     * The operation will return CdbStatus::Success and set up a valid identifier
00363     * if the input name has a correct format and if the corresponding condition
00364     * is known to CDB.
00365     *
00366     * If an input name is valid but the condition doesn't exist in the database
00367     * then CdbStatus::NotFound will be returned.
00368     *
00369     * Other status values returned will depend on what exactly is wrong.
00370     */
00371     CdbStatus physicalConditionName2Id( CdbId&                  theId,
00372                                         const CdbCompositeName& theName );
00373 
00374   /// Translate an identifier of a 'physical' condition into its name
00375   /**
00376     * The operation will return CdbStatus::Success and set up a valid identifier
00377     * if the input name has a correct format and if the corresponding condition
00378     * is known to CDB.
00379     *
00380     * If an input name is valid but the condition doesn't exist in the database
00381     * then CdbStatus::NotFound will be returned.
00382     *
00383     * Other status values returned will depend on what exactly is wrong.
00384     */
00385     CdbStatus physicalConditionId2Name( CdbCompositeName& theName              ,
00386                                         const CdbId&      theId );
00387 
00388   /// Find the specified condition by its 'physical address'
00389   /**
00390     * This method is supposed to be implemented by the corresponding subclass.
00391     *
00392     * This method would locate a condition by its 'physical address'. See the description
00393     * of the constructor of the CdbCondition class for the implications of this method.
00394     *
00395     * @see CdbId
00396     */
00397     virtual CdbStatus findCondition( CdbConditionPtr& thePtr,   /**< a smart pointer to an object to be initialized */
00398                                      const CdbId&     theId     /**< the object specifications */
00399                                    ) = 0;
00400 
00401   /// Find the specified condition by its 'physical name'
00402   /**
00403     * This method is supposed to be implemented by the corresponding subclass.
00404     *
00405     * This method would locate a condition by its 'physical name'. See the description
00406     * of the constructor of the CdbCondition class for the implications of this method.
00407     *
00408     * @see CdbCompositeName
00409     */
00410     virtual CdbStatus findCondition( CdbConditionPtr&        thePtr,            /**< a smart pointer to an object to be initialized */
00411                                      const CdbCompositeName& thePhysicalName    /**< the object specifications */
00412                                    ) = 0;
00413 
00414 private:
00415 
00416     CdbPtr      _myParentPtr;
00417     std::string _myName;
00418 };
00419 
00420 #endif  // CDB_DATABASE_HH

Generated on Mon Dec 5 18:22:05 2005 for CDB by doxygen1.3-rc3