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

cObjectBuffer.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 // Standard Header(s)
00016 #include <malloc.h>
00017 
00018 // Common POLiTe Header(s)
00019 #include <lDefs.h>
00020 #include <lTypes.h>
00021 #include <lTrace.h>
00022 
00023 // Own Header
00024 #include <cObjectBuffer.h>
00025 
00026 // Other POLiTe Header(s)
00027 #include <cBufferItem.h>
00028 #include <cObject.h>
00029 #include <cRefBase.h>
00030 
00031 class ObjectBuffer ObjectCache;
00032 
00033 //***********************************************************************
00034 //***********************************************************************
00035 unsigned long ObjectBuffer::_GarbageCollector()
00036 //***********************************************************************
00037 //***********************************************************************
00038 {
00039         unsigned long RemovedObjects = 0;
00040         unsigned int i,j;
00041         BufferItem **CurrentItemPtr,*CurrentItem;
00042         Object *MemPtr;
00043 
00044         #ifdef C_OBJECTBUFFER_TRACE
00045                 logmsg("ObjectBuffer::_GarbageCollector() invoked");
00046         #endif
00047         for(i=0;i<MAX_CONNECTION;i++)
00048                 for(j=0;j<HASH_TABLE_SIZE;j++)
00049                 {
00050                         CurrentItemPtr=&(_Structure[i][j]);
00051                         while (*CurrentItemPtr)
00052                         {
00053                                 CurrentItem = *CurrentItemPtr;
00054                                 MemPtr=CurrentItem->GetMemoryPointer();
00055 
00056                                 // tests for locks on the object
00057                                 if(!CurrentItem->_MemoryPointer->MemoryLocked())
00058                                 {
00059                                         // remove CurrentItem from the buffer;
00060                                         MemPtr->Update();
00061                                         MemPtr->_FreeWasDone = true; 
00062                                         delete(MemPtr);
00063                                         delete((RefBase *)(CurrentItem->_RefBase));
00064                                         *CurrentItemPtr = CurrentItem->_Next;
00065                                         free(CurrentItem);
00066                                         _ObjectsInBuffer--;
00067                                         RemovedObjects++;
00068                                 }
00069                                 else
00070                                         CurrentItemPtr = &(CurrentItem->_Next);
00071                         };
00072                 };
00073         _LastAccessedItem = NULL;
00074 
00075         #ifdef C_OBJECTBUFFER_TRACE
00076                 logmsg("ObjectBuffer::_GarbageCollector() finished");
00077         #endif
00078 
00079         return (RemovedObjects);
00080 };
00081 
00082 
00083 //***********************************************************************
00084 //***********************************************************************
00085 unsigned int ObjectBuffer::_Hash(const char *values) const
00086 //***********************************************************************
00087 //***********************************************************************
00088 {
00089         unsigned int dummy = 0;
00090         int i = 0;
00091 
00092         #ifdef C_OBJECTBUFFER_TRACE
00093                 logmsg("ObjectBuffer::_Hash() invoked");
00094         #endif
00095 
00096         if (values != NULL)
00097                 while ((*values) && (i++ < 8))
00098                         dummy ^= *values++;
00099 
00100         #ifdef C_OBJECTBUFFER_TRACE
00101                 logmsg("ObjectBuffer::_Hash() finished");
00102         #endif
00103 
00104         return(dummy%HASH_TABLE_SIZE);
00105 };
00106 
00107 //***********************************************************************
00108 //***********************************************************************
00109 BufferItem *ObjectBuffer::_FindItem(const RefBase &DbPtr)
00110 //***********************************************************************
00111 //***********************************************************************
00112 
00113 {
00114         #ifdef C_OBJECTBUFFER_TRACE
00115                 logmsg("ObjectBuffer::_FindItem() invoked");
00116         #endif
00117         int index;
00118         BufferItem *CurrListItem;
00119 
00120         if (_LastAccessedItem != NULL)
00121                 if (_LastAccessedItem->GetRefBase() == DbPtr)
00122                 {
00123                         #ifdef C_OBJECTBUFFER_TRACE
00124                                 logmsg("ObjectBuffer::_FindItem() finished, returned NOT-NULL");
00125                         #endif
00126                         return (_LastAccessedItem);
00127                 };
00128 
00129         index=_Hash(DbPtr._ObjectIdentification._SelectKeyValues);
00130         for(CurrListItem=_Structure[DbPtr._Connection->_Handle][index];
00131                 (CurrListItem!=NULL)&&(CurrListItem->GetRefBase()!=DbPtr);
00132                 CurrListItem=CurrListItem->_Next);
00133         if (CurrListItem==NULL) {
00134                 #ifdef C_OBJECTBUFFER_TRACE
00135                         logmsg("ObjectBuffer::_FindItem() finished, returned NULL");
00136                 #endif
00137                 return(NULL);
00138         }
00139         else {
00140                 _LastAccessedItem = CurrListItem;
00141                 #ifdef C_OBJECTBUFFER_TRACE
00142                         logmsg("ObjectBuffer::_FindItem() finished, returned NOT-NULL");
00143                 #endif
00144                 return(_LastAccessedItem);
00145         };
00146 };
00147 
00148 //***********************************************************************
00149 //***********************************************************************
00150 ObjectBuffer::ObjectBuffer()
00151 //***********************************************************************
00152 //***********************************************************************
00153 
00154 //Creates a new empty ObjectBuffer
00155 {
00156         #ifdef C_OBJECTBUFFER_TRACE
00157                 logmsg("ObjectBuffer::ObjectBuffer() invoked");
00158         #endif
00159         _Strategies = DEFAULT_STRATEGIES;
00160         _ResetForUpdateFlags = false;
00161         _Requests = 0;
00162         _Hits = 0;
00163         for (int i=0;i<MAX_CONNECTION;i++)
00164                 for(int j=0;j<HASH_TABLE_SIZE;j++){
00165                         _Structure[i][j]=NULL;
00166                 };
00167         _LastAccessedItem = NULL;
00168         _ObjectsInBuffer  = 0;
00169 };
00170 
00171 //***********************************************************************
00172 //***********************************************************************
00173 ObjectBuffer::~ObjectBuffer()
00174 //***********************************************************************
00175 //***********************************************************************
00176 //
00177 { unsigned int i,j;
00178         BufferItem *ListItem,*RestOfList;
00179 
00180         #ifdef C_OBJECTBUFFER_TRACE
00181                 logmsg("ObjectBuffer::~ObjectBuffer() invoked");
00182         #endif
00183         for (i=0;i<MAX_CONNECTION;i++)
00184                 for(j=0;j<HASH_TABLE_SIZE;j++){
00185                         RestOfList=_Structure[i][j];
00186                         while (RestOfList!=NULL){
00187                                 ListItem=RestOfList;
00188                                 RestOfList=RestOfList->_Next;
00189                                 delete (ListItem);
00190                         }
00191                 }
00192         #ifdef C_OBJECTBUFFER_TRACE
00193                 logmsg("ObjectBuffer::~ObjectBuffer() finished");
00194         #endif
00195 };
00196 
00197 //***********************************************************************
00198 //***********************************************************************
00199 bool ObjectBuffer::Init(
00200   const enum LockingStrategy aLockingStrategy,
00201   const enum UpdatingStrategy anUpdatingStrategy,
00202   const enum WaitingStrategy aWaitingStrategy
00203   )
00204 //***********************************************************************
00205 //***********************************************************************
00206 { unsigned int i,j;
00207 
00208         #ifdef C_OBJECTBUFFER_TRACE
00209                 logmsg("ObjectBuffer::Init(a,b,c) invoked");
00210         #endif
00211         if (!_Initialised) {
00212                 (void)SetLockingStrategy(aLockingStrategy);
00213                 (void)SetUpdatingStrategy(anUpdatingStrategy);
00214                 (void)SetWaitingStrategy(aWaitingStrategy);
00215 
00216                 for (i=0;i<MAX_CONNECTION;i++)
00217                         for(j=0;j<HASH_TABLE_SIZE;j++){
00218                                 _Structure[i][j]=NULL;
00219                         };
00220                 _Initialised = true;
00221         };
00222         _LastAccessedItem = NULL;
00223         _ObjectsInBuffer  = 0;
00224         #ifdef C_OBJECTBUFFER_TRACE
00225                 logmsg("ObjectBuffer::Init(a,b,c) invoked");
00226         #endif
00227         return true;
00228 };
00229 
00230 
00231 //***********************************************************************
00232 //***********************************************************************
00233 Object *ObjectBuffer::IsInMemory(
00234         const RefBase &DbPtr
00235         )
00236 //***********************************************************************
00237 //***********************************************************************
00238 {
00239         BufferItem *BuffItem;
00240         #ifdef C_OBJECTBUFFER_TRACE
00241                 logmsg("ObjectBuffer::IsInMemory() invoked");
00242         #endif
00243 
00244         if ((DbPtr == DBNULL) || ((BuffItem = _FindItem(DbPtr))==NULL)) {
00245                 #ifdef C_OBJECTBUFFER_TRACE
00246                          logmsg("ObjectBuffer::IsInMemory() finished, returned NULL");
00247                 #endif
00248                 return (NULL);
00249         }
00250         else {
00251                 #ifdef C_OBJECTBUFFER_TRACE
00252                         logmsg("ObjectBuffer::IsInMemory() finished, returned NOT-NULL");
00253                 #endif
00254                 return (Object *)(BuffItem->_MemoryPointer);
00255         };
00256 };
00257 
00258 //***********************************************************************
00259 //***********************************************************************
00260 bool ObjectBuffer::RegisterObject(
00261   const class RefBase &DbPtr,
00262   const class Object *const MemPtr
00263   )
00264 //***********************************************************************
00265 //***********************************************************************
00266 //
00267 {
00268   #ifdef C_OBJECTBUFFER_TRACE
00269          logmsg("ObjectBuffer::RegisterObject() invoked");
00270          #endif
00271   int index;
00272   BufferItem *NewListItem;
00273 
00274   if (IsInMemory(DbPtr)!=NULL) {
00275         #ifdef C_OBJECTBUFFER_TRACE
00276          logmsg("ObjectBuffer::RegisterObject() finished, returned false");
00277          #endif
00278         return (false);
00279   }
00280   if (_ObjectsInBuffer >= MAX_OBJECTS_IN_BUFFER)
00281                 _GarbageCollector();
00282   index=_Hash(DbPtr._ObjectIdentification._SelectKeyValues);
00283 
00284   NewListItem = new BufferItem(DbPtr,MemPtr);
00285   NewListItem ->_Next=_Structure[DbPtr._Connection->_Handle][index];
00286   _Structure[DbPtr._Connection->_Handle][index]=NewListItem;
00287   _ObjectsInBuffer++;
00288   #ifdef C_OBJECTBUFFER_TRACE
00289          logmsg("ObjectBuffer::RegisterObject() finished, returned true");
00290          #endif
00291   return(true);
00292 };
00293 
00294 //***********************************************************************
00295 //***********************************************************************
00296 bool ObjectBuffer::RemoveObject(
00297         class Object *MemPtr,
00298         const class Connection * const DbCon
00299         )
00300 //***********************************************************************
00301 //***********************************************************************
00302 { int index;
00303   BufferItem *CurrListItem,*PrevListItem;
00304 
00305 #ifdef C_OBJECTBUFFER_TRACE
00306          logmsg("ObjectBuffer::RemoveObject(MemPtr) invoked");
00307          #endif
00308 
00309   if ((MemPtr==NULL) || (DbCon==NULL))
00310           return false;
00311 
00312   MemPtr->Prototype()->_ExportKeyAttributes(*MemPtr);
00313   char *keyvalues = MemPtr->Prototype()->_KeyValues(*MemPtr);
00314   index=_Hash(keyvalues);
00315   StrFree(keyvalues);
00316   CurrListItem = _Structure[DbCon->_Handle][index];
00317   PrevListItem = CurrListItem;
00318   while((CurrListItem!=NULL) &&
00319                   (CurrListItem->GetMemoryPointer())!=MemPtr){
00320          PrevListItem=CurrListItem;
00321          CurrListItem=CurrListItem->_Next;
00322   }
00323 
00324 // the item is not in a list
00325         if (CurrListItem == NULL) {
00326         #ifdef C_OBJECTBUFFER_TRACE
00327                 logmsg("ObjectBuffer::RemoveObject(MemPtr) finished, returned false");
00328         #endif
00329         return(false);}
00330 
00331         if(CurrListItem->_MemoryPointer->MemoryLocked()){
00332                 #ifdef C_OBJECTBUFFER_TRACE
00333                         logmsg("ObjLibException_MemoryLock in ObjectBuffer::RemoveObject");
00334                 #endif
00335                 throw ObjLibException_MemoryLock();
00336         }
00337 
00338         // deleting from the head of a list
00339         _ObjectsInBuffer--;
00340         if (CurrListItem == PrevListItem){
00341                 _Structure[DbCon->_Handle][index]=CurrListItem->_Next;
00342                 if (CurrListItem == _LastAccessedItem)
00343                         _LastAccessedItem = NULL;
00344                 delete(CurrListItem);
00345         }
00346         else{
00347         // deleting from the other place
00348         if (CurrListItem->_Next == NULL)
00349                 PrevListItem->_Next=NULL;
00350         else
00351                 PrevListItem->_Next=CurrListItem->_Next->_Next;
00352         if (CurrListItem == _LastAccessedItem)
00353                 _LastAccessedItem = NULL;
00354         delete (CurrListItem);
00355         }
00356 
00357 
00358         #ifdef C_OBJECTBUFFER_TRACE
00359                 logmsg("ObjectBuffer::RemoveObject(MemPtr) finished");
00360         #endif
00361 
00362         return true;
00363 };
00364 
00365 //***********************************************************************
00366 //***********************************************************************
00367 bool ObjectBuffer::RemoveObject(const class RefBase &DbPtr)
00368 //***********************************************************************
00369 //***********************************************************************
00370 {
00371         int index;
00372         BufferItem *CurrListItem,*PrevListItem;
00373 
00374         #ifdef C_OBJECTBUFFER_TRACE
00375                 logmsg("ObjectBuffer::RemoveObject(DbPtr) invoked");
00376         #endif
00377 
00378         if ((DbPtr.ObjectID()==NULL)|| (DbPtr.Connection()==NULL))
00379                 return false;
00380 
00381         index=_Hash(DbPtr._ObjectIdentification._SelectKeyValues);
00382         CurrListItem = _Structure[DbPtr._Connection->_Handle][index];
00383         PrevListItem = CurrListItem;
00384         while((CurrListItem!=NULL) &&
00385                 (CurrListItem->GetRefBase())!=DbPtr)
00386         {
00387                 PrevListItem=CurrListItem;
00388                 CurrListItem=CurrListItem->_Next;
00389         }
00390 
00391         // the item is not in a list
00392         if (CurrListItem == NULL) {
00393                 #ifdef C_OBJECTBUFFER_TRACE
00394                         logmsg("ObjectBuffer::RemoveObject(DbPtr) finished, returned false");
00395                 #endif
00396                 return(false);
00397         }
00398 
00399         if(CurrListItem->_MemoryPointer->MemoryLocked()){
00400                 #ifdef C_OBJECTBUFFER_TRACE
00401                         logmsg("ObjLibException_MemoryLock in ObjectBuffer::RemoveObject");
00402                 #endif
00403                 throw ObjLibException_MemoryLock();
00404         }
00405 
00406         // deleting from the head of a list
00407         _ObjectsInBuffer--;
00408         if (CurrListItem == PrevListItem){
00409                 _Structure[DbPtr._Connection->_Handle][index]=CurrListItem->_Next;
00410                 delete(CurrListItem);
00411         }
00412         else{
00413         // deleting from the other place
00414                 if (CurrListItem->_Next == NULL)
00415                         PrevListItem->_Next=NULL;
00416                 else
00417                         PrevListItem->_Next=CurrListItem->_Next->_Next;
00418                 delete (CurrListItem);
00419         }
00420 
00421         #ifdef C_OBJECTBUFFER_TRACE
00422                 logmsg("ObjectBuffer::RemoveObject(DbPtr) finished, returned true");
00423         #endif
00424 
00425         return (true);
00426 };
00427 
00428 //***********************************************************************
00429 //***********************************************************************
00430 bool ObjectBuffer::UpdateConnection(int ConHandle)
00431 //***********************************************************************
00432 //***********************************************************************
00433 //
00434 
00435 {
00436         #ifdef C_OBJECTBUFFER_TRACE
00437                 logmsg("ObjectBuffer::UpdateConnection(handle) invoked");
00438         #endif
00439 
00440         unsigned int j;
00441         BufferItem *CurrListItem;
00442         Object *MemPtr;
00443 
00444         for(j=0;j<HASH_TABLE_SIZE;j++){
00445                 CurrListItem=_Structure[ConHandle][j];
00446                 while (CurrListItem!=NULL){
00447                         MemPtr=CurrListItem->GetMemoryPointer();
00448                         MemPtr->Update();
00449                         if (_ResetForUpdateFlags)
00450                                 MemPtr->_ForUpdate=false;
00451                         CurrListItem=CurrListItem->_Next;
00452                 };
00453         };
00454 
00455         #ifdef C_OBJECTBUFFER_TRACE
00456                 logmsg("ObjectBuffer::UpdateConnection(handle) finished");
00457         #endif
00458         return(true);
00459  };
00460 
00461 
00462 //***********************************************************************
00463 //***********************************************************************
00464 bool ObjectBuffer::UpdateAll()
00465 //***********************************************************************
00466 //***********************************************************************
00467 //
00468 {
00469         #ifdef C_OBJECTBUFFER_TRACE
00470                 logmsg("ObjectBuffer::UpdateAll() invoked");
00471         #endif
00472         unsigned int i;
00473 
00474         for (i=0;i<MAX_CONNECTION;i++)
00475                 UpdateConnection(i);
00476 
00477         #ifdef C_OBJECTBUFFER_TRACE
00478                 logmsg("ObjectBuffer::UpdateAll() finished");
00479         #endif
00480         return(true);
00481 };
00482 
00483 //***********************************************************************
00484 //***********************************************************************
00485 bool ObjectBuffer::UpdateAll(const Connection *const DbC)
00486 //***********************************************************************
00487 //***********************************************************************
00488 //
00489 {
00490         #ifdef C_OBJECTBUFFER_TRACE
00491                 logmsg("ObjectBuffer::UpdateAll(DbC) invoked");
00492         #endif
00493 
00494         UpdateConnection (DbC->_Handle);
00495 
00496         #ifdef C_OBJECTBUFFER_TRACE
00497                 logmsg("ObjectBuffer::UpdateAll(DbC) finished");
00498         #endif
00499         return(true);
00500 };
00501 
00502 //***********************************************************************
00503 //***********************************************************************
00504 bool ObjectBuffer::UpdateAll(const Database *const DB)
00505 //***********************************************************************
00506 //***********************************************************************
00507 //
00508 {
00509         unsigned int i;
00510         #ifdef C_OBJECTBUFFER_TRACE
00511                 logmsg("ObjectBuffer::UpdateAll(DB) invoked ");
00512         #endif
00513         for (i=0;i<MAX_CONNECTION_PER_DATABASE;i++)
00514                 if (DB->_Connections[i]!=NULL)
00515                         UpdateAll(DB->_Connections[i]);
00516         #ifdef C_OBJECTBUFFER_TRACE
00517                 logmsg("ObjectBuffer::UpdateAll(DB) finished");
00518         #endif
00519         return(true);
00520 };
00521 
00522 
00523 //***********************************************************************
00524 //***********************************************************************
00525 bool ObjectBuffer::RemoveConnection(int ConHandle)
00526 //***********************************************************************
00527 //***********************************************************************
00528 //
00529 {
00530         unsigned int j;
00531         BufferItem *ListItem,*RestOfList;
00532         Object *MemPtr;
00533 
00534         #ifdef C_OBJECTBUFFER_TRACE
00535                 logmsg("ObjectBuffer::RemoveConnection () invoked");
00536         #endif
00537 
00538         for(j=0;j<HASH_TABLE_SIZE;j++){
00539                 RestOfList=_Structure[ConHandle][j];
00540                 while (RestOfList!=NULL){
00541                         ListItem=RestOfList;
00542                         RestOfList=RestOfList->_Next;
00543                         MemPtr=ListItem->GetMemoryPointer();
00544 
00545                         // tests for locks on the object
00546                         // this makes the differece from  _RemoveConnection
00547                         if(ListItem->_MemoryPointer->MemoryLocked())
00548                                 throw ObjLibException_MemoryLock();
00549                         MemPtr->Update();
00550                         MemPtr->_FreeWasDone = true; 
00551                         delete(MemPtr);
00552                         delete(ListItem);
00553                         _ObjectsInBuffer--;
00554                 };
00555                 _Structure[ConHandle][j] = NULL;
00556         };
00557         #ifdef C_OBJECTBUFFER_TRACE
00558                 logmsg("ObjectBuffer::RemoveConnection () finished");
00559         #endif
00560         return(true);
00561 };
00562 
00563 //***********************************************************************
00564 //***********************************************************************
00565 bool ObjectBuffer::RemoveAll(const Connection *const DbC)
00566 //***********************************************************************
00567 //***********************************************************************
00568 //
00569 {
00570         #ifdef C_OBJECTBUFFER_TRACE
00571                 logmsg("ObjectBuffer::RemoveAll(DbC) invoked");
00572         #endif
00573         RemoveConnection(DbC->_Handle);
00574         #ifdef C_OBJECTBUFFER_TRACE
00575                 logmsg("ObjectBuffer::RemoveAll(DbC) finished");
00576         #endif
00577         return(true);
00578 };
00579 
00580 
00581 //***********************************************************************
00582 //***********************************************************************
00583 bool ObjectBuffer::RemoveAll(const Database *const DB)
00584 //***********************************************************************
00585 //***********************************************************************
00586 //
00587 { unsigned int i;
00588         #ifdef C_OBJECTBUFFER_TRACE
00589                 logmsg("ObjectBuffer::RemoveAll(DB) invoked ");
00590         #endif
00591         for (i=0;i<MAX_CONNECTION_PER_DATABASE;i++)
00592                 if (DB->_Connections[i]!=NULL)
00593                         RemoveAll(DB->_Connections[i]);
00594         #ifdef C_OBJECTBUFFER_TRACE
00595                 logmsg("ObjectBuffer::RemoveAll(DB) finished");
00596         #endif
00597         return(true);
00598 };
00599 
00600 //***********************************************************************
00601 //***********************************************************************
00602 bool ObjectBuffer::RemoveAll()
00603 //***********************************************************************
00604 //***********************************************************************
00605 //
00606 {
00607         #ifdef C_OBJECTBUFFER_TRACE
00608                 logmsg("ObjectBuffer::RemoveAll() invoked");
00609         #endif
00610 
00611         unsigned int i;
00612         for (i=0;i<MAX_CONNECTION;i++)
00613                 RemoveConnection(i);
00614 
00615         #ifdef C_OBJECTBUFFER_TRACE
00616                 logmsg("ObjectBuffer::RemoveAll() finished");
00617         #endif
00618         return(true);
00619 };
00620 
00621 //***********************************************************************
00622 //***********************************************************************
00623 bool ObjectBuffer::_RemoveConnection(int ConHandle)
00624 //***********************************************************************
00625 //***********************************************************************
00626 //
00627 {
00628         unsigned int j;
00629         BufferItem *ListItem,*RestOfList;
00630         Object *MemPtr;
00631 
00632         #ifdef C_OBJECTBUFFER_TRACE
00633                 logmsg("ObjectBuffer::_RemoveConnection() invoked");
00634         #endif
00635 
00636         for(j=0;j<HASH_TABLE_SIZE;j++){
00637                 RestOfList=_Structure[ConHandle][j];
00638                 while (RestOfList!=NULL){
00639                         ListItem=RestOfList;
00640                         RestOfList=RestOfList->_Next;
00641                         MemPtr=ListItem->GetMemoryPointer();
00642                         MemPtr->_MarkAsClean(); // No update of the deleted object
00643                         MemPtr->_FreeWasDone = true; 
00644                         delete(MemPtr);
00645                         delete((RefBase *)(ListItem->_RefBase));
00646                         _ObjectsInBuffer--;
00647                 }
00648         _Structure[ConHandle][j] = NULL;
00649         }
00650         #ifdef C_OBJECTBUFFER_TRACE
00651                 logmsg("ObjectBuffer::_RemoveConnection() finished");
00652         #endif
00653         return(true);
00654 };
00655 
00656 
00657 //***********************************************************************
00658 //***********************************************************************
00659 bool ObjectBuffer::_RemoveAll(const class Connection *const DbC)
00660 //***********************************************************************
00661 //***********************************************************************
00662 //
00663 {
00664         #ifdef C_OBJECTBUFFER_TRACE
00665                 logmsg("ObjectBuffer::_RemoveAll() invoked");
00666         #endif
00667 
00668         _RemoveConnection(DbC->_Handle);
00669 
00670         #ifdef C_OBJECTBUFFER_TRACE
00671                 logmsg("ObjectBuffer::_RemoveAll() finished");
00672         #endif
00673         return(true);
00674 };
00675 
00676 //***********************************************************************
00677 //***********************************************************************
00678 bool ObjectBuffer::_RemoveAll()
00679 //***********************************************************************
00680 //***********************************************************************
00681 //
00682 {
00683         unsigned int i;
00684 
00685         #ifdef C_OBJECTBUFFER_TRACE
00686                 logmsg("ObjectBuffer::_RemoveAll() invoked");
00687         #endif
00688 
00689         for (i=0;i<MAX_CONNECTION;i++)
00690                 _RemoveConnection(i);
00691 
00692         #ifdef C_OBJECTBUFFER_TRACE
00693                 logmsg("ObjectBuffer::_RemoveAll() finished");
00694         #endif
00695         return(true);
00696 };
00697 
00698 //***********************************************************************
00699 //***********************************************************************
00700 bool ObjectBuffer::_RemoveAll(const Database *const DB)
00701 //***********************************************************************
00702 //***********************************************************************
00703 //
00704 { unsigned int i;
00705 
00706         #ifdef C_OBJECTBUFFER_TRACE
00707                 logmsg("ObjectBuffer::_RemoveAll(DB) invoked");
00708         #endif
00709 
00710         for (i=0;i< MAX_CONNECTION_PER_DATABASE;i++)
00711                 if (DB->_Connections[i]!=NULL)
00712                         _RemoveAll(DB->_Connections[i]);
00713 
00714         #ifdef C_OBJECTBUFFER_TRACE
00715                 logmsg("ObjectBuffer::_RemoveAll(DB) invoked");
00716         #endif
00717 
00718         return(true);
00719 };
00720 
00721 //***********************************************************************
00722 //***********************************************************************
00723 bool ObjectBuffer::RemoveAllMemoryLocks()
00724 //***********************************************************************
00725 //***********************************************************************
00726 { unsigned int i;
00727 
00728         #ifdef C_OBJECTBUFFER_TRACE
00729                 logmsg("ObjectBuffer::RemoveAllMemoryLocks() invoked");
00730         #endif
00731 
00732         for (i=0;i<MAX_CONNECTION;i++)
00733                 if (Database::_AllConnections[i] != NULL)
00734                         RemoveAllMemoryLocks(*(Database::_AllConnections[i]));
00735 
00736         #ifdef C_OBJECTBUFFER_TRACE
00737                 logmsg("ObjectBuffer::RemoveAllMemoryLocks() finished");
00738         #endif
00739         return(true);
00740 };
00741 
00742 //***********************************************************************
00743 //***********************************************************************
00744 bool ObjectBuffer::RemoveAllMemoryLocks(class Database &DB)
00745 //***********************************************************************
00746 //***********************************************************************
00747 {
00748         unsigned int i;
00749 
00750         #ifdef C_OBJECTBUFFER_TRACE
00751                 logmsg("ObjectBuffer::RemoveAllMemoryLocks(Database &) invoked");
00752         #endif
00753 
00754         for (i=0;i<MAX_CONNECTION_PER_DATABASE;i++)
00755                 if (DB._Connections[i] != NULL)
00756                         RemoveAllMemoryLocks(*(DB._Connections[i]));
00757 
00758         #ifdef C_OBJECTBUFFER_TRACE
00759                 logmsg("ObjectBuffer::RemoveAllMemoryLocks(Database &) finished");
00760         #endif
00761         return(true);
00762 };
00763 
00764 //***********************************************************************
00765 //***********************************************************************
00766 bool ObjectBuffer::RemoveAllMemoryLocks(class Connection &DbConn)
00767 //***********************************************************************
00768 //***********************************************************************
00769 {
00770         unsigned int i = DbConn._Handle;
00771         unsigned int j;
00772         BufferItem *CurrentItem;
00773 
00774         #ifdef C_OBJECTBUFFER_TRACE
00775                 logmsg("ObjectBuffer::RemoveAllMemoryLocks(Connection &) invoked");
00776         #endif
00777 
00778         for (j = 0; j < HASH_TABLE_SIZE; j++)
00779         {
00780                 CurrentItem = _Structure[i][j];
00781                 while (CurrentItem)
00782                 {
00783                         ((Object *)CurrentItem->_MemoryPointer)->RemoveAllMemoryLocks();
00784                         CurrentItem = CurrentItem->_Next;
00785                 };
00786         };
00787 
00788         #ifdef C_OBJECTBUFFER_TRACE
00789                 logmsg("ObjectBuffer::RemoveAllMemoryLocks(Connection &) finished");
00790         #endif
00791         return(true);
00792 };
00793 
00794 //***********************************************************************
00795 //***********************************************************************
00796 Object *ObjectBuffer::GetReferencedObject (
00797         const RefBase &DbPtr //,
00798         //const enum LockingStrategy _Locking_strategy
00799         )
00800 //***********************************************************************
00801 //***********************************************************************
00802 //
00803 {
00804         Object *MemPtr;
00805         #ifdef C_OBJECTBUFFER_TRACE
00806                 logmsg("ObjectBuffer::GetReferencedObject(DbPtr) invoked");
00807         #endif
00808 
00809         _Requests++;
00810         if ((MemPtr=IsInMemory(DbPtr))!=NULL) {
00811                 #ifdef C_OBJECTBUFFER_TRACE
00812                         logmsg("ObjectBuffer::GetReferencedObject(DbPtr) finished");
00813                 #endif
00814                 _Hits++;
00815                 MemPtr->_Strategies=DbPtr._Strategies;
00816                 // if reload is necessary, refreshes the instance
00817                 MemPtr->_Refresh();
00818         }
00819         else {
00820                 MemPtr=(DbPtr.Prototype()->New());
00821                 MemPtr->_Connection=DbPtr._Connection;
00822                 MemPtr->_Strategies=DbPtr._Strategies;
00823                 DbPtr.Prototype()->_ExportKeyAttributes(DbPtr);
00824                 DbPtr.Prototype()->_Load(*MemPtr);
00825                 RegisterObject(DbPtr,MemPtr);
00826         }
00827         #ifdef C_OBJECTBUFFER_TRACE
00828                 logmsg("ObjectBuffer::GetReferencedObject(DbPtr) finished");
00829         #endif
00830         return(MemPtr);
00831 };
00832 
00833 // Set corresponging patrs of attribute _Strategies
00834 // that holds all concurency strategies
00835 bool ObjectBuffer::SetUpdatingStrategy(enum UpdatingStrategy anUpdatingStrategy)
00836 {
00837         #ifdef C_OBJECTBUFFER_TRACE
00838                 logmsg("bool ObjectBuffer::SetUpdatingStrategy(...) invoked");
00839         #endif
00840         switch (anUpdatingStrategy)
00841         {
00842                 case US_Current:
00843                         break;
00844                 case US_Inherited:
00845                 case US_Default:
00846                         _Strategies = _Strategies & ~US_MASK | DEFAULT_UPDATING_STRATEGY;
00847                         break;
00848                 default:
00849                         _Strategies = _Strategies & ~US_MASK | (unsigned int)anUpdatingStrategy;
00850         };
00851         #ifdef C_OBJECTBUFFER_TRACE
00852                 logmsg("bool ObjectBuffer::SetUpdatingStrategy(...) finished");
00853         #endif
00854         return true;
00855 };
00856 bool ObjectBuffer::SetWaitingStrategy(enum WaitingStrategy aWaitingStrategy)
00857 {
00858         #ifdef C_OBJECTBUFFER_TRACE
00859                 logmsg("bool ObjectBuffer::SetWaitingStrategy(...) invoked");
00860         #endif
00861         switch (aWaitingStrategy)
00862         {
00863                 case WS_Current:
00864                         break;
00865                 case WS_Inherited:
00866                 case WS_Default:
00867                         _Strategies = _Strategies & ~WS_MASK | DEFAULT_WAITING_STRATEGY;
00868                         break;
00869                 default:
00870                         _Strategies = _Strategies & ~WS_MASK | (unsigned int)aWaitingStrategy;
00871         };
00872         #ifdef C_OBJECTBUFFER_TRACE
00873                 logmsg("bool ObjectBuffer::SetWaitingStrategy(...) finished");
00874         #endif
00875         return true;
00876 };
00877 bool ObjectBuffer::SetLockingStrategy(enum LockingStrategy aLockingStrategy)
00878 {
00879         #ifdef C_OBJECTBUFFER_TRACE
00880                 logmsg("bool ObjectBuffer::SetLockingStrategy(...) invoked");
00881         #endif
00882         switch (aLockingStrategy)
00883         {
00884                 case LS_Current:
00885                         break;
00886                 case LS_Inherited:
00887                 case LS_Default:
00888                         _Strategies = _Strategies & ~LS_MASK | DEFAULT_LOCKING_STRATEGY;
00889                         break;
00890                 default:
00891                         _Strategies = _Strategies & ~LS_MASK | (unsigned int)aLockingStrategy;
00892         };
00893         #ifdef C_OBJECTBUFFER_TRACE
00894                 logmsg("bool ObjectBuffer::SetLockingStrategy(...) finished");
00895         #endif
00896         return true;
00897 };
00898 bool ObjectBuffer::SetReadingStrategy(enum ReadingStrategy aReadingStrategy)
00899 {
00900         #ifdef C_OBJECTBUFFER_TRACE
00901                 logmsg("bool ObjectBuffer::SetReadingStrategy(...) invoked");
00902         #endif
00903         switch (aReadingStrategy)
00904         {
00905                 case RS_Current:
00906                         break;
00907                 case RS_Inherited:
00908                 case RS_Default:
00909                         _Strategies = _Strategies & ~RS_MASK | DEFAULT_READING_STRATEGY;
00910                         break;
00911                 default:
00912                         _Strategies = _Strategies & ~RS_MASK | (unsigned int)aReadingStrategy;
00913         };
00914         #ifdef C_OBJECTBUFFER_TRACE
00915                 logmsg("bool ObjectBuffer::SetReadingStrategy(...) finished");
00916         #endif
00917         return true;
00918 };

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