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

CdbObject.hh

Go to the documentation of this file.
00001 #ifndef CDB_OBJECT_HH
00002 #define CDB_OBJECT_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbObject.hh,v 1.14 2005/09/08 00:59:32 gapon Exp $
00006 
00007 #include "BdbTime/BdbTime.hh"
00008 
00009 #include "CdbBase/CdbCPtrBase.hh"
00010 #include "CdbBase/CdbCPtr.hh"
00011 #include "CdbBase/CdbObjectPtrFwd.hh"
00012 #include "CdbBase/CdbConditionPtrFwd.hh"
00013 #include "CdbBase/CdbType2Id.hh"
00014 #include "CdbBase/CdbObjectTranslator.hh"
00015 
00016 class CdbStateId;
00017 
00018 /// The transient interface to a condition object.
00019 /**
00020   * More details to come...
00021   */
00022 class CdbObject {
00023 
00024 friend class CdbCPtrBase< CdbObject >;  // Who destroys me
00025 
00026 private:
00027 
00028   /// The constructor (NOT IMPLEMENTED)
00029   /**
00030     * Is disabled...
00031     */
00032     CdbObject( );
00033 
00034   /// The copy constructor (NOT IMPLEMENTED)
00035   /**
00036     * Is disabled...
00037     */
00038     CdbObject( const CdbObject& theObject );
00039 
00040   /// The assignment operator (NOT IMPLEMENTED)
00041   /**
00042     * Is disabled...
00043     */
00044     CdbObject& operator=( const CdbObject& theObject );
00045 
00046 protected:
00047 
00048   /// The normal constructor.
00049   /**
00050     * Initialize context with specified parameters.
00051     *
00052     * @see CdbCondition
00053     * @see CdbConditionPtr
00054     * @see BdbTime
00055     */
00056     CdbObject( const CdbConditionPtr& theConditionPtr,          /**< the smart pointer providing a back back link to the parent condition object */
00057                const BdbTime&         theBeginOriginalValidity, /**< a point where the object's 'original' validity begins from */
00058                const BdbTime&         theEndOriginalValidity,   /**< ... and finishes (exclusing) at */
00059                const BdbTime&         theBeginValidity,         /**< a point where the object's 'visible' validity begins from */
00060                const BdbTime&         theEndValidity,           /**< ... and finishes (exclusing) at */
00061                const BdbTime&         theBeginDuration,         /**< a point where the object's duration at insertin time begins from */
00062                const BdbTime&         theEndDuration,           /**< ... and finishes (exclusing) at */
00063                const BdbTime&         theInsertionTime          /**< the time when an object was inserted */
00064              );
00065 
00066   /// The destructor.
00067   /**
00068     * More details...
00069     */
00070     virtual ~CdbObject( );
00071 
00072 public:
00073 
00074   /// The static locator for a condition object
00075   /**
00076     * This locator uses the "state identifier" to resolve the right
00077     * instance of the condition object in the scope of a database.
00078     *
00079     * The database itself as well as the top-level API object are two
00080     * optional parameters of this method. If either (or both) of them are
00081     * not specified then the corresponding default values will be used.
00082     *
00083     * @see CdbObjectPtr
00084     * @see BdbTime
00085     * @see CdbStateId
00086     *
00087     * @return the completion status of the operation
00088     */
00089     static CdbStatus instance( CdbObjectPtr&     theObjectPtr,
00090                                const char*       theFullPath,
00091                                const BdbTime&    theValidityTime,
00092                                const CdbStateId& theStateId,                /**< NOTE: the view identifier is encoded here */
00093                                const char*       theDatabaseName       = 0, /**< the database name */
00094                                const char*       theImplementationName = 0, /**< the implementation name */
00095                                const char*       theTechnologyName     = 0  /**< the technology name */
00096                              );
00097 
00098   /// Convert into a transient form
00099   /**
00100     * The method will try to find and use a "persistnet-to-transient" translator
00101     * to produce a transient object of the specified (by the pointer) type. The translator
00102     * is supposed to be registered with the top-level CDB API object of the current
00103     * "technology" and "implementation".
00104     *
00105     * @see Cdb::registerTranslator()
00106     * @see Cdb::convertToTransient()
00107     */
00108     template< class T >
00109     static CdbStatus transient( T*&                 theTransientPtr,
00110                                 const CdbObjectPtr& theObjectPtr )
00111     {
00112         if( theObjectPtr.isNull( )) return CdbStatus::IllegalParameters;
00113 
00114       // Find the translator matching a pair of the desired transient and the actual
00115       // persistent types.
00116 
00117         CdbCPtr<CdbObjectTranslator> translatorPtr;
00118         CdbStatus result = findTranslator( translatorPtr,
00119                                            CdbType2Id<T>::id( ),
00120                                            theObjectPtr );
00121         if( CdbStatus::Success != result ) return result;
00122 
00123       // Proceed with the found translator.
00124 
00125         return translatorPtr->transient( theTransientPtr,
00126                                          theObjectPtr );
00127     }
00128 
00129 private:
00130 
00131   /// Find a user defined "persistent-to-transient" translator (helper)
00132   /**
00133     * That's essentially a redirection to the Cdb::findTranslator() method meant
00134     * to break a potential circular dependency between CdbObject and Cdb classes,
00135     * and to avoid doing non-specific operations in the Cdb class.
00136     *
00137     * @see Cdb::findTranslator()
00138     */
00139     static CdbStatus findTranslator( CdbCPtr<CdbObjectTranslator>& theTranslatorPtr,
00140                                      unsigned int                  theTransientTypeId,
00141                                      const CdbObjectPtr&           theObjectPtr );
00142 public:
00143 
00144   /// Return a smart pointer to the parent condition object.
00145   /**
00146     * @see CdbCondition
00147     * @see CdbConditionPtr
00148     */
00149     const CdbConditionPtr& parent( ) const;
00150 
00151   /// The beginning of the "original" validity interval of an object
00152   /**
00153     * @see BdbTime
00154     */
00155     const BdbTime& beginOriginal( ) const;
00156 
00157   /// The end of the "original" validity interval of an object
00158   /**
00159     * @see CdbObject::beginOriginal()
00160     */
00161     const BdbTime& endOriginal( ) const;
00162 
00163   /// The beginning of the "visible" validity interval of an object
00164   /**
00165     * NOTE: that the difference between the "visible" validity interval of an object and
00166     * the validity interval it was originally stored with in the database. The "visible"
00167     * validity interval is how the object was seen in the database when iy was fetched
00168     * from it at specific revision level. This interval may get shorten (or even completelly
00169     * overshadowed) as new objects are stored in a condition.
00170     * Meanwhile the original (stored) validity never changes.
00171     *
00172     * @see BdbTime
00173     */
00174     const BdbTime& begin( ) const;
00175 
00176   /// The end of the "visible" validity interval of an object
00177   /**
00178     * @see CdbObject::begin()
00179     */
00180     const BdbTime& end( ) const;
00181 
00182   /// The beginning of the "duration" interval of an object at the insertion dimension
00183   /**
00184     * The "duration" interval is 
00185     *
00186     * @see BdbTime
00187     */
00188     const BdbTime& beginDuration( ) const;
00189 
00190   /// The end of the "duration" interval of an object at the insertion dimension
00191   /**
00192     * @see CdbObject::beginDuration()
00193     */
00194     const BdbTime& endDuration( ) const;
00195 
00196   /// The insertion time of an object
00197   /**
00198     * This is an actual time when an object was stored in the database.
00199     *
00200     * @see BdbTime
00201     */
00202     const BdbTime& inserted( ) const;
00203 
00204   /// An object identifier
00205   /**
00206     * The contents and the semantic of the string is defined by the underlying
00207     * persistent technology.
00208     *
00209     * The method has to be implemented by a subclass.
00210     */
00211     virtual std::string id( ) const = 0;
00212 
00213     /// A 'legacy' object identifier
00214   /**
00215     * The contents and the semantic of the string is defined by the underlying
00216     * persistent technology.
00217     *
00218     * The method has to be implemented by a subclass.
00219     */
00220     virtual std::string legacyId( ) const = 0;
00221 
00222   /// A persistent type name
00223   /**
00224     * The contents and the semantic of the string is defined by the underlying
00225     * persistent technology.
00226     *
00227     * The method has to be implemented by a subclass.
00228     */
00229     virtual std::string type( ) const = 0;
00230 
00231 private:
00232 
00233     CdbConditionPtr _myParent;
00234 
00235     BdbTime _beginOriginalValidity;
00236     BdbTime _endOriginalValidity;
00237     BdbTime _beginValidity;
00238     BdbTime _endValidity;
00239     BdbTime _beginDuration;
00240     BdbTime _endDuration;
00241 
00242     BdbTime _inserted;
00243 };
00244 
00245 #endif  // CDB_OBJECT_HH

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