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

cObjectBuffer.h

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 #ifndef __C_OBJECTBUFFER_H__
00016 #define __C_OBJECTBUFFER_H__
00017 
00018 // Common POLiTe Header(s)
00019 #include <lDefs.h>
00020 #include <lTypes.h>
00021 #include <lExceptions.h>
00022 
00023 extern DLL_External class ObjectBuffer ObjectCache;
00024 
00025 class DLL_External ObjectBuffer
00026 {
00027 #ifdef POLITE_TEST_FRIEND
00028         friend POLITE_TEST_FRIEND;
00029 #endif // POLITE_TEST_FRIEND
00030 
00031 friend class Connection;
00032 friend class Database;
00033 friend class RefBase;
00034 
00035 protected:
00036         bool _Initialised;
00037         bool _ResetForUpdateFlags;
00038         // If set, UpdateAll resets _ForUpdate flags in objects
00039         // This is necessary to do, if the connection is commited
00040         // because locks are then released
00041         unsigned long int _Requests;
00042         // Number of requests to object buffer
00043         unsigned long int _Hits;
00044         // Number of hits
00045         unsigned short _Strategies;
00046         class BufferItem *_LastAccessedItem;
00047         class BufferItem *_Structure[MAX_CONNECTION][HASH_TABLE_SIZE];
00048         unsigned long _ObjectsInBuffer;
00049 
00050         unsigned long _GarbageCollector();
00051         // returns the number of the objects removed from the buffer
00052         unsigned int _Hash(const char *values) const;
00053         class BufferItem * _FindItem(const class RefBase &DbPtr);
00054         // similar to IsInMemory, instead databasepointer returns bufferitem
00055         bool _RemoveConnection (int ConHandle);
00056         // similar to _RemoveAll(Connection), instead pointer to database connection
00057         // takes handle as a parameter
00058         bool RemoveConnection (int ConHandle);
00059         // similar to RemoveAll(Connection), instead pointer to database connection
00060         // takes handle as a parameter
00061         // Differently from _RemoveConnection does some additional tests
00062         bool UpdateConnection (int ConHandle);
00063         // see above (Connection) and below (Update)
00064 
00065 public:
00066         ObjectBuffer(); // Init() from the specification
00067 
00068         ~ObjectBuffer(); // Close() from the specification
00069 
00070         bool Init(
00071                 const enum LockingStrategy aLockingStrategy,
00072                 const enum UpdatingStrategy anUpdateStrategy,
00073                 const enum WaitingStrategy aWaitingStrategy
00074                 );
00075 
00076         class Object *IsInMemory(
00077                 const class RefBase &DbPtr
00078                 );
00079         // If the object is in the internal data structure, the pointer
00080         // to it is returned, otherwise NULL
00081         // If the RefBase contains NULL as memory pointer or
00082         // database connection, the exception is thrown
00083 
00084         bool RegisterObject(
00085                 const class RefBase &DbPtr,
00086                 const class Object *const MemPtr
00087                 );
00088         // Is called, when the newly created object is made persistent
00089         // or whenever the buffer loads object to the memory
00090 
00091         bool RemoveObject(
00092                 class Object *MemPtr,
00093                 const class Connection * const DbCon);
00094         // The corresponding buffer item is freed from the memory.
00095         // Is called by DatabaseObject.Delete or Free
00096 
00097         bool RemoveObject(const class RefBase &DbPtr);
00098         // The corresponding buffer item is freed from the memory.
00099         // Is called by DatabaseObject.Delete or Free
00100 
00101         // All dirty objects are written to the database.
00102         bool UpdateAll();
00103         bool UpdateAll(const class Connection *const DbC);
00104         bool UpdateAll(const class Database *const DB);
00105 
00106         // All the objects are freed from the memory
00107         bool RemoveAll();
00108         bool RemoveAll(const class Connection *const DbC);
00109         bool RemoveAll(const class Database *const DB);
00110 
00111         // Get and set corresponging patrs of attribute _Strategies
00112         // that holds all concurency strategies
00113         virtual enum UpdatingStrategy CurrentUpdatingStrategy() const
00114         // Returns Update Strategy part of attribute _Strategies
00115         {
00116                 return (enum UpdatingStrategy)(_Strategies & US_MASK);
00117         };
00118         virtual bool SetUpdatingStrategy(enum UpdatingStrategy anUpdateStrategy);
00119         virtual enum WaitingStrategy CurrentWaitingStrategy() const
00120         {
00121                 return (enum WaitingStrategy)(_Strategies & WS_MASK);
00122         };
00123         virtual bool SetWaitingStrategy(enum WaitingStrategy aWaitingStrategy);
00124         virtual enum LockingStrategy CurrentLockingStrategy() const
00125         {
00126                 return (enum LockingStrategy)(_Strategies & LS_MASK);
00127         };
00128         virtual bool SetLockingStrategy(enum LockingStrategy aLockingStrategy);
00129         virtual enum ReadingStrategy CurrentReadingStrategy() const
00130         {
00131                 return (enum ReadingStrategy)(_Strategies & RS_MASK);
00132         };
00133         virtual bool SetReadingStrategy(enum ReadingStrategy aReadingStrategy);
00134 
00135 protected:
00136         bool _RemoveAll();
00137         bool _RemoveAll(const class Connection *const DbC);
00138         bool _RemoveAll(const class Database *const DB);
00139 
00140 public:
00141 //  DatabaseObject *MemoryLock(const class RefBase &const DbPtr);
00142                                         // Multilevel lock of the object
00143 //  bool MemoryUnlock(const class RefBase &const DbPtr);
00144                                         // One lock on the object is released
00145 
00146         bool RemoveAllMemoryLocks();
00147         bool RemoveAllMemoryLocks(class Database &DB);
00148         bool RemoveAllMemoryLocks(class Connection &DbConn);
00149 
00150         Object *GetReferencedObject(
00151                 const class RefBase &DbPtr
00152                 );
00153         // From DbPtr recognizes appropriate buffer item
00154         // then creates empty copy of appropriate object
00155         // finally fills the copy with values from the database
00156 
00157         //unsigned int MemoryLocked(const class RefBase &const DbPtr);
00158         // Returns the number of lock on the object
00159 
00160 };
00161 
00162 #endif //__C_OBJECTBUFFER_H__

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