OOFILE  1.9
oofrel.h
Go to the documentation of this file.
1 #ifndef H_OOFREL
2 #define H_OOFREL
3 // COPYRIGHT 1994 A.D. Software, All rights reserved
4 
5 // public layer of OOFILE database
6 
7 #ifndef H_OOF2
8  #include "oof2.h"
9 #endif
10 
11 class OOF_RelMN;
12 
20 {
21 public:
22  dbRelRefBase(const char* fieldName=0, unsigned long maxLinks=0);
23  dbRelRefBase(const dbRelRefBase& rhs);
24  virtual ~dbRelRefBase();
25  virtual dbField* clone() const;
26 
27  virtual void postCloneTableCleanup();
28  void completeCloneOfInverse(dbRelRefBase* cloner);
29  void completeCloneOfInverse(dbTable* clonerTable);
30  void setMNlink(OOF_RelMN*);
31  OOF_RelMN* getMNlink() const;
32 
33 // finish specifying the relationship
34  void relatesTo(dbRelRefBase&);
35 
36  void joinField(dbField&);
37  dbField* joinField() const;
38  bool propagatesDeletes() const;
39  void propagateRelatedDeletes(bool prop=true);
40 
42 
43  virtual OOF_fieldTypes fieldType() const;
44  virtual unsigned long fieldStorageLen() const;
46 
48 
49  virtual bool fieldIsSameTypeAs(const dbField*) const;
50  virtual const OOF_String& fieldName() const;
51  virtual void describe(std::ostream&) const;
52  virtual void extract(std::ostream&) const;
53  virtual OOF_fieldTypes nativeType() const;
54  virtual bool fieldIsVirtual() const;
55  dbRelRefBase* inverse() const;
56  dbTable* relatedTable();
57  tableNumT relatedTableNumber() const;
58  bool isRef() const;
59  virtual bool pointsToCorrectTableType() const;
61 
63 //{@
64  bool isOneToMany() const;
65  bool isManyToOne() const;
66  bool isOneToOne() const;
67  bool isManyToMany() const;
68  bool isJoin() const;
69  bool isRelBackToParent() const;
71 
73 //{@
74  unsigned long countAllRelated(); // note macros define countAllRelatedIn()
75  bool relateRecord(bool broadcastChange=true);
76  bool selectAllRelated(bool broadcastChange=true);
77  bool relateFromRecord(bool broadcastChange=true);
79 
81 
82  void updateRelValue(); // update link for rhs
83  void setOID(oidT);
84  void breakRelLink(); // maintain referential integrity
85  void changeRelationshipTo(dbRelRefBase& newRhs);
87  virtual bool receiveMsg(OOFmsgT msg, unsigned long senderDefined);
88 
89 protected:
90  unsigned long CountAllRelatedIn(dbTable*); // used by macros
91  void BuildRelatedTable();
92  bool CompletelySpecified() const;
93  void SetCommonRelationshipFields(dbRelRefBase&);
94  oidT OID() const;
95  void OID(oidT);
96 
97 // data storage
98  unsigned long mMinLinks, mMaxLinks;
99  dbTable* mRelatedTableProto; // the prototype of the related table
100  dbTable* mActualRelatedTable; // the cloned table managing the related selection
105  OOF_RelMN* mMNlink; // owned, ref-counted
106 };
107 
108 
114 {
115 public:
116  dbRelRef(const char* fieldName=0);
117  virtual ~dbRelRef();
118  dbRelRef(const dbRelRef&);
119  const dbRelRef& operator=(const dbRelRef&);
120 
121  dbQueryBinary nullRelationship() const;
122  bool setRelatedRecord(oidT);
123  bool setRelatedRecord(dbTable*);
124  bool setRelatedRecordMatching(const dbQueryClause&);
125 
126 protected:
128 };
129 
130 
136 {
137 public:
139  dbRelSet(const char* inFieldName=0) : dbRelRefBase(inFieldName) {};
140  // use default copy ctor
141 };
142 
143 
155 {
156 public:
157 // just exists to declare a relationship
160 // variations with join fields
163 
164 // method to specify an M:N linker
165  void linkMNvia(dbRelRefBase&, dbRelRefBase&);
166  void linkMNvia(dbRelRefBase*, dbRelRefBase*);
167 
168 // data storage
169 private:
170  dbRelRefBase& mLHS;
171  dbRelRefBase& mRHS;
172 };
173 
174 
182 private: // only used by friends
183  OOF_RelMN(dbRelRefBase& lhs, dbRelRefBase& rhs);
184  OOF_RelMN(const OOF_RelMN& rhs);
185 
186  bool RelateMN();
187  dbTable* BuildRelatedTable(dbRelRefBase* cloner);
188 
189 public:
190  void incRefs();
191  void decRefs(); // may delete this
192  bool cloningRelIs(dbRelRefBase*);
193 
194  void makeRelMaintainer();
195  void appendSelection(dbSelection*);
196  void removeSelection(dbSelection*);
197  void clearSelection();
198 
199 
200 private:
201 // data storage
202  dbRelRefBase& mProtoLHS;
203  dbRelRefBase& mProtoRHS;
204  unsigned int mReferences;
205  dbRelRefBase* mRelToLHS;
206  dbRelRefBase* mRelToRHS;
207  dbRelMaintainer* mMaintainer;
208 
209  static OOF_RelMN* sCurrentlyBuilding;
210  static dbRelRefBase* sCurrentRHSref;
211 
212 friend class dbRelRefBase;
213 friend class dbRelationship;
214 };
215 
216 
217 // -------------------------------------------------------
218 // d b R e l R e f B a s e
219 // -------------------------------------------------------
220 inline OOF_RelMN*
222 {
223  return mMNlink;
224 }
225 
226 
227 inline bool
229 {
230  return mRelatedTableProto!=0;
231 }
232 
233 
234 inline bool
236 {
237  return mPropagatesDeletes;
238 }
239 
240 
241 inline dbRelRefBase*
243 {
244  assert(mActualRelatedTable);
245  return (dbRelRefBase*) (mActualRelatedTable->field(mInverseFieldNumber) ); // safe downcast
246 }
247 
248 
249 inline dbField*
251 {
252  return mJoinField;
253 }
254 
255 
260 inline bool
262 {
263  return mMaxLinks==1;
264 }
265 
266 
267 inline bool
269 {
270  assert(mInverseField);
271  return !isRef() && mInverseField->isRef();
272 }
273 
274 
275 inline bool
277 {
278  assert(mInverseField);
279  return isRef() && !mInverseField->isRef();
280 }
281 
282 
283 inline bool
285 {
286  assert(mInverseField);
287  return isRef() && mInverseField->isRef();
288 }
289 
290 
291 inline bool
293 {
294  assert(mInverseField);
295  return !isRef() && !mInverseField->isRef();
296 }
297 
298 
303 inline bool
305 {
306  assert(CompletelySpecified());
307  return mJoinField!=0;
308 }
309 
310 
320 inline bool
322 {
323  return mTable->controllingRelationship()==this;
324 }
325 
326 #endif
327 
unsigned long mMinLinks
Definition: oofrel.h:98
dbRelSet(const char *inFieldName=0)
ctor allowing you to pass field name for relationship.
Definition: oofrel.h:139
virtual const oofString & fieldName() const
Definition: oof3.h:769
bool mPropagatesDeletes
Definition: oofrel.h:103
dbField * mJoinField
Definition: oofrel.h:102
OOF_RelMN * getMNlink() const
Definition: oofrel.h:221
dbRelRefBase * mInverseField
Definition: oofrel.h:104
bool isRef() const
Is "ref" to just one instance.
Definition: oofrel.h:261
Highest level used to assemble queries.
Definition: oofquery.h:46
dbRelRefBase * inverse() const
Definition: oofrel.h:242
Envelope class to contain an abstract selection apart from its dbTable.
Definition: oof1.h:316
dbTable * mCachedSearchTable
Definition: oofrel.h:127
Object used to specify relationship between two dbTable instances.
Definition: oofrel.h:154
virtual unsigned long fieldStorageLen() const =0
Special limited oofReceiver which will only ever listen to one oofBroadcaster at a time...
Definition: oofmsg.h:133
virtual bool receiveMsg(OOFmsgT msg, unsigned long senderDefined)
The default receiveMsg behaviour is to delete yourself when the broadcaster closes.
Definition: oofmsg.cpp:275
bool propagatesDeletes() const
Definition: oofrel.h:235
bool isJoin() const
If we don't have mJoinField then we are a pointer relationship.
Definition: oofrel.h:304
virtual OOF_fieldTypes nativeType() const
Definition: oof3.cpp:301
Common binary query for field, eg: People.Salary > 90000.
Definition: oofquery.h:165
Created by dbRelationship::linkMNvia to maintain an MN relationship.
Definition: oofrel.h:181
Parent for any field that is a relationship to another table.
Definition: oofrel.h:19
virtual void postCloneTableCleanup()
Definition: oof3.h:77
unsigned short tableNumT
Definition: oof1.h:275
dbRelRefBase * controllingRelationship() const
Definition: oof1.h:1816
unsigned long oidT
type we pass around pretending we have a real OID.
Definition: oof1.h:229
dbTable * mTable
Definition: oof3.h:156
void operator=(const char *)
Definition: oof3.h:671
virtual bool fieldIsSameTypeAs(const dbField *) const
Definition: oof3.cpp:557
Relationship field to set of 0..N instances.
Definition: oofrel.h:135
bool isManyToMany() const
Definition: oofrel.h:292
OOF_fieldTypes
Definition: oof3.h:26
virtual void describe(std::ostream &) const
Provide human-readable information about object.
Definition: oof3.cpp:544
bool isRelBackToParent() const
Do we point left or right? ie: in Patients->Visits is this relationship field pointing back from Visi...
Definition: oofrel.h:321
dbField * field(fieldNumT) const
Definition: oof1.h:2355
unsigned short fieldNumT
Definition: oof1.h:276
bool isOneToOne() const
Definition: oofrel.h:284
Base class for persistent tables.
Definition: oof1.h:452
virtual void extract(std::ostream &) const
Definition: oof3.cpp:506
Portable highly capable string class.
Definition: oofstr.h:101
OOF_RelMN * mMNlink
Definition: oofrel.h:105
bool CompletelySpecified() const
Definition: oofrel.h:228
dbTable * mActualRelatedTable
Definition: oofrel.h:100
virtual dbField * clone() const =0
listener for an MN link that adds and deletes records.
Definition: oof1.h:1456
virtual bool fieldIsVirtual() const
Definition: oof3.cpp:400
virtual OOF_fieldTypes fieldType() const =0
unsigned long OOFmsgT
Definition: oofmsg.h:31
unsigned long mMaxLinks
Definition: oofrel.h:98
fieldNumT mInverseFieldNumber
Definition: oofrel.h:101
#define OOFILE_EXPORT
Prefix for OOFILE database & general classes to enable optional DLL linking.
Definition: oof0.h:187
dbField * joinField() const
Definition: oofrel.h:250
dbTable * mRelatedTableProto
Definition: oofrel.h:99
bool isOneToMany() const
Definition: oofrel.h:268
bool isManyToOne() const
Definition: oofrel.h:276
Base class for persistent fields in dbTable's.
Definition: oof3.h:63
Relationship field to 1 or 0 instances.
Definition: oofrel.h:113