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

CdbBdbObjectCloneImpl.hh

Go to the documentation of this file.
00001 #ifndef CDBBDB_OBJECT_CLONE_IMPL_HH
00002 #define CDBBDB_OBJECT_CLONE_IMPL_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbBdbObjectCloneImpl.hh,v 1.2 2004/10/21 20:35:49 gapon Exp $
00006 
00007 #include "CdbBase/CdbCommon.hh"
00008 
00009 #include <string>
00010 
00011 #include <oo.h>         // Objectivity/DB core API
00012 #include <ooas.h>       // Objectivity/DB Active Schema API
00013 
00014 // Forward declarations
00015 
00016 class CdbBdbObjectCloneUserAction;
00017 
00018 template< class T > class CdbBdbCache;
00019 
00020 /// This class implements the "deep clone" facility for persistent objects.
00021 /**
00022   * More details...
00023   */
00024 class CdbBdbObjectCloneImpl {
00025 
00026     friend class CdbBdbObjectClone;     // who is able to create and destroy me
00027 
00028 private:
00029 
00030   /// Default constructor (NOT IMPLEMENTED)
00031   /**
00032     * Implements the contract of the corresponding method of the facade class.
00033     *
00034     * @see CdbBdbObjectClone::CdbBdbObjectClone()
00035     */
00036     CdbBdbObjectCloneImpl( );
00037 
00038   /// Normal constructor
00039   /**
00040     * Implements the contract of the corresponding method of the facade class.
00041     *
00042     * @see CdbBdbObjectClone::CdbBdbObjectClone()
00043     */
00044     CdbBdbObjectCloneImpl(          const ooRef(ooObj)& theHint,
00045                            CdbBdbObjectCloneUserAction* theUserAction,
00046                                                    bool deepCopyMode,
00047                                                    bool verboseMode,
00048                                                    bool debugMode );
00049 
00050   /// Destructor
00051   /**
00052     * Implements the contract of the corresponding method of the facade class.
00053     *
00054     * @see CdbBdbObjectClone::~CdbBdbObjectClone()
00055     */
00056     virtual ~CdbBdbObjectCloneImpl( );
00057 
00058   /// Make a persistent clone of the specified object
00059   /**
00060     * Implements the contract of the corresponding method of the facade class.
00061     *
00062     * @see CdbBdbObjectClone::clone()
00063     */
00064     virtual bool clone( const ooHandle(ooObj)& theInputH,
00065                               ooHandle(ooObj)& theOutputH );
00066   /// Set hint
00067   /**
00068     * Implements the contract of the corresponding method of the facade class.
00069     *
00070     * @see CdbBdbObjectClone::setHint()
00071     */
00072     ooRef(ooObj) setHint( const ooRef(ooObj)& theHint );
00073 
00074   /// Set user action
00075   /**
00076     * Implements the contract of the corresponding method of the facade class.
00077     *
00078     * @see CdbBdbObjectClone::setUserAction()
00079     */
00080     CdbBdbObjectCloneUserAction* setUserAction( CdbBdbObjectCloneUserAction* theUserAction );
00081 
00082 private:
00083 
00084     /// An automatic prefix class
00085     /**
00086       * This internal helper class is meant to help with forming a proper prefix
00087       * string depending on the current "level" in a copied graph.
00088       */
00089     class Prefix {
00090 
00091     private:
00092 
00093       /// Default constructor (NOT IMPLEMENTED)
00094       /**
00095         * The object's default does not make any sense at all.
00096         */
00097         Prefix( );
00098 
00099       /// Copy constructor (NOT IMPLEMENTED)
00100       /**
00101         * Copying of these objects does not make any sense at all.
00102         */
00103         Prefix( const Prefix& );
00104 
00105       /// Assignment operator (NOT IMPLEMENTED)
00106       /**
00107         * Copying of these objects does not make any sense at all.
00108         */
00109         Prefix& operator=( const Prefix& );
00110 
00111     public:
00112 
00113       /// Normal constructor
00114       /**
00115         * Decrement the current level at the caller's context.
00116         * Set up the current prefix string at the current context.
00117         */
00118         Prefix(               int& theLevel,        /**< a reference onto the caller's context */
00119                 const std::string& theStep = "  "   /**< the step between levels */
00120               );
00121 
00122       /// Destructor
00123       /**
00124         * Decrement the current level at the caller's context.
00125         */
00126         ~Prefix( );
00127 
00128       /// An explicit type conversion operator
00129       /**
00130         * Will return a pointer onto the current prefix string.
00131         *
00132         * NONE: The returned string is bound to the local object's context.
00133         */
00134         const char* c_str( ) const;
00135 
00136     private:
00137 
00138                int& _level;   // a reference onto the caller's context
00139         std::string _str;     // the current prefix
00140     };
00141 
00142   // Helper methods
00143 
00144     bool cloneObject( const ooHandle(ooObj)& theH,
00145                             ooHandle(ooObj)& theOutputH );
00146 
00147     void copyObjectContents( const ooas::Class_Object& theClassObject,
00148                                    ooas::Class_Object& theOutputClassObject,
00149                                          const Prefix& thePrefix );
00150 
00151     void copyStringValue( const ooas::String_Value& theStringValue,
00152                                 ooas::String_Value& theOutputStringValue,
00153                                       const Prefix& thePrefix );
00154 
00155     void copyVArrayObject( const ooas::VArray_Object& theVArrayObject,
00156                                  ooas::VArray_Object& theOutputVArrayObject,
00157                                   const ooas::d_Type& theVArrayTypeDsc,
00158                                         const Prefix& thePrefix );
00159 
00160 private:
00161 
00162   // Current context
00163 
00164     bool _deepCopyMode;
00165     bool  _verboseMode;
00166     bool    _debugMode;
00167 
00168     CdbBdbObjectCloneUserAction* _userAction;
00169 
00170     ooHandle(ooObj)    _hintH;  // a location of the output objects  (set up by the c-tor)
00171     ooHandle(ooObj)    _rootH;  // an object a cloning begins        (set up by the cloning method)
00172     ooHandle(ooObj) _currentH;  // a current object being copied     (is "root" at the beginning, then changes)
00173 
00174   // A dictionary to map OID-s of input (to be copied) objects into their output
00175   // copies. The dictionary is used for the following reasons:
00176   //
00177   // - to optimize copy for objects which have already been copied
00178   // - to prevent duplicating the same source object at a destination
00179   // - to escape from the cyclic graph problem
00180 
00181     CdbBdbCache< ooRef(ooObj) >* _dictionary;
00182 
00183   // Supplementary data structures
00184 
00185     int _level;     // the current level in a copied graph (begins with 0 for 'root' object)
00186 };
00187 
00188 #endif  // CDBBDB_OBJECT_CLONE_IMPL_HH

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