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

cObjRef.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 <cObjRef.h>                                    // ObjRef class header
00017 
00018 // Other POLiTe Header(s)
00019 #include <cRefBase.h>
00020 #include <cProtoBase.h>
00021 #include <cQuery.h>
00022 #include <cConnection.h>
00023 
00025 //  An Object is a common ancestor class of RefBase and
00026 //  Object. It is virtual class.
00027 //      Object is a simple object which consists of some methods,
00028 //      that in its successors must be redefined.
00029 //  It was created to resolve some problems with RefBase and
00030 //      Object (and ResultBase as well).
00031 //
00033 
00035 // Object constructor:
00036 // Create the Object object with the appropriate initialization.
00037 
00038 ObjRef::ObjRef()
00039 {
00040         _Strategies =
00041                 DEFAULT_LOCKING_STRATEGY
00042                 | DEFAULT_UPDATING_STRATEGY
00043                 | DEFAULT_WAITING_STRATEGY
00044                 | DEFAULT_READING_STRATEGY;
00045         _Connection = NULL;
00046         #ifdef GC_OBJRF_TRACE
00047         logmsg("ObjRef::ObjRef() invoked and finished");
00048         #endif
00049 }
00050 
00052 // Object destructor:
00053 // Delete the Object object with the appropriate de-initialization.
00054 
00055 ObjRef::~ObjRef()
00056 {
00057         #ifdef GC_OBJRF_TRACE
00058         logmsg("ObjRef::~ObjRef() invoked and finished");
00059         #endif
00060 }
00061 
00062 char *ObjRef::_Where() const
00063 //Returns Where clause in SQL select for referenced object
00064 {
00065         if (Prototype() == NULL)
00066                 return NONE._Where();
00067         char *_where = NULL;
00068         char *_columns = StrCpy(_columns = NULL, Prototype()->KeySelect());
00069         char *_values = _KeyValues();
00070         char *_1column = NULL;
00071         char *_1value = NULL;
00072         const char *delim = "";
00073         while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value))
00074         {
00075                 StrDecode(_1value);
00076                 StrCat(_where,6,delim,"(",_1column," = ",_1value,")");
00077                 delim = " AND ";
00078                 StrFree(_1column);
00079                 StrFree(_1value);
00080         };
00081         StrFree(_columns);
00082         StrFree(_values);
00083         return _where;
00084 };
00085 
00086 bool ObjRef::IsAncestor(
00087   const ObjRef &descendant
00088   ) const
00089         // Returns if *this Object is ancestor
00090         // of *descendant Object
00091 {
00092         return (this->Prototype())>=(descendant.Prototype());
00093 };
00094 
00096 // returns oid of the object referenced by the database pointer
00097 // and vice versa
00098 // Usefull for representing pointers to objects between application classes
00099 
00100 /*
00101 long int ObjRef::_PtrToOid(
00102         const ObjRef &ref
00103    ) const
00104 {
00105         if (ref.Prototype()->IsPersistentObject())
00106                 return StrToLong(ref.SelectKeyValues());
00107         return 0;
00108 };
00109 */
00110 
00111 /*
00112 RefBase ObjRef::_OidToPtr(
00113         const long int oid,
00114         class ProtoBase *prot
00115         ) const
00116 {
00117 
00118         if (oid <= 0)
00119                 return (RefBase &)DBNULL;
00120         else
00121         {
00122                 RefBase result(Connection(),prot,LongToStr(oid));
00123                 result.Virtualise();
00124                 return result;
00125         };
00126 };
00127 */
00128 
00129 /*
00130 Object *ObjRef::_OidToMemPtr(
00131         const long int oid,
00132    class ProtoBase *prot
00133         ) const
00134 {
00135 
00136         if (oid <= 0)
00137                 return NULL;
00138    else
00139    {
00140         RefBase result(Connection(),prot,LongToStr(oid));
00141       result.Virtualise();
00142                 return &(result.ReferencedObject());
00143    };
00144 };
00145 */
00146 
00147 // Set corresponging patrs of attribute _Strategies
00148 // that holds all concurency strategies
00149 bool ObjRef::SetUpdatingStrategy(enum UpdatingStrategy anUpdatingStrategy)
00150 {
00151         #ifdef C_OBJREF_TRACE
00152                 logmsg("bool ObjRef::SetUpdatingStrategy(...) invoked");
00153         #endif
00154         switch (anUpdatingStrategy)
00155         {
00156                 case US_Current:
00157                         break;
00158                 case US_Inherited:
00159                         _Strategies = _Strategies & ~US_MASK | (unsigned int)(_Connection ? _Connection->CurrentUpdatingStrategy() : DEFAULT_UPDATING_STRATEGY);
00160                         break;
00161                 case US_Default:
00162                         _Strategies = _Strategies & ~US_MASK | DEFAULT_UPDATING_STRATEGY;
00163                         break;
00164                 default:
00165                         _Strategies = _Strategies & ~US_MASK | (unsigned int)anUpdatingStrategy;
00166         };
00167         #ifdef C_OBJREF_TRACE
00168                 logmsg("bool ObjRef::SetUpdatingStrategy(...) finished");
00169         #endif
00170         return true;
00171 };
00172 bool ObjRef::SetWaitingStrategy(enum WaitingStrategy aWaitingStrategy)
00173 {
00174         #ifdef C_OBJREF_TRACE
00175                 logmsg("bool ObjRef::SetWaitingStrategy(...) invoked");
00176         #endif
00177         switch (aWaitingStrategy)
00178         {
00179                 case WS_Current:
00180                         break;
00181                 case WS_Inherited:
00182                         _Strategies = _Strategies & ~WS_MASK | (unsigned int)(_Connection ? _Connection->CurrentWaitingStrategy() : DEFAULT_WAITING_STRATEGY);
00183                         break;
00184                 case WS_Default:
00185                         _Strategies = _Strategies & ~WS_MASK | DEFAULT_WAITING_STRATEGY;
00186                         break;
00187                 default:
00188                         _Strategies = _Strategies & ~WS_MASK | (unsigned int)aWaitingStrategy;
00189         };
00190         #ifdef C_OBJREF_TRACE
00191                 logmsg("bool ObjRef::SetWaitingStrategy(...) finished");
00192         #endif
00193         return true;
00194 };
00195 bool ObjRef::SetLockingStrategy(enum LockingStrategy aLockingStrategy)
00196 {
00197         #ifdef C_OBJREF_TRACE
00198                 logmsg("bool ObjRef::SetLockingStrategy(...) invoked");
00199         #endif
00200         switch (aLockingStrategy)
00201         {
00202                 case LS_Current:
00203                         break;
00204                 case LS_Inherited:
00205                         _Strategies = _Strategies & ~LS_MASK | (unsigned int)(_Connection ? _Connection->CurrentLockingStrategy() : DEFAULT_LOCKING_STRATEGY);
00206                         break;
00207                 case LS_Default:
00208                         _Strategies = _Strategies & ~LS_MASK | DEFAULT_LOCKING_STRATEGY;
00209                         break;
00210                 default:
00211                         _Strategies = _Strategies & ~LS_MASK | (unsigned int)aLockingStrategy;
00212         };
00213         #ifdef C_OBJREF_TRACE
00214                 logmsg("bool ObjRef::SetLockingStrategy(...) finished");
00215         #endif
00216         return true;
00217 };
00218 bool ObjRef::SetReadingStrategy(enum ReadingStrategy aReadingStrategy)
00219 {
00220         #ifdef C_OBJREF_TRACE
00221                 logmsg("bool ObjRef::SetReadingStrategy(...) invoked");
00222         #endif
00223         switch (aReadingStrategy)
00224         {
00225                 case RS_Current:
00226                         break;
00227                 case RS_Inherited:
00228                         _Strategies = _Strategies & ~RS_MASK | (unsigned int)(_Connection ? _Connection->CurrentReadingStrategy() : DEFAULT_READING_STRATEGY);
00229                         break;
00230                 case RS_Default:
00231                         _Strategies = _Strategies & ~RS_MASK | DEFAULT_READING_STRATEGY;
00232                         break;
00233                 default:
00234                         _Strategies = _Strategies & ~RS_MASK | (unsigned int)aReadingStrategy;
00235         };
00236         #ifdef C_OBJREF_TRACE
00237                 logmsg("bool ObjRef::SetReadingStrategy(...) finished");
00238         #endif
00239         return true;
00240 };

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