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 #ifndef __C_REFBASE_H__ 00016 #define __C_REFBASE_H__ 00017 00018 // Standard Header(s) 00019 #include <stdio.h> 00020 00021 // Common POLiTe Header(s) 00022 #include <lStr.h> 00023 #include <lTypes.h> 00024 #include <lTrace.h> 00025 #include <lDefs.h> 00026 00027 // Parent Header(s) 00028 #include <cObjRef.h> 00029 00030 // Other POLiTe Header(s) 00031 #include <cObjectIdentification.h> 00032 00033 extern DLL_External const class RefBase DBNULL; 00034 00035 class DLL_External RefBase : public ObjRef 00036 { 00037 #ifdef POLITE_TEST_FRIEND 00038 friend POLITE_TEST_FRIEND; 00039 #endif // POLITE_TEST_FRIEND 00040 00041 friend class ObjectBuffer; 00042 friend class Object; 00043 friend class ProtoBase; 00044 friend class ResultBase; 00045 friend class OneToOneRelationBase; 00046 friend class OneToManyRelationBase; 00047 friend class ManyToOneRelationBase; 00048 friend class ManyToManyRelationBase; 00049 friend class ChainedRelationBase; 00050 00051 protected: 00052 class ObjectIdentification _ObjectIdentification; 00053 00054 public: 00055 // empty constructor - construct DBNULL pointer 00056 RefBase(); 00057 // other constructors 00058 RefBase( 00059 const RefBase &Dbp 00060 ); 00061 RefBase( 00062 const Object * const DbObj 00063 ); 00064 RefBase( 00065 class Connection *aConnection, 00066 class ProtoBase *aPrototype, 00067 char *aSelectKeyValues, 00068 unsigned short aStrategies 00069 ); 00070 RefBase( 00071 class Connection *aConnection, 00072 ObjectIdentification *anIdentification 00073 ); 00074 RefBase( 00075 class Connection *aConnection, 00076 const long anOid, 00077 class ProtoBase *aPrototype 00078 ); 00079 // destructor 00080 virtual ~RefBase(); 00081 // re-initialization of already existing database pointer 00082 virtual bool Init( 00083 class Connection *aConnection, 00084 class ProtoBase *aPrototype, 00085 char *aSelectKeyValues 00086 ); 00087 00088 protected: 00089 virtual class Object *_Object() 00090 // returns pointer to object stored in the Object Identification 00091 { 00092 return (Object *)_ObjectIdentification._object; 00093 }; 00094 00095 protected: 00096 virtual class RefBase &_Virtualise(); 00097 // Typecasts RefBase to class A to RefBase to 00098 // correct A's subclass B. Does nothing in other derived classes. 00099 00100 virtual char *_KeyValues() const {return StrCpy(_ObjectIdentification._SelectKeyValues);}; 00101 00102 public: 00103 virtual Object &ReferencedObject() const; 00104 //Returns the reference to the pointed object 00105 //which will be read from the database, if the object 00106 //is not present in memory yet. 00107 00108 class Object* IsInMemory() const; 00109 //Access to the object with the tests whether the object 00110 //is loaded into the memory. It returns the pointer to 00111 //the object in the memory (if he is loaded in the memory) 00112 //or NULL otherwise. 00113 00114 class ObjectIdentification ObjectID() const; 00115 //Returns identification of 00116 //an object independent on the instance location 00117 //It consists of either memory pointer, 00118 //or couple of prototype an comma-separated list of primary key values 00119 00120 virtual class ProtoBase *Prototype() const; 00121 // Returns a reference to a prototype instance of the referenced class 00122 00123 public: 00124 virtual bool IsDirty() const; 00125 //Returns True, if an object is marked as dirty (e.g. the 00126 //object was changed in the memory). 00127 00128 virtual bool MarkAsDirty(); 00129 //Marks a persistent object as Dirty. Only Dirty (changed) 00130 //objects are written to the database when flushing the buffer. 00131 00132 protected: 00133 virtual bool _MarkAsClean(); 00134 //Marks a persistent object as Clean. Only Dirty (changed) 00135 //objects are written to the database when flushing the buffer. 00136 00137 public: 00138 // 00139 virtual bool Refresh(); 00140 // It copies an object from disk to the memory again. 00141 // Returns true, if it succeed. 00142 00143 virtual bool Update(); 00144 //Writes an object from the memory to the disk. 00145 00146 virtual bool Free(); 00147 //Tries to destroy an object referenced by this RefBase 00148 //in the memory only. 00149 //Succeeds if all the tests 00150 //(for example, if the object is not locked) 00151 //are passed successfully. 00152 00153 protected: 00154 virtual bool _Free(); 00155 //Destroys an object in the memory. _Free is called by the 00156 //method Free, if all the tests passed. _Free is not visible 00157 //for the programmers of the target application. 00158 00159 public: 00160 virtual bool Delete(); 00161 //Tries to destroy an object from the memory as well as 00162 //from the database. Succeeds if all the tests (for 00163 //example, if the object is not locked) are passed 00164 //successfully. 00165 00166 Object *MemoryLock(); 00167 //Locks a persistent object. Multiple locks 00168 //can be placed on the object. The object can be 00169 //removed from memory only when all the locks are 00170 //released. 00171 //possible exceptions: 00172 00173 bool MemoryUnlock(); 00174 //Unlocks a persistent object in memory. See MemoryLock. 00175 00176 virtual unsigned int MemoryLocked() const; 00177 //Returns the number of memory locks on receiver or zero 00178 //if it is not locked. 00179 00180 virtual bool RemoveAllMemoryLocks(); 00181 //Removes all memory locks existing in the GEN.LIB 00182 00183 virtual class RefBase BePersistent(class Connection *DbCon) 00184 //Causes an object to be persistent. 00185 //Persistent objects are created as transient (they exist only 00186 //in memory) and when it is needed (all attributes are set to 00187 //appropriate values), then they can be converted to true 00188 //persistent objects. An advantage is that transient objects do 00189 //not propagate into a database while persistent objects are 00190 //written (in spite of buffering mechanism) to the database 00191 //often. 00192 { 00193 return *this; 00194 }; 00195 00196 bool operator == (const class RefBase &DbPtr) const; 00197 //Tests, if the objects to which two database pointers 00198 //point, are the same 00199 00200 bool operator != (const class RefBase &DbPtr) const; 00201 }; 00202 00203 #endif //__C_REFBASE_H__