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

d_Object.h

Go to the documentation of this file.
00001 
00002 #ifndef d_Object_h
00003 #define d_Object_h 1
00004 //------------------------------------------------------------------------------
00005 
00006 #include "oObjectId.h"
00007 #include "d_Binary.h"
00008 #include "oStreamable.h"
00009 
00010 //------------------------------------------------------------------------------
00011 class _ODLL d_Database;
00012 class _ODLL d_Transaction;
00013 
00014 class _ODLL oContext;
00015 class _ODLL oStreamProtocol;
00016 class _ODLL oClass;
00017 class _ODLL oStorage;
00018 class _ODLL oSession;
00019 
00020 /**
00021  * The d_Object class is the base class for each persistent object.
00022  *
00023  * Every user objects that want to be persistent had to inherit this class.
00024  * 
00025  * It's an abstract class therefore cannot be instantiated.
00026  * 
00027  * You had to use the d_Ref template class for referencing persistent objects
00028  * rather than C++ pointers [see d_Ref].
00029  *
00030  * LOCATION:
00031  * d_Object.h
00032  *
00033  * USAGE:
00034  * class <user-class-name> : public d_Object
00035  * {
00036  *   ...
00037  * }
00038  * 
00039  * Where:
00040  * 
00041  * <user-class-name>:   is the name of user class
00042  *
00043  * EXAMPLES:
00044  * class Invoice : public d_Object     * Persistent class
00045  * {
00046  *   d_ULong                  number;
00047  *   d_Ref<Customer>          customer;
00048  *   d_Set< d_Ref<Product> >  products;
00049  * };
00050  *
00051  * SEE ALSO:
00052  * d_Ref, d_Ref_Any
00053  *
00054  * ODMG:
00055  * Compliant 
00056  */
00057 class _ODLL d_Object : public oStreamable
00058 {
00059   public:
00060 
00061     /**
00062      * Default constructor.
00063      *
00064      * ODMG    :  Compliant 
00065      */
00066     d_Object ();
00067 
00068     /**
00069      * Destructor.
00070      *
00071      * ODMG    :  Compliant 
00072      */
00073     virtual ~d_Object();
00074 
00075     /**
00076      * Create a transient object.
00077      *
00078      * It allocates memory for transient (not persistent) object. This is
00079      * the redefinition of C++ new operator. 
00080      *
00081      * ODMG    :  Compliant 
00082      */
00083     void * operator new (size_t iSize);
00084 
00085     /**
00086      * Create a persistent object.
00087      *
00088      * Allocates a persistent object of class <iClassName> into <iDb>
00089      * database. The database <iDb> must be opened as read_write [see
00090      * d_Database], a transaction must be opened and the class <iClassName>
00091      * must be defined as persistent class.
00092      *
00093      * ODMG    :  Compliant+ (with optional Extension)
00094      */
00095     void* operator new (size_t iSize, d_Database* iDb, const char* iClassName,
00096                         int iTxMode = TRANSACTIONAL );
00097 
00098     // Internal.
00099     void* operator new (size_t iSize, oStorage* iStorage, const char* iClassName,
00100                         int iTxMode = TRANSACTIONAL );
00101     // Internal.
00102     void* operator new (size_t iSize, oObjectId& iOid, int iTxMode );
00103 
00104     /**
00105      * Remove the object permanently in database and memory.
00106      *
00107      * ODMG    :  Compliant
00108      */
00109     void operator delete (void* iAddress );
00110 
00111 #ifdef COMP_MSVC6
00112     // Internal.
00113     // NOTE: MSVC6 NEEDS SPECIAL DELETE OPERATORS FOR EACH NEW OPERATORS.
00114     void operator delete (void* iAddress, d_Database* iDb, const char* iClassName,
00115                           int iTxMode )
00116                    {d_Object::operator delete(iAddress);}
00117     // Internal.
00118     // NOTE: MSVC6 NEEDS SPECIAL DELETE OPERATORS FOR EACH NEW OPERATORS.
00119     void operator delete (void* iAddress, oStorage* iStorage, const char* iClassName,
00120                           int iTxMode )
00121                    {d_Object::operator delete(iAddress);}
00122     // Internal.
00123     // NOTE: MSVC6 NEEDS SPECIAL DELETE OPERATORS FOR EACH NEW OPERATORS.
00124     void operator delete (void* iAddress, oObjectId& iOid, int iTxMode )
00125                    {d_Object::operator delete(iAddress);}
00126 #endif
00127 
00128     /**
00129      * Remove the object permanently in database and memory.
00130      *
00131      * This method is needed by collections deletion
00132      *
00133      * ODMG    :  Extension
00134      */
00135     void delete_object();
00136 
00137     /**
00138      * Mark the object as modified.
00139      *
00140      * When context commits the object will be updated on storage.
00141      *
00142      * Enterprise Edition: This operation requires an exclusive lock to
00143      *                     the server.
00144      *
00145      * ODMG    :  Compliant 
00146      */
00147     void mark_modified ();
00148 
00149     /**
00150      * Object activation trigger.
00151      *
00152      * It's the trigger called asynchronously by Orient ODBMS when the object
00153      * is requested by a context. It can be defined as a special "cache
00154      * constructor".
00155      *
00156      * It's useful for reset transient members before the use.
00157      *
00158      * If the user class, inherited by d_Object, doesn't define a own
00159      * d_activate virtual method, by default is called the
00160      * d_Object::d_activate() that doesn't execute any operation.
00161      *
00162      * SEE ALSO:  d_deactivate()
00163      * ODMG    :  Compliant
00164      */
00165     virtual void d_activate ();
00166 
00167     /**
00168      * Object deactivation trigger.
00169      *
00170      * It's the trigger called asynchronously by Orient ODBMS when the object
00171      * is freed in memory. It can be defined as a special "cache destructor".
00172      *
00173      * It's useful when an object had to free some memory (transient members)
00174      * before to die.
00175      *
00176      * If the user class, inherited by d_Object, doesn't define a own
00177      * d_deactivate virtual method, by default is called the
00178      * d_Object::d_deactivate() that doesn't execute any operation.
00179      *
00180      * SEE ALSO:  d_activate()
00181      * ODMG    :  Compliant
00182      */
00183     virtual void d_deactivate ();
00184 
00185     /**
00186      * STORE A NON-TRANSACTIONAL OBJECT 
00187      */
00188     void store();
00189     
00190     // Internal.
00191     typedef enum{ stStatic, stLoad, stNew, stCreated,
00192                   stReserved, stUpdated, stDeleted,
00193                   stCheckpointed } statuses;
00194 
00195     // Internal.
00196     typedef enum{ TRANSACTIONAL, NO_TRANSACTIONAL } txmode;
00197 
00198     // Internal.
00199     void static free( d_Object* iObject, bool removeAlsoInContext = true );
00200 
00201     // Internal.
00202     static d_Object* newObject (const size_t iSize);
00203     // Internal.
00204     static bool assignContext( d_Object* iObject, int iTxMode, bool iMandatory );
00205     // Internal.
00206     void setStreamProtocol( const char* iProtName );
00207 
00208     // Internal.
00209     virtual void toStream (oObjectStream& ioBuffer );
00210     // Internal.
00211     virtual void fromStream (oObjectStream& iBuffer );
00212 
00213     // Internal.
00214     oStorage* getStorage() const;
00215     // Internal.
00216     oClass* getClass() const;
00217     // Internal.
00218     bool is_reserved();
00219     // Internal.
00220     bool isInCache();
00221 
00222     /**
00223      * Get the oid associated with the object.
00224      *
00225      * ODMG    :  Extension
00226      */
00227     oObjectId& get_oid();
00228 
00229     // Internal
00230     void setOid( oObjectId& iOid );
00231 
00232     /**
00233      * Pin the object.
00234      *
00235      * Use this method to mark the most used objects. The Orient Object
00236      * Manager doesn't remove this object when the context is committed.
00237      *
00238      * Using this feature avoid loads of the same object from different
00239      * contexts.
00240      *
00241      * SEE ALSO:  unpin()
00242      * ODMG    :  Extension
00243      */
00244     void pin ();
00245 
00246     /**
00247      * Unpin the object.
00248      *
00249      * Unpin the object marked with d_Object::pin() method. Objects are
00250      * unpinned by default.
00251      *
00252      * SEE ALSO:  pin()
00253      * ODMG    :  Extension
00254      */
00255     void unpin ();
00256 
00257     /**
00258      * Trigger called before to store a new persistent object.
00259      *
00260      * It's the trigger called asynchronously by Orient ODBMS on context
00261      * commit before that new object is stored in database.
00262      *
00263      * Inherited class must return a boolean value: true for success, false
00264      * for error. If error is returned, a d_Error_TriggerBeforeNew exception
00265      * is thrown.
00266      *
00267      * It's useful when it needs to validate objects attributes.
00268      *
00269      * If the user class, inherited by d_Object, doesn't define a own
00270      * d_beforerNew virtual method, by default is called the
00271      * d_Object::d_beforeNew() that doesn't execute any operation.
00272      *
00273      * ODMG    :  Extension 
00274      */
00275     virtual bool d_beforeNew ();
00276 
00277     /**
00278      * Trigger called after when a persistent object is update.
00279      *
00280      * It's the trigger called asynchronously by Orient ODBMS immediately
00281      * after the mark_modified() method is called on the object.
00282      *
00283      * Inherited class must return a boolean value: true for success, false
00284      * for error. If error is returned, a d_Error_TriggerOnUpdate exception
00285      * is thrown.
00286      *
00287      * If the user class, inherited by d_Object, doesn't define a own
00288      * d_onUpdate virtual method, by default is called
00289      * the d_Object::d_onUpdate () that doesn't execute any operation.
00290      *
00291      * SEE ALSO:  d_beforeUpdate()
00292      * ODMG    :  Extension 
00293      */
00294     virtual bool d_onUpdate ();
00295 
00296     /**
00297      * Trigger called before to store an updated persistent object.
00298      *
00299      * It's the trigger called asynchronously by Orient ODBMS on context
00300      * commit before that updated object is stored in database.
00301      *
00302      * Inherited class must return a boolean value: true for success, false
00303      * for error. If error is returned, a d_Error_TriggerBeforeUpdate
00304      * exception is thrown.
00305      *
00306      * If the user class, inherited by d_Object, doesn't define a own
00307      * d_beforeUpdate virtual method, by default is called the
00308      * d_Object::d_beforeUpdate() that doesn't execute any operation.
00309      *
00310      * SEE ALSO:  d_onUpdate()
00311      * ODMG    :  Extension 
00312      */
00313     virtual bool d_beforeUpdate ();
00314 
00315     /**
00316      * Make the object transactional.
00317      *
00318      * SEE ALSO:  makeNoTransactional()
00319      * ODMG    :  Extension 
00320      */
00321     void makeTransactional();
00322 
00323     /**
00324      * Make the object no transactional.
00325      *
00326      * SEE ALSO:  makeTransactional()
00327      * ODMG    :  Extension 
00328      */
00329     void makeNoTransactional();
00330 
00331     // Internal.
00332     oContext* getContext() const;
00333 
00334     // Internal.
00335     int                 status;
00336     // Internal.
00337     oObjectStream*      origin;
00338     // Internal.
00339     oClass*             metaClass;
00340 
00341     //--------------------------------------------------------------------------
00342     // INNER CLASSES:
00343     //--------------------------------------------------------------------------
00344     class DynaFactoryConstructor
00345     {
00346     };
00347 
00348   private:
00349     // Internal.
00350     void setSessionPendingInfo( oSession* iSess );
00351     // Internal.
00352     virtual void toStream (oObjectStream& ioBuffer, oInterface* iInterface );
00353     // Internal.
00354     virtual void fromStream (oObjectStream& iBuffer, oInterface* iInterface );
00355 
00356     // Internal.
00357     oContext*           context;
00358     // Internal.
00359     bool                pinned;
00360     // Internal.
00361     oObjectId           oid;
00362     // Internal.
00363     oStorage*           storage;
00364     // Internal.
00365     d_Object*           containerClass;
00366 
00367   // FRIENDSHIPS
00368   friend class _ODLL d_Transaction;
00369 };
00370 
00371 //------------------------------------------------------------------------------
00372 inline d_Object::~d_Object()
00373 {
00374 }
00375 //------------------------------------------------------------------------------
00376 inline void d_Object::pin ()
00377 {
00378   pinned = true;
00379 }
00380 //------------------------------------------------------------------------------
00381 inline void d_Object::unpin ()
00382 {
00383   pinned = false;
00384 }
00385 //------------------------------------------------------------------------------
00386 inline oObjectId& d_Object::get_oid()
00387 {
00388   return oid;
00389 }
00390 //------------------------------------------------------------------------------
00391 inline oClass* d_Object::getClass() const
00392 {
00393   return metaClass;
00394 }
00395 //------------------------------------------------------------------------------
00396 inline oContext* d_Object::getContext() const
00397 {
00398   return context;
00399 }
00400 //------------------------------------------------------------------------------
00401 inline bool d_Object::is_reserved()
00402 {
00403   return status == stReserved;
00404 }
00405 //------------------------------------------------------------------------------
00406 inline void d_Object::d_activate ()
00407 {
00408 }
00409 //------------------------------------------------------------------------------
00410 inline void d_Object::d_deactivate ()
00411 {
00412 }
00413 //------------------------------------------------------------------------------
00414 inline bool d_Object::d_beforeNew ()
00415 {
00416   // IF NOT DEFINED BY INHERITED CLASSES RETURNS ALWAYS TRUE (OK)
00417   return true;
00418 }
00419 //------------------------------------------------------------------------------
00420 inline bool d_Object::d_onUpdate ()
00421 {
00422   // IF NOT DEFINED BY INHERITED CLASSES RETURNS ALWAYS TRUE (OK)
00423   return true;
00424 }
00425 //------------------------------------------------------------------------------
00426 inline bool d_Object::d_beforeUpdate ()
00427 {
00428   // IF NOT DEFINED BY INHERITED CLASSES RETURNS ALWAYS TRUE (OK)
00429   return true;
00430 }
00431 //------------------------------------------------------------------------------
00432 
00433 #endif
00434 

Generated on Fri Nov 29 17:12:13 2002 for Orient ODBMS Just Edition v. 2.0e by doxygen1.3-rc1