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

cDatabaseObject.cpp

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /* POLiTe - Persistent Object Library Test                                    */
00004 /*                                        Ph.D. Thesis by Mgr. Michal Kopecky */
00005 /*                                                                            */
00006 /* Charles University Prague                                                  */
00007 /*                                                                            */
00008 /******************************************************************************/
00009 /*                                                                            */
00010 /* File name: ...                                                             */
00011 /* Module: ......                                                             */
00012 /*                                                                            */
00013 /******************************************************************************/
00014 
00015 // Own Header
00016 #include <cDatabaseObject.h>                                                    // Persistent Object class header
00017 
00018 // Other POLiTe Header(s)
00019 #include <cObjectBuffer.h>
00020 #include <cRefBase.h>
00021 
00023 
00024 // Database Objects are objects stored in a relational database. Database objects
00025 // represent rows in existing external relational database tables. Each row is identified
00026 // by values of the primary key attributes. Persistent Objects can be locked in the memory
00027 // to avoid their swapping out from memory and to assure their fixed memory address until
00028 // unlock is called.
00029 
00030 PROTOTYPE(DatabaseObject);
00031 //Proto<DatabaseObject> DatabaseObject_class;
00032 
00034 // DatabaseObject constructor:
00035 // Create the DatabaseObject object with the appropriate initialization.
00036 
00037 DatabaseObject::DatabaseObject()
00038 {
00039 // DatabaseObject
00040 // Select may access data in one table only.
00041 // Using of GROUP BY and HAVING clauses, aggregate function operators is not allowed.
00042 // Object structure must be compatible with the accessed table structure.
00043 // Object changes are propagated to an appropriate row of database table.
00044 
00045         #ifdef C_DATABASEOBJECT_TRACE
00046         logmsg("DatabaseObject::DatabaseObject() invoked");
00047         #endif
00048 
00049         _DirtyFlag = false;
00050         _MemoryLocks = 0;
00051 
00052         #ifdef C_DATABASEOBJECT_TRACE
00053                 logmsg("DatabaseObject::DatabaseObject() finished");
00054         #endif
00055 }
00056 
00058 // DatabaseObject constructor:
00059 // Create the DatabaseObject object with the appropriate initialization.
00060 
00061 DatabaseObject::DatabaseObject(
00062         enum LockingStrategy a_LockingStrategy,
00063         enum UpdatingStrategy an_UpdatingStrategy,
00064         enum WaitingStrategy a_WaitingStrategy,
00065         enum ReadingStrategy a_ReadingStrategy
00066         )
00067 {
00068         #ifdef C_DATABASEOBJECT_TRACE
00069                 logmsg("DatabaseObject::DatabaseObject(...) invoked");
00070                 logmsg("a_LockingStrategy == \"%s\"", msg(a_LockingStrategy));
00071                 logmsg("an_UpdatingStrategy == \"%s\"", msg(an_UpdatingStrategy));
00072                 logmsg("a_WaitingStrategy == \"%s\"", msg(a_WaitingStrategy));
00073                 logmsg("a_ReadingStrategy == \"%s\"", msg(a_ReadingStrategy));
00074         #endif
00075 
00076         SetLockingStrategy(a_LockingStrategy);
00077         SetUpdatingStrategy(an_UpdatingStrategy);
00078         SetWaitingStrategy(a_WaitingStrategy);
00079         _DirtyFlag = false;
00080         _MemoryLocks = 0;
00081 
00082         #ifdef C_DATABASEOBJECT_TRACE
00083         logmsg("DatabaseObject::DatabaseObject(...) finished");
00084         #endif
00085 }
00086 
00088 // Object destructor:
00089 // Delete the Object object with the appropriate de-initialization.
00090 
00091 DatabaseObject::~DatabaseObject()     // destructor
00092 {
00093         #ifdef C_DATABASEOBJECT_TRACE
00094         logmsg("DatabaseObject::~DatabaseObject() invoked");
00095         #endif
00096 
00097         _Free();
00098 
00099         #ifdef C_DATABASEOBJECT_TRACE
00100         logmsg("DatabaseObject::~DatabaseObject() finished");
00101         #endif
00102 }
00103 
00105 //Causes an object to be persistent.
00106 //Persistent objects are  created as transient (they exist only
00107 //in memory) and when it is needed (all attributes are set to
00108 //appropriate values), then they  can be converted to true
00109 //persistent objects. An advantage is that transient objects do
00110 //not propagate into a database while persistent objects are
00111 //written (in spite of buffering mechanism) to the database
00112 //often.
00113 
00114 class RefBase DatabaseObject::BePersistent(
00115         class Connection *DbCon
00116         )
00117 {
00118         RefBase retval;
00119 
00120         #ifdef C_DATABASEOBJECT_TRACE
00121                 logmsg("int DatabaseObject::BePersistent() invoked");
00122         #endif
00123 
00124         if (IsTransient())
00125         {
00126                 //Prototype()->_ExportAttributes(this);
00127                 _Connection = DbCon;
00128                 // Insert this object from
00129                 // all prototypes including
00130                 // predecessors
00131                 if (Prototype()->_InsertAll(this))
00132                 {
00133                         retval = Address();
00134                         ObjectCache.RegisterObject(retval,this);
00135                         _MarkAsClean();
00136                 }
00137                 else
00138                 {
00139                         _Connection = NULL;
00140         };
00141         };
00142 
00143         #ifdef C_DATABASEOBJECT_TRACE
00144                 logmsg("int DatabaseObject::BePersistent() finished");
00145         #endif
00146 
00147         return Address();
00148         };

Generated on Sun Jul 14 20:51:14 2002 for POLiTe by doxygen1.2.16