00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __C_PROTOBASE_H__
00016 #define __C_PROTOBASE_H__
00017
00018
00019 #include <stdio.h>
00020 #include <malloc.h>
00021 #include <fstream.h>
00022
00023
00024 #include <lDefs.h>
00025
00026
00027 #include <cQueRefProto.h>
00028
00029 class DLL_External ProtoBase : public QueRefProto
00030 {
00031 #ifdef POLITE_TEST_FRIEND
00032 friend POLITE_TEST_FRIEND;
00033 #endif // POLITE_TEST_FRIEND
00034
00035 friend class RefBase;
00036 friend class ClassRegister;
00037 friend class Object;
00038 friend class DatabaseObject;
00039 friend class ObjectBuffer;
00040 friend class ResultBase;
00041 friend class ChainedRelationBase;
00042
00043 protected:
00044 static class ProtoBase *_root;
00045
00046 static class ProtoBase *_first;
00047
00048
00049
00050 class ProtoBase *_left, *_right, *_next;
00051 bool _initialised;
00052 bool _processed;
00053 bool _isObject, _isImmutableObject, _isDatabaseObject, _isPersistentObject, _isRootClass;
00054
00055
00056 char *_condition;
00057 struct
00058 {
00059 int KeyCount;
00060
00061
00062 int Count;
00063
00064 int SpecCount;
00065
00066
00067
00068
00069 void *Arr;
00070 } _sqlVars;
00071
00072
00073 class ProtoBase *_rootPrototype;
00074
00075
00076 int _parentPrototypeCount;
00077
00078 class ProtoBase **_parentPrototype;
00079
00080 int _fullParentPrototypeCount;
00081
00082 class ProtoBase **_fullParentPrototype;
00083
00084 char *_select;
00085 char *_fullSelect;
00086 char *_keySelect;
00087 char *_ptrSelect;
00088 char *_into;
00089
00090
00091 char *_fullFrom;
00092 char *_where;
00093 char *_fullWhere;
00094 char *_keyWhere;
00095 char *_groupBy;
00096 char *_having;
00097 char *_stmtSelect;
00098 char *_stmtInsert;
00099 char *_stmtDelete;
00100 char *_stmtUpdate;
00101 static void _ResetProcessed(ProtoBase * const _p);
00102 virtual bool _KeyValues(char *&s);
00103 virtual char * _KeyValues(const class Object &o);
00104
00105 virtual bool _ExportAttributes(const class Object &o);
00106
00107 virtual bool _ExportKeyAttributes(const class Object &o);
00108
00109 virtual bool _ExportKeyAttributes(const class RefBase &x);
00110
00111 virtual bool _ImportAttributes(class Object &o);
00112
00113 virtual bool _ImportKeyAttributes(class RefBase &x);
00114
00115 void _Initialise();
00116 void _InitialiseParentPrototype();
00117 void _InitialiseFullParentPrototype(class ProtoBase *_p);
00118 void _InitialiseSqlVar();
00119 void _InitialiseSelect();
00120 void _InitialiseFullSelect();
00121 void _InitialiseKeySelect();
00122 void _InitialisePtrSelect();
00123 void _InitialiseInto();
00124
00125
00126 void _InitialiseFullFrom();
00127 void _InitialiseWhere();
00128 void _InitialiseFullWhere();
00129 void _InitialiseKeyWhere();
00130 void _InitialiseGroupBy();
00131 void _InitialiseHaving();
00132 void _InitialiseStmtSelect();
00133 void _InitialiseStmtInsert();
00134 void _InitialiseStmtDelete();
00135 void _InitialiseStmtUpdate();
00136
00137 char * _StmtSelectPtr(
00138
00139
00140
00141
00142
00143
00144 const QueRefProto &Q,
00145 const int i
00146 );
00147
00148 char * _StmtSelectPtr(
00149
00150
00151
00152
00153
00154 const char *const _where_clause,
00155 const char *const _order_by_clause,
00156 const char *const _select_clause,
00157 const char *const _from_clause,
00158 const int i
00159 );
00160
00161 bool _BindPtr(
00162
00163 class Cursor *C
00164 );
00165
00166 ProtoBase *_PtrPrototype();
00167
00168
00169 public:
00170 virtual char* _Where() const {return StrCpy(_condition);};
00171 virtual char* _OrderBy() const {return StrCpy(OrderBy());};
00172 static void Register(class ProtoBase *_p, const char * const _n);
00173
00174 static class ProtoBase *Find(const char * const _n);
00175 virtual class ResultBase * ExecuteQuery(
00176 const QueRefProto &Q,
00177 class Connection *DbCon,
00178 const int i,
00179 class ResultBase * QR
00180 );
00181 bool operator==(class ProtoBase &_p) {return (this == &_p);};
00182 bool operator!=(class ProtoBase &_p) {return (this != &_p);};
00183 bool operator<(class ProtoBase &_p);
00184 bool operator>(class ProtoBase &_p) {return (_p < *this);};
00185 bool operator<=(class ProtoBase &_p) {return ((this == &_p) || (*this < _p));};
00186 bool operator>=(class ProtoBase &_p) {return ((this == &_p) || (_p < *this));};
00187 ProtoBase() :
00188 _left(NULL),
00189 _right(NULL),
00190 _next(NULL),
00191 _initialised(false),
00192 _processed(false),
00193 _isObject(false),
00194 _isImmutableObject(false),
00195 _isDatabaseObject(false),
00196 _isPersistentObject(false),
00197 _isRootClass(false),
00198 _condition(NULL),
00199 _rootPrototype(NULL),
00200 _parentPrototypeCount(0),
00201 _parentPrototype(NULL),
00202 _fullParentPrototypeCount(0),
00203 _fullParentPrototype(NULL),
00204 _select(NULL),
00205 _fullSelect(NULL),
00206 _keySelect(NULL),
00207 _ptrSelect(NULL),
00208 _into(NULL),
00209
00210
00211 _fullFrom(NULL),
00212 _where(NULL),
00213 _fullWhere(NULL),
00214 _keyWhere(NULL),
00215 _stmtSelect(NULL),
00216 _stmtInsert(NULL),
00217 _stmtDelete(NULL),
00218 _stmtUpdate(NULL)
00219 {
00220 _sqlVars.KeyCount = 0;
00221 _sqlVars.Count = 0;
00222 _sqlVars.Arr = NULL;
00223 };
00224 ~ProtoBase();
00225 virtual bool IsObject() {_Initialise(); return _isObject;};
00226 virtual bool IsImmutableObject() {_Initialise(); return _isImmutableObject;};
00227 virtual bool IsDatabaseObject() {_Initialise(); return _isDatabaseObject;};
00228 virtual bool IsPersistentObject() {_Initialise(); return _isPersistentObject;};
00229 virtual const char* ClassName() = 0;
00230 virtual const char* BaseClassName() {return NULL;};
00231 virtual const char* RootClassName() = 0;
00232 virtual const char* ParentClassNames() = 0;
00233 virtual const char* Select() {_Initialise(); return _select;};
00234 virtual const char* Into() {_Initialise(); return _into;};
00235 virtual const char* From() = 0;
00236 virtual const char* Where() {_Initialise(); return _where;};
00237 virtual const char* GroupBy() {_Initialise(); return _groupBy;};
00238 virtual const char* Having() {_Initialise(); return _having;};
00239 virtual const char* OrderBy() const = 0;
00240 virtual const char* FullSelect() {_Initialise(); return _fullSelect;};
00241 virtual const char* FullFrom() {_Initialise(); return _fullFrom;};
00242 virtual char* FullFrom(int k);
00243 virtual const char* FullWhere() {_Initialise(); return _fullWhere;};
00244 virtual char* FullWhere(int k);
00245 virtual const char* KeySelect() {_Initialise(); return _keySelect;};
00246
00247 virtual const char* KeyWhere() {_Initialise(); return _keyWhere;};
00248
00249 virtual const char* KeyFrom() {return _rootPrototype->From();};
00250 virtual class ProtoBase * RootPrototype() const {return _rootPrototype;};
00251 virtual int ParentPrototypeCount() {_Initialise(); return _parentPrototypeCount;};
00252 virtual class ProtoBase * ParentPrototype(const int i);
00253 virtual int FullParentPrototypeCount() {_Initialise(); return _fullParentPrototypeCount;};
00254 virtual class ProtoBase * FullParentPrototype(const int i);
00255 virtual class Object *New() const = 0;
00256
00257 virtual class RefBase *NewRef() = 0;
00258
00259
00260
00261
00262 const char* ColumnTable(const char* const col);
00263
00264
00265 protected:
00266 virtual char *_RealiasT(
00267 char * &fragment,
00268 const char *table,
00269 const int i,
00270 const int j
00271 );
00272
00273 virtual char *_RealiasT(
00274 char * &fragment,
00275 const int i
00276 );
00277
00278 virtual void _MapKey(int i, const char *&attr, unsigned char Object::*&mem, const char *&col, char &type, unsigned int &len, bool &rw) = 0;
00279 virtual void _Map(int i, const char *&attr, unsigned char Object::*&mem, const char *&col, char &type, unsigned int &len, bool &rw) = 0;
00280 virtual const char *_ProtoTWhere() = 0;
00281 virtual const char *_ProtoTGroupBy() = 0;
00282 virtual const char *_ProtoTHaving() = 0;
00283 bool _InsertAll(class Object *target);
00284
00285 bool _Insert(class Connection *aDbConn);
00286
00287 bool _UpdateAll(class Object *target);
00288
00289 bool _Update(class Connection *aDbConn);
00290
00291 bool _DeleteAll(class RefBase *target);
00292
00293 bool _DeleteAll(class Object *target);
00294
00295 bool _Delete(class Connection * aDbConn);
00296
00297 bool ProtoBase::_Load(
00298 class Object &o
00299 );
00300
00301
00302 public:
00304
00305
00306 bool ProtoBase::LockTable(
00307 class Connection *aDbCon,
00308 enum LockingStrategy aLockingStrategy = LS_Default,
00309 enum WaitingStrategy aWaitingStrategy = WS_Default
00310 );
00311
00312 bool WriteDDL(ofstream &S, class Database &Db);
00313
00314 char *ProtoBase::ColumnTypeDDL(int i, class Database &Db);
00315
00316
00317 protected:
00318 char *_TranslateToSql(char * (&dst), const char * const src);
00319 char *_TranslateToSql(char * (&src));
00320
00321 class Query &_TranslateToSql(class Query &Q);
00322
00323 ProtoBase *_gcs(ProtoBase &X);
00324
00325
00326 };
00327
00328
00329 #endif //__GC__PROTOBASE_H__