00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <lTypes.h>
00017
00018
00019 #include <cObject.h>
00020
00021
00022 #include <cObjectBuffer.h>
00023
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 PROTOTYPE(Object);
00035
00036
00038
00039
00040
00041 Object::Object()
00042 {
00043 #ifdef C_OBJECT_TRACE
00044 logmsg("Object::Object() invoked");
00045 #endif
00046
00047 _FreeWasDone = false;
00048 _ForUpdate = false;
00049
00050 #ifdef C_OBJECT_TRACE
00051 logmsg("Object::Object() finished");
00052 #endif
00053 }
00054
00056
00057
00058
00059
00060 Object::~Object()
00061 {
00062 #ifdef C_OBJECT_TRACE
00063 logmsg("Object::~DatabaseObject() invoked");
00064 #endif
00065
00066 _Free();
00067
00068 #ifdef C_OBJECT_TRACE
00069 logmsg("Object::~DatabaseObject() finished");
00070 #endif
00071 }
00072
00073 bool Object::Free()
00074
00075
00076
00077
00078 {
00079 delete this;
00080 return true;
00081 };
00082
00083 bool Object::_Free()
00084
00085
00086
00087 {
00088 if (!_FreeWasDone) {
00089 _FreeWasDone = true;
00090 if (IsPersistent()) {
00091 if (IsDirty())
00092 Update();
00093 if (MemoryLocked() > 0)
00094 throw ObjLibException_MemoryLock();
00095 ObjectCache.RemoveObject(this,Connection());
00096 };
00097 };
00098 return true;
00099 };
00100
00102
00103
00104
00105
00106 bool Object::Delete()
00107 {
00108 bool retval = true;
00109
00110 #ifdef C_OBJECT_TRACE
00111 logmsg("bool Object::Delete() invoked");
00112 #endif
00113
00114 if (IsPersistent())
00115 {
00116 if (MemoryLocked())
00117 throw ObjLibException_MemoryLock();
00118 Prototype()->_ExportKeyAttributes(*this);
00119 Prototype()->_DeleteAll(this);
00120 };
00121
00122 _MarkAsClean();
00123 retval = retval && Free();
00124
00125 #ifdef C_OBJECT_TRACE
00126 logmsg("bool Object::Delete() finished");
00127 #endif
00128
00129 return retval;
00130 }
00131
00132 bool Object::Update()
00133 {
00134 bool retval = true;
00135
00136 #ifdef C_OBJECT_TRACE
00137 logmsg("bool Object::Update() invoked");
00138 #endif
00139
00140 if (IsPersistent() && IsDirty()) {
00141 #ifdef C_OBJECT_TRACE
00142 logmsg("Object is dirty");
00143 #endif
00144
00145
00146 retval = Prototype()->_UpdateAll(this);
00147
00148 };
00149
00150 #ifdef C_OBJECT_TRACE
00151 logmsg("bool Object::Update() finished");
00152 #endif
00153
00154 return retval;
00155 };
00156
00158
00159
00160 bool Object::Refresh()
00161 {
00162 bool retval;
00163 bool do_refresh;
00164
00165 #ifdef C_OBJECT_TRACE
00166 logmsg("bool Object::Refresh() invoked");
00167 #endif
00168
00169 if (IsTransient())
00170
00171 do_refresh = false;
00172 else
00173 do_refresh = true;
00174
00175 if (do_refresh)
00176 {
00177 retval = Prototype()->_ExportKeyAttributes(*this);
00178 retval = retval && Prototype()->_Load(*this);
00179 }
00180 else
00181 retval = true;
00182
00183 #ifdef C_OBJECT_TRACE
00184 logmsg("bool Object::Refresh() finished");
00185 #endif
00186
00187 return (retval);
00188 };
00189
00190
00191 bool Object::_Refresh()
00192 {
00193 bool retval;
00194 bool do_refresh;
00195
00196 #ifdef C_OBJECT_TRACE
00197 logmsg("bool Object::_Refresh() invoked");
00198 #endif
00199
00200 if (IsTransient())
00201
00202 do_refresh = false;
00203 else if (Prototype()->IsObject())
00204
00205 do_refresh = false;
00206 else if (_ForUpdate)
00207
00208 do_refresh = false;
00209 else if ((CurrentLockingStrategy()==LS_Exclusive) && !_ForUpdate)
00210
00211 do_refresh = true;
00212 else if (CurrentReadingStrategy()==RS_Database)
00213
00214 do_refresh = true;
00215 else if (CurrentReadingStrategy()==RS_Timestamp)
00216 {
00217
00218 do_refresh = !_VersionsMatch();
00219 }
00220 else
00221 do_refresh = false;
00222
00223 if (do_refresh)
00224 {
00225 retval = Prototype()->_ExportKeyAttributes(*this);
00226 retval = retval && Prototype()->_Load(*this);
00227 }
00228 else
00229 retval = true;
00230
00231 #ifdef C_OBJECT_TRACE
00232 logmsg("bool Object::_Refresh() finished");
00233 #endif
00234
00235 return (retval);
00236 };
00237
00239
00240
00241
00242 ObjectIdentification Object::ObjectID() const
00243 {
00244 #ifdef C_OBJECT_TRACE
00245 logmsg("ObjectIdentification Object::ObjectID()"
00246 " invoked and finished");
00247 #endif
00248
00249 if (IsTransient())
00250 return ObjectIdentification(this);
00251 else
00252 return ObjectIdentification(Prototype(),_KeyValues());
00253 }
00254
00256
00257
00258 RefBase Object::Address() const
00259 {
00260 if (IsPersistent())
00261 return RefBase(Connection(),Prototype(),Prototype()->_KeyValues(*this),_Strategies);
00262 else
00263 return RefBase(this);
00264 };
00265