00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _EYEDB_ODL_H
00026 #define _EYEDB_ODL_H
00027
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <string.h>
00031 #include <eyedb/eyedb.h>
00032
00033 extern "C" {
00034 extern int odlparse();
00035 }
00036
00037 namespace eyedb {
00038
00039 extern int odl_error;
00040
00041
00042
00043
00044
00045 template <class T> struct odl_temp_link {
00046 T x;
00047 odl_temp_link<T> *next;
00048
00049 odl_temp_link(T _x) : x(_x) {
00050 next = 0;
00051 }
00052
00053 ~odl_temp_link() {}
00054 };
00055
00056 template <class T> class odl_temp_list {
00057
00058 public:
00059 odl_temp_link<T> *first;
00060 odl_temp_link<T> *last;
00061
00062 int count;
00063
00064 odl_temp_list() {
00065 first = last = 0;
00066 count = 0;
00067 }
00068 void add(T x) {
00069 odl_temp_link<T> *l = new odl_temp_link<T>(x);
00070 if (last)
00071 last->next = l;
00072 else
00073 first = l;
00074 last = l;
00075 count++;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085 ~odl_temp_list() {
00086 odl_temp_link<T> *l = first;
00087 while (l)
00088 {
00089 odl_temp_link<T> *next = l->next;
00090 delete l;
00091 l = next;
00092 }
00093 }
00094 };
00095
00096 enum odlBool {
00097 odlFalse = 0,
00098 odlTrue = 1
00099 };
00100
00101 extern const char *odl_get_typname(const char *);
00102
00103 class odlIndexImplSpec;
00104 class odlCollImplSpec;
00105 class odlImplementation;
00106
00107 class odlClassSpec {
00108
00109 public:
00110 char *classname, *parentname, *aliasname;
00111 odlCollImplSpec *coll_impl_spec;
00112
00113 odlClassSpec(const char *_classname, const char *_parentname,
00114 const char *_aliasname, odlCollImplSpec *_coll_impl_spec);
00115
00116 ~odlClassSpec() {
00117 free(classname);
00118 free(parentname);
00119 free(aliasname);
00120 }
00121 };
00122
00123
00124
00125
00126
00127 class odlInverse;
00128 class odlImplementation;
00129 class odlIndex;
00130 class odlCardinality;
00131 class odlMagOrder;
00132 class odlImplementation;
00133 class odlExecSpec;
00134 class odlDeclItem;
00135 class odlMethodSpec;
00136 class odlTriggerSpec;
00137 class odlQuotedSeq;
00138 class odlArgSpec;
00139 class odlAgregatClass;
00140 class odlEnumClass;
00141 class odlAttrComponent;
00142 class odlConstraint;
00143 class odlUnique;
00144 class odlNotnull;
00145 class odlIndexImplSpec;
00146 class odlIndexImplSpecItem;
00147 class odlCollImplSpec;
00148 class odlCollImplSpecItem;
00149
00150 typedef odl_temp_link<int> odlArrayItemLink;
00151 typedef odl_temp_list<int> odlArrayList;
00152 typedef odl_temp_link<odlArgSpec *> odlArgSpecLink;
00153 typedef odl_temp_list<odlArgSpec *> odlArgSpecList;
00154 typedef odl_temp_link<odlExecSpec *> odlExecLink;
00155 typedef odl_temp_list<odlExecSpec *> odlExecList;
00156
00157 class odlUpdateHint;
00158
00159 struct odlDeclRoot {
00160 virtual odlDeclItem *asDeclItem() {return 0;}
00161 virtual odlExecSpec *asExecSpec() {return 0;}
00162 virtual odlQuotedSeq *asQuotedSeq() {return 0;}
00163 virtual odlAttrComponent *asAttrComponent() {return 0;}
00164 virtual odlConstraint *asConstraint() {return 0;}
00165 virtual odlUnique *asUnique() {return 0;}
00166 virtual odlNotnull *asNotnull() {return 0;}
00167 virtual odlIndex *asIndex() {return 0;}
00168 virtual odlCardinality *asCardinality() {return 0;}
00169 virtual odlImplementation *asImplementation() {return 0;}
00170 virtual void setUpdateHint(odlUpdateHint *) { }
00171 };
00172
00173 struct odlQuotedSeq : public odlDeclRoot {
00174
00175 char *quoted_seq;
00176
00177 odlQuotedSeq(const char *_quoted_seq) {
00178 quoted_seq = strdup(_quoted_seq);
00179 }
00180
00181 odlQuotedSeq *asQuotedSeq() {return this;}
00182
00183 ~odlQuotedSeq() {
00184 delete quoted_seq;
00185 }
00186 };
00187
00188 struct odlCollSpec {
00189 char *collname;
00190 char *typname;
00191 odlBool isref;
00192 int dim;
00193 odlCollSpec *coll_spec;
00194 odlBool isString;
00195
00196 odlCollSpec(const char *_collname, const char *_typname, odlBool _isref,
00197 int _dim) :
00198 collname(strdup(_collname)), typname(strdup(odl_get_typname(_typname))),
00199 isref(_isref), dim(_dim), coll_spec(NULL), isString(odlFalse) {}
00200
00201 odlCollSpec(int _dim) : collname(NULL),
00202 dim(_dim), typname(NULL), coll_spec(NULL), isref(odlFalse),
00203 isString(odlTrue) {}
00204
00205 odlCollSpec(const char *_collname, odlCollSpec *_coll_spec, odlBool _isref,
00206 int _dim) :
00207 collname(strdup(_collname)), typname(NULL),
00208 coll_spec(_coll_spec), isref(_isref), dim(_dim), isString(odlFalse) {}
00209
00210 ~odlCollSpec() {
00211 free(collname);
00212 free(typname);
00213 }
00214 };
00215
00216 struct odlUpdateHint {
00217
00218 enum Type {
00219 UNDEFINED,
00220 Remove,
00221 RenameFrom,
00222 Convert,
00223 Extend,
00224 MigrateFrom,
00225 MigrateTo
00226 } type;
00227
00228 char *detail, *detail2, *detail3;
00229 odlUpdateHint(Type _type, const char *_detail = 0,
00230 const char *_detail2 = 0,
00231 const char *_detail3 = 0) :
00232 type(_type),
00233 detail(_detail ? strdup(_detail) : 0),
00234 detail2(_detail2 ? strdup(_detail2) : 0),
00235 detail3(_detail3 ? strdup(_detail3) : 0) { }
00236 };
00237
00238 struct odlInverse {
00239 char *classname, *attrname;
00240
00241 odlInverse(const char *_classname, const char *_attrname) {
00242 classname = (_classname ? strdup(_classname) : NULL);
00243 attrname = strdup(_attrname);
00244 }
00245
00246 ~odlInverse() {
00247 free(classname);
00248 free(attrname);
00249 }
00250 };
00251
00252 struct odlDeclItem : odlDeclRoot {
00253 char *attrname;
00254 char *typname;
00255 odlArrayList *array_list;
00256 odlInverse *inverse;
00257 odlCollSpec *coll_spec;
00258 odlBool isref;
00259 odlUpdateHint *upd_hints;
00260
00261 odlDeclItem(const char *_attrname,
00262 const char *_typname, odlBool _isref,
00263 odlArrayList *_array_list, odlInverse *_inverse) {
00264
00265 upd_hints = 0;
00266 attrname = strdup(_attrname);
00267 array_list = _array_list;
00268 inverse = _inverse;
00269
00270 if (!strcmp(_typname, "string"))
00271 {
00272 typname = strdup("char");
00273 if (!array_list)
00274 {
00275 array_list = new odlArrayList();
00276 array_list->add(-1);
00277 }
00278 else
00279 {
00280
00281
00282
00283
00284
00285 fprintf(stderr, "eyedbodl: warning attribute '%s': "
00286 "arrays of unbounded strings are not allowed.\n"
00287 "Using class 'ostring' instead of class 'string'.\n",
00288 attrname);
00289 free(typname);
00290 typname = strdup("ostring");
00291 }
00292 }
00293 else
00294 typname = strdup(odl_get_typname(_typname));
00295
00296 coll_spec = NULL;
00297 isref = _isref;
00298 }
00299
00300 odlDeclItem *asDeclItem() {return this;}
00301
00302 odlDeclItem(const char *_attrname, odlCollSpec *_coll_spec,
00303 odlBool _isref,
00304 odlArrayList *_array_list, odlInverse *_inverse) {
00305
00306 attrname = strdup(_attrname);
00307 array_list = _array_list;
00308 inverse = _inverse;
00309
00310 if (_coll_spec->isString)
00311 {
00312 typname = strdup("char");
00313 if (!array_list)
00314 array_list = new odlArrayList();
00315 else
00316 {
00317 fprintf(stderr, "eyedbodl: attribute '%s': "
00318 "array of string are not allowed: use class 'ostring'.\n", attrname);
00319 odl_error++;
00320 }
00321
00322 array_list->add(_coll_spec->dim);
00323 coll_spec = 0;
00324 }
00325 else
00326 {
00327 coll_spec = _coll_spec;
00328 typname = NULL;
00329 }
00330
00331 isref = _isref;
00332 upd_hints = 0;
00333 }
00334
00335 void setUpdateHint(odlUpdateHint *_upd_hints) {
00336 upd_hints = _upd_hints;
00337 }
00338
00339 odlBool hasInverseAttr() const;
00340
00341 ~odlDeclItem() {
00342 free(attrname);
00343 free(typname);
00344 delete array_list;
00345 }
00346 };
00347
00348 struct odlAttrComponent : public odlDeclRoot {
00349
00350 char *attrpath;
00351 odlBool propagate;
00352 odlBool isCloned;
00353
00354 odlAttrComponent(const char *_attrpath, odlBool propag) :
00355 attrpath(strdup(_attrpath)), propagate(propag), isCloned(odlFalse) {}
00356 virtual odlAttrComponent *asAttrComponent() {return this;}
00357 AttributeComponent *make(Database *, Schema *m, Class *cls,
00358 const Attribute *&);
00359 virtual AttributeComponent *make_realize(Database *, Schema *m, Class *cls, const Attribute *) = 0;
00360 virtual odlBool similar(odlAttrComponent *,
00361 const Class *, const Class *);
00362 virtual odlAttrComponent *clone() {abort(); return 0;}
00363 };
00364
00365 struct odlCollImplSpecItem {
00366 enum Type {
00367 UndefType,
00368 HashIndex,
00369 BTreeIndex,
00370 NoIndex
00371 } type;
00372 char *hints;
00373
00374 void init() {
00375 type = UndefType;
00376 hints = 0;
00377 }
00378 };
00379
00380 struct odlCollImplSpec {
00381 unsigned int item_alloc, item_cnt;
00382 odlCollImplSpecItem *items;
00383
00384 odlCollImplSpec() {
00385 item_alloc = item_cnt = 0;
00386 items = 0;
00387 }
00388
00389 void add(const odlCollImplSpecItem &item) {
00390 if (item_cnt >= item_alloc) {
00391 item_alloc += 4;
00392 items = (odlCollImplSpecItem *)realloc(items, item_alloc * sizeof(odlCollImplSpecItem));
00393 }
00394 items[item_cnt++] = item;
00395 }
00396
00397 int make_class_prologue(const char *clsname,
00398 odlCollImplSpecItem::Type &type,
00399 char *&hints) const;
00400 int make_attr_prologue(const char *attrpath,
00401 odlCollImplSpecItem::Type &type,
00402 char *&hints, const Attribute *) const;
00403 int make_prologue(Bool isclass, const char *attrpath,
00404 odlCollImplSpecItem::Type &type,
00405 char *&hints, const Attribute *) const;
00406 ~odlCollImplSpec() {
00407 free(items);
00408 }
00409 };
00410
00411 struct odlImplementation : public odlAttrComponent {
00412
00413 odlCollImplSpec *coll_impl_spec;
00414
00415 odlImplementation(const char *_attrpath, odlCollImplSpec *_coll_impl_spec,
00416 odlBool propag = odlTrue) :
00417 odlAttrComponent(_attrpath, propag), coll_impl_spec(_coll_impl_spec) {}
00418
00419 virtual odlImplementation *asImplementation() {return this;}
00420 AttributeComponent *make_realize(Database *, Schema *m, Class *cls, const Attribute *);
00421 odlBool similar(odlAttrComponent *,
00422 const Class *, const Class *);
00423 virtual odlAttrComponent *clone() {odlAttrComponent *comp = new odlImplementation(attrpath, coll_impl_spec); comp->isCloned = odlTrue; return comp;}
00424 };
00425
00426 struct odlIndexImplSpecItem {
00427 enum Type {
00428 UndefType,
00429 Hash,
00430 BTree
00431 } type;
00432 char *hints;
00433
00434 void init() {
00435 type = UndefType;
00436 hints = 0;
00437 }
00438 };
00439
00440 struct odlIndexImplSpec {
00441 unsigned int item_alloc, item_cnt;
00442 odlIndexImplSpecItem *items;
00443
00444 odlIndexImplSpec() {
00445 item_alloc = item_cnt = 0;
00446 items = 0;
00447 }
00448
00449 void add(const odlIndexImplSpecItem &item) {
00450 if (item_cnt >= item_alloc) {
00451 item_alloc += 4;
00452 items = (odlIndexImplSpecItem *)realloc(items, item_alloc * sizeof(odlIndexImplSpecItem));
00453 }
00454 items[item_cnt++] = item;
00455 }
00456
00457 int make_prologue(const char *attrpath,
00458 odlIndexImplSpecItem::Type &type,
00459 char *&hints, const Attribute *) const;
00460 ~odlIndexImplSpec() {
00461 free(items);
00462 }
00463 };
00464
00465 struct odlIndex : public odlAttrComponent {
00466 odlIndexImplSpec *index_impl_spec;
00467 odlIndexImplSpec *index_impl_spec_in;
00468
00469 odlIndex(const char *_attrpath, odlIndexImplSpec *_index_impl_spec = 0,
00470 odlBool propag = odlTrue) :
00471 odlAttrComponent(_attrpath, propag), index_impl_spec(_index_impl_spec),
00472 index_impl_spec_in(_index_impl_spec) {}
00473
00474 static Status findIndex(Schema *m, Index *&idx_obj);
00475
00476 virtual void retype(odlBool isCollOrIsRef) {
00477 }
00478
00479 AttributeComponent *make_realize(Database *, Schema *m, Class *cls, const Attribute *);
00480 odlBool similar(odlAttrComponent *,
00481 const Class *, const Class *);
00482 virtual odlIndex *asIndex() {return this;}
00483 virtual odlAttrComponent *clone() {odlAttrComponent *comp = new odlIndex(attrpath, index_impl_spec); comp->isCloned = odlTrue; return comp;}
00484 };
00485
00486 struct odlConstraint : public odlAttrComponent {
00487
00488 odlConstraint(const char *_attrpath, odlBool propag) :
00489 odlAttrComponent(_attrpath, propag) {}
00490 virtual odlConstraint *asConstraint() {return this;}
00491 };
00492
00493 struct odlUnique : public odlConstraint {
00494
00495 odlUnique(const char *attrpath, odlBool propag = odlTrue) :
00496 odlConstraint(attrpath, odlTrue) {}
00497 virtual odlUnique *asUnique() {return this;}
00498 AttributeComponent *make_realize(Database *, Schema *m, Class *cls, const Attribute *);
00499 odlBool similar(odlAttrComponent *,
00500 const Class *, const Class *);
00501 virtual odlAttrComponent *clone() {odlAttrComponent *comp = new odlUnique(attrpath); comp->isCloned = odlTrue; return comp;}
00502 };
00503
00504 struct odlNotnull : public odlConstraint {
00505
00506 odlNotnull(const char *attrpath, odlBool propag = odlTrue) :
00507 odlConstraint(attrpath, propag) {}
00508 virtual odlNotnull *asNotnull() {return this;}
00509 AttributeComponent *make_realize(Database *, Schema *m, Class *cls, const Attribute *);
00510 odlBool similar(odlAttrComponent *,
00511 const Class *, const Class *);
00512 virtual odlAttrComponent *clone() {odlAttrComponent *comp = new odlNotnull(attrpath); comp->isCloned = odlTrue; return comp;}
00513 };
00514
00515 struct odlCardinality : public odlAttrComponent {
00516 int bottom;
00517 odlBool bottom_excl;
00518 int top;
00519 odlBool top_excl;
00520
00521 odlCardinality(int _bottom, odlBool _bottom_excl,
00522 int _top, odlBool _top_excl) :
00523 odlAttrComponent("", odlTrue),
00524 bottom(_bottom), bottom_excl(_bottom_excl),
00525 top(_top), top_excl(_top_excl)
00526 { }
00527
00528 AttributeComponent *make_realize(Database *, Schema *m, Class *cls, const Attribute *);
00529 odlBool similar(odlAttrComponent *,
00530 const Class *, const Class *);
00531 virtual odlAttrComponent *clone() {odlAttrComponent *comp = new odlCardinality(bottom, bottom_excl, top, top_excl); comp->isCloned = odlTrue; return comp;}
00532 virtual odlCardinality *asCardinality() {return this;}
00533 };
00534
00535 struct odlExecSpec : public odlDeclRoot {
00536 odlUpdateHint *upd_hints;
00537
00538 odlExecSpec() {upd_hints = 0;}
00539 virtual odlMethodSpec *asMethodSpec() {return 0;}
00540 virtual odlTriggerSpec *asTriggerSpec() {return 0;}
00541 odlExecSpec *asExecSpec() {return this;}
00542 void setUpdateHint(odlUpdateHint *_upd_hints) {
00543 upd_hints = _upd_hints;
00544 }
00545 };
00546
00547 struct odlArgSpec {
00548
00549 int inout;
00550 char *typname;
00551 char *varname;
00552
00553 odlArgSpec(int _inout, const char *_typname, const char *_varname) :
00554 inout(_inout), typname(strdup(_typname)),
00555 varname(_varname ? strdup(_varname) : NULL) {}
00556
00557 ~odlArgSpec() {
00558 free(typname);
00559 free(varname);
00560 }
00561 };
00562
00563 struct odlMethodHints {
00564 odlBool isClient;
00565 enum {
00566 ANY_HINTS,
00567 OQL_HINTS,
00568 C_HINTS,
00569 JAVA_HINTS
00570 } calledFrom;
00571 };
00572
00573 struct odlSignUserData {
00574 char **names;
00575 odlMethodHints *mth_hints;
00576 odlUpdateHint *upd_hints;
00577 odlSignUserData(char **_names) {
00578 names = _names;
00579 mth_hints = 0;
00580 upd_hints = 0;
00581 }
00582 };
00583
00584 struct odlMethodSpec : public odlExecSpec {
00585 char *rettype;
00586 char *fname;
00587 odlArgSpecList *arglist;
00588 char *extref;
00589 odlMethodHints mth_hints;
00590 odlBool isClassMethod;
00591 char *oqlSpec;
00592
00593 odlMethodSpec(const char *_rettype, const char *_fname,
00594 odlArgSpecList *_arglist)
00595 {
00596 mth_hints.isClient = odlFalse;
00597 mth_hints.calledFrom = odlMethodHints::ANY_HINTS;
00598 isClassMethod = odlFalse;
00599 rettype = strdup(_rettype);
00600 fname = strdup(_fname);
00601 arglist = _arglist;
00602 extref = 0;
00603 oqlSpec = 0;
00604 }
00605
00606 odlMethodSpec *asMethodSpec() {return this;}
00607
00608 int getParamNames(char **&typnames, char **&varnames);
00609
00610 ~odlMethodSpec() {
00611 free(rettype);
00612 free(fname);
00613 free(extref);
00614 free(oqlSpec);
00615 delete arglist;
00616 }
00617 };
00618
00619 struct odlTriggerSpec : public odlExecSpec {
00620 int light;
00621 char *name;
00622 char *localisation;
00623 char *oqlSpec;
00624 char *extref;
00625
00626 odlTriggerSpec(int _light, const char *_localisation, const char *_name)
00627 {
00628 light = _light;
00629 name = strdup(_name);
00630 localisation = strdup(_localisation);
00631 oqlSpec = 0;
00632 extref = 0;
00633 }
00634
00635 std::string makeOQLBody(const Class *cls) const;
00636
00637 odlTriggerSpec *asTriggerSpec() {return this;}
00638
00639 ~odlTriggerSpec() {
00640 free(oqlSpec);
00641 free(extref);
00642 free(name);
00643 free(localisation);
00644 }
00645 };
00646
00647 struct odlEnumItem {
00648 char *name;
00649 char *aliasname;
00650 int value;
00651 odlBool novalue;
00652
00653 odlEnumItem(const char *_name, const char *_aliasname, int _value) {
00654 name = strdup(_name);
00655 aliasname = _aliasname ? strdup(_aliasname) : 0;
00656 value = _value;
00657 novalue = odlFalse;
00658 }
00659
00660 odlEnumItem(const char *_name, const char *_aliasname, odlBool) {
00661 name = strdup(_name);
00662 aliasname = _aliasname ? strdup(_aliasname) : strdup(_name);
00663 value = 0;
00664 novalue = odlTrue;
00665 }
00666 };
00667
00668
00669 typedef odl_temp_link<odlDeclRoot *> odlDeclRootLink;
00670 typedef odl_temp_list<odlDeclRoot *> odlDeclRootList;
00671
00672 typedef odl_temp_link<odlDeclItem *> odlDeclItemLink;
00673 typedef odl_temp_list<odlDeclItem *> odlDeclList;
00674
00675 typedef odl_temp_link<odlTriggerSpec *> odlTriggerSpecLink;
00676 typedef odl_temp_list<odlTriggerSpec *> odlTriggerList;
00677
00678 typedef odl_temp_link<odlEnumItem *> odlEnumItemLink;
00679 typedef odl_temp_list<odlEnumItem *> odlEnumList;
00680
00681 extern LinkedList *odl_decl_list;
00682
00683 enum odlAgregSpec {
00684 odl_Struct,
00685 odl_Union,
00686 odl_SuperClass,
00687 odl_RootClass,
00688 odl_NativeClass,
00689 odl_Declare,
00690 odl_Remove
00691 };
00692
00693 class odlDeclaration {
00694 protected:
00695 char *name;
00696 Class *ocls;
00697 Class *cls;
00698 char *aliasname;
00699 int check(Schema *, const char *prefix);
00700
00701 public:
00702 odlDeclaration(const char *_name, const char *_aliasname) :
00703 name(_name ? strdup(_name) : 0), aliasname(_aliasname ? strdup(_aliasname) : 0) {
00704 odl_decl_list->insertObjectLast(this);
00705 ocls = NULL;
00706 }
00707 virtual int record(Database *, Schema *, const char *, const char *) = 0;
00708 virtual int realize(Database *, Schema *, const char *, const char *, Bool diff) = 0;
00709 const char *getName() const {return name;}
00710 const char *getAliasName() const {return aliasname;}
00711
00712 void addPrefix(const char *prefix) {
00713 char *s = (char *)malloc(strlen(name)+strlen(prefix)+1);
00714 strcpy(s, prefix);
00715 strcat(s, name);
00716 free(name);
00717 name = s;
00718 }
00719
00720 virtual odlAgregatClass *asAgregatClass() {return 0;}
00721 virtual odlEnumClass *asEnumClass() {return 0;}
00722 Class *getClass() {return cls;}
00723 Class *getOClass() {return ocls;}
00724 ~odlDeclaration() {free(name); free(aliasname);}
00725 };
00726
00727 extern const char *odl_rootclass;
00728
00729 class odlAgregatClass : public odlDeclaration {
00730 odlAgregSpec agrspec;
00731 char *parentname;
00732 odlDeclRootList *decl_list;
00733 Class *parent;
00734 odlCollImplSpec *coll_impl_spec;
00735 static LinkedList declared_list;
00736
00737 public:
00738 odlUpdateHint *upd_hints;
00739
00740 odlAgregatClass(odlUpdateHint *_upd_hints, odlAgregSpec _agrspec,
00741 odlClassSpec *spec, odlDeclRootList *_decl_list) :
00742 odlDeclaration(spec->classname, spec->aliasname) {
00743 upd_hints = _upd_hints;
00744 agrspec = _agrspec;
00745 parentname = (spec->parentname ? strdup(spec->parentname) :
00746 (superclass ? superclass->name : 0));
00747 coll_impl_spec = spec->coll_impl_spec;
00748 decl_list = _decl_list;
00749
00750 class_count++;
00751
00752 if (agrspec == odl_Declare)
00753 declared_list.insertObject(spec->classname);
00754
00755 if (agrspec != odl_SuperClass &&
00756 agrspec != odl_RootClass)
00757 return;
00758
00759 if (superclass)
00760 {
00761 if (superclass->agrspec == odl_RootClass)
00762 fprintf(stderr,
00763 "eyedbodl: superclass `%s' must be defined before all other classes\n", spec->classname);
00764 else
00765 fprintf(stderr,
00766 "eyedbodl: can't have 2 superclasses `%s' and `%s'\n",
00767 spec->classname, superclass->name);
00768 exit(1);
00769 }
00770
00771
00772 if (class_count > 1)
00773 {
00774 fprintf(stderr,
00775 "eyedbodl: superclass `%s' must be defined before all other classes\n", spec->classname);
00776 exit(1);
00777 }
00778
00779 if (agrspec == odl_RootClass &&
00780 decl_list && decl_list->count > 0)
00781 {
00782 fprintf(stderr,
00783 "eyedbodl: volatile superclass `%s' cannot contain any attributes\n", spec->classname);
00784 exit(1);
00785 }
00786
00787 superclass = this;
00788 }
00789
00790 odlBool hasSimilarComp(odlAttrComponent *comp, const Class *);
00791 int propagateComponents(Database *db, Schema *m);
00792 int record(Database *, Schema *, const char *, const char *);
00793 int realize(Database *db, Schema *, const char *, const char *, Bool diff);
00794 int postRealize(Database *db, Schema *, const char *);
00795 void realize(odlDeclItem *item,
00796 Schema *m, const char *prefix,
00797 int n, ClassComponent **comp,
00798 int &comp_cnt, Attribute **agr);
00799 void realize(Database *db, odlAttrComponent *comp,
00800 Schema *m, const char *prefix);
00801 void realize(Database *db, Schema *, odlExecSpec *, const char *);
00802
00803 void addComp(odlAttrComponent *comp);
00804 int preManage(Schema *m);
00805 int manageDifferences(Database *db, Schema *m, Bool diff);
00806 int manageDiffRelationShips(Database *db, Schema *m, Bool diff);
00807
00808 odlAgregSpec getAgregSpec() const {return agrspec;}
00809
00810 static int getDeclaredCount() {return declared_list.getCount();}
00811 static LinkedList &getDeclaredList() {return declared_list;}
00812
00813 virtual odlAgregatClass *asAgregatClass() {return this;}
00814
00815 ~odlAgregatClass() {
00816 free(parentname);
00817 delete decl_list;
00818 }
00819 static odlAgregatClass *superclass;
00820 static unsigned int class_count;
00821 };
00822
00823 class odlEnumClass : public odlDeclaration {
00824 odlEnumList *enum_list;
00825
00826 public:
00827
00828
00829
00830
00831
00832
00833
00834
00835 odlEnumClass(const char *_aliasname, odlEnumList *_enum_list,
00836 const char *_name) :
00837 odlDeclaration((_name ? _name : _aliasname), _aliasname) {
00838 enum_list = _enum_list;
00839 }
00840
00841 int record(Database *, Schema *, const char *, const char *);
00842 int realize(Database *, Schema *, const char *, const char *, Bool diff);
00843
00844 odlEnumClass *asEnumClass() {return this;}
00845 ~odlEnumClass() {
00846 delete enum_list;
00847 }
00848 };
00849
00850
00851
00852
00853
00854 class odlUpdateComponent;
00855 class odlAddComponent;
00856 class odlRemoveComponent;
00857
00858 class odlUpdateAttribute;
00859 class odlAddAttribute;
00860 class odlRemoveAttribute;
00861 class odlRenameAttribute;
00862 class odlConvertAttribute;
00863 class odlReorderAttribute;
00864 class odlMigrateAttribute;
00865
00866 class odlUpdateRelationship;
00867 class odlAddRelationship;
00868 class odlRemoveRelationship;
00869
00870 class odlUpdateClass;
00871 class odlAddClass;
00872 class odlRemoveClass;
00873 class odlRenameClass;
00874 class odlReparentClass;
00875 class odlConvertClass;
00876
00877 class odlUpdateEnum;
00878
00879 class odlUpdateItem {
00880
00881 public:
00882 ClassConversion *clsconv;
00883
00884 odlUpdateItem() : clsconv(0) { }
00885
00886 virtual void display() = 0;
00887 virtual void displayDiff(Database *db, const char *odlfile) = 0;
00888 virtual Status prePerform(Database *, Schema *m) {
00889 return Success;
00890 }
00891
00892 virtual Status postPerform(Database *, Schema *m) {
00893 return Success;
00894 }
00895
00896 static void initDisplay();
00897 static void initDisplayDiff(Database *, const char * = 0);
00898
00899 virtual odlUpdateComponent *asUpdateComponent() {return 0;}
00900 virtual odlAddComponent *asAddComponent() {return 0;}
00901 virtual odlRemoveComponent *asRemoveComponent() {return 0;}
00902
00903 virtual odlUpdateAttribute *asUpdateAttribute() {return 0;}
00904 virtual odlAddAttribute *asAddAttribute() {return 0;}
00905 virtual odlRemoveAttribute *asRemoveAttribute() {return 0;}
00906 virtual odlRenameAttribute *asRenameAttribute() {return 0;}
00907 virtual odlConvertAttribute *asConvertAttribute() {return 0;}
00908 virtual odlReorderAttribute *asReorderAttribute() {return 0;}
00909 virtual odlMigrateAttribute *asMigrateAttribute() {return 0;}
00910
00911 virtual odlUpdateRelationship *asUpdateRelationship() {return 0;}
00912 virtual odlAddRelationship *asAddRelationship() {return 0;}
00913 virtual odlRemoveRelationship *asRemoveRelationship() {return 0;}
00914
00915 virtual odlUpdateClass *asUpdateClass() {return 0;}
00916 virtual odlAddClass *asAddClass() {return 0;}
00917 virtual odlRemoveClass *asRemoveClass() {return 0;}
00918 virtual odlRenameClass *asRenameClass() {return 0;}
00919 virtual odlReparentClass *asReparentClass() {return 0;}
00920 virtual odlConvertClass *asConvertClass() {return 0;}
00921 };
00922
00923 class odlUpdateComponent : public odlUpdateItem {
00924
00925 private:
00926 odlBool updating;
00927 void setUpdating(Object *o) {
00928 updating = o->getOid().isValid() ? odlTrue : odlFalse;
00929 }
00930
00931 protected:
00932 void realize(Database *, Schema *);
00933
00934 public:
00935 ClassComponent *cls_comp;
00936 AttributeComponent *attr_comp;
00937
00938 odlUpdateComponent(ClassComponent *_cls_comp) :
00939 cls_comp(_cls_comp), attr_comp(0) { setUpdating(cls_comp); }
00940 odlUpdateComponent(AttributeComponent *_attr_comp) :
00941 attr_comp(_attr_comp), cls_comp(0) { setUpdating(attr_comp); }
00942 virtual void display();
00943 virtual void displayDiff(Database *db, const char *odlfile);
00944 virtual odlUpdateComponent *asUpdateComponent() {return this;}
00945 };
00946
00947 class odlAddComponent : public odlUpdateComponent {
00948
00949 public:
00950
00951 odlAddComponent(ClassComponent *);
00952 odlAddComponent(AttributeComponent *);
00953 virtual odlAddComponent *asAddComponent() {return this;}
00954 Status postPerform(Database *, Schema *);
00955 };
00956
00957 class odlRemoveComponent : public odlUpdateComponent {
00958
00959 public:
00960
00961 odlRemoveComponent(ClassComponent *);
00962 odlRemoveComponent(AttributeComponent *);
00963 virtual odlRemoveComponent *asRemoveComponent() {return this;}
00964 Status postPerform(Database *, Schema *);
00965 Status prePerform(Database *, Schema *);
00966 };
00967
00968 class odlUpdateRelationship : public odlUpdateItem {
00969
00970 public:
00971 const Attribute *item, *invitem;
00972
00973 odlUpdateRelationship(const Attribute *_item,
00974 const Attribute *_invitem) :
00975 item(_item), invitem(_invitem) { }
00976
00977 virtual odlUpdateRelationship *asUpdateRelationship() {return this;}
00978 virtual void display();
00979 virtual void displayDiff(Database *db, const char *odlfile);
00980 };
00981
00982 class odlAddRelationship : public odlUpdateRelationship {
00983
00984 public:
00985 odlAddRelationship(const Attribute *_item,
00986 const Attribute *_invitem) :
00987 odlUpdateRelationship(_item, _invitem) { }
00988
00989 virtual odlAddRelationship *asAddRelationship() {return this;}
00990 Status postPerform(Database *, Schema *);
00991 };
00992
00993 class odlRemoveRelationship : public odlUpdateRelationship {
00994
00995 public:
00996 odlRemoveRelationship(const Attribute *_item,
00997 const Attribute *_invitem) :
00998 odlUpdateRelationship(_item, _invitem) { }
00999
01000 virtual odlRemoveRelationship *asRemoveRelationship() {return this;}
01001 Status postPerform(Database *, Schema *);
01002 };
01003
01004 class odlUpdateAttribute : public odlUpdateItem {
01005
01006 Status check();
01007 Status check(Database *, const Class *);
01008 public:
01009 const Class *cls;
01010 const Attribute *item;
01011 Status initClassConv(Database *);
01012
01013 odlUpdateAttribute(const Class *_cls, const Attribute *_item) :
01014 cls(_cls), item(_item) { }
01015
01016 virtual Status postPerform(Database *, Schema *m);
01017
01018 virtual void display();
01019 virtual void displayDiff(Database *db, const char *odlfile);
01020
01021 virtual odlUpdateAttribute *asUpdateAttribute() {return this;}
01022
01023 protected:
01024 Status invalidateCollClassOid(Database *, const Class *);
01025 Status invalidateInverseOid(Database *, const Class *);
01026 Status reportExtentOid(Database *db, const Class *);
01027 };
01028
01029 class odlAddAttribute : public odlUpdateAttribute {
01030
01031 public:
01032 odlAddAttribute(const Class *_cls, const Attribute *_item) :
01033 odlUpdateAttribute(_cls, _item) { }
01034 virtual odlAddAttribute *asAddAttribute() {return this;}
01035 Status prePerform(Database *, Schema *);
01036 };
01037
01038 class odlRemoveAttribute : public odlUpdateAttribute {
01039
01040 public:
01041 odlRemoveAttribute(const Class *_cls, const Attribute *_item) :
01042 odlUpdateAttribute(_cls, _item) { }
01043 virtual odlRemoveAttribute *asRemoveAttribute() {return this;}
01044 Status prePerform(Database *, Schema *);
01045 };
01046
01047 class odlRenameAttribute : public odlUpdateAttribute {
01048
01049 public:
01050 odlUpdateHint *upd_hints;
01051 odlRenameAttribute(const Class *_cls, const Attribute *_item,
01052 odlUpdateHint *_upd_hints) :
01053 odlUpdateAttribute(_cls, _item), upd_hints(_upd_hints) { }
01054 virtual odlRenameAttribute *asRenameAttribute() {return this;}
01055 virtual void display();
01056 virtual void displayDiff(Database *db, const char *odlfile);
01057 Status prePerform(Database *, Schema *);
01058 };
01059
01060 class odlConvertAttribute : public odlUpdateAttribute {
01061
01062 public:
01063 odlUpdateHint *upd_hints;
01064 const Attribute *oitem;
01065 odlConvertAttribute(const Class *_cls, const Attribute *_oitem,
01066 const Attribute *_item, odlUpdateHint *_upd_hints) :
01067 odlUpdateAttribute(_cls, _item), oitem(_oitem), upd_hints(_upd_hints) {
01068 }
01069 virtual odlConvertAttribute *asConvertAttribute() {return this;}
01070 virtual void display();
01071 virtual void displayDiff(Database *db, const char *odlfile);
01072 Status prePerform(Database *, Schema *);
01073 Status prePerformBasic(Schema *, const Class *ncls,
01074 const Class *ocls);
01075 };
01076
01077 class odlReorderAttribute : public odlUpdateAttribute {
01078
01079 public:
01080 int oldnum, newnum;
01081 odlReorderAttribute(const Class *_cls, const Attribute *_item,
01082 int _oldnum, int _newnum) :
01083 odlUpdateAttribute(_cls, _item), oldnum(_oldnum), newnum(_newnum) { }
01084 void display();
01085 void displayDiff(Database *db, const char *odlfile);
01086 virtual odlReorderAttribute *asReorderAttribute() {return this;}
01087 Status prePerform(Database *, Schema *);
01088 };
01089
01090 class odlMigrateAttribute : public odlUpdateAttribute {
01091
01092 public:
01093 odlUpdateHint *upd_hints;
01094 odlMigrateAttribute(const Class *_cls, const Attribute *_item,
01095 odlUpdateHint *_upd_hints) :
01096 odlUpdateAttribute(_cls, _item), upd_hints(_upd_hints) { }
01097 virtual odlMigrateAttribute *asMigrateAttribute() {return this;}
01098 void display();
01099 void displayDiff(Database *db, const char *odlfile);
01100 Status prePerform(Database *, Schema *);
01101 };
01102
01103
01104 class odlUpdateClass : public odlUpdateItem {
01105
01106 public:
01107 const Class *cls;
01108 odlUpdateClass(const Class *_cls) : cls(_cls) { }
01109 virtual Status postPerform(Database *, Schema *m);
01110 void display();
01111 void displayDiff(Database *db, const char *odlfile);
01112 };
01113
01114 class odlAddClass : public odlUpdateClass {
01115
01116 public:
01117 odlAddClass(const Class *_cls) : odlUpdateClass(_cls) { }
01118 virtual odlAddClass *asAddClass() {return this;}
01119 Status prePerform(Database *, Schema *);
01120 };
01121
01122 class odlRemoveClass : public odlUpdateClass {
01123
01124 LinkedList *list;
01125 public:
01126 odlRemoveClass(Database *db, const Class *_cls, LinkedList *list);
01127 virtual odlRemoveClass *asRemoveClass() {return this;}
01128 Status prePerform(Database *, Schema *);
01129 Status postPerform(Database *, Schema *);
01130 };
01131
01132 class odlRenameClass : public odlUpdateClass {
01133
01134 public:
01135 char *name;
01136 odlRenameClass(const Class *_cls, const char *_name) :
01137 odlUpdateClass(_cls), name(strdup(_name)) { }
01138 virtual odlRenameClass *asRenameClass() {return this;}
01139 Status prePerform(Database *, Schema *);
01140 };
01141
01142 class odlReparentClass : public odlUpdateClass {
01143
01144 public:
01145 odlReparentClass(const Class *_cls) : odlUpdateClass(_cls) { }
01146 virtual odlReparentClass *asReparentClass() {return this;}
01147 Status prePerform(Database *, Schema *);
01148 };
01149
01150 class odlConvertClass : public odlUpdateClass {
01151
01152 public:
01153 odlConvertClass(const Class *_cls) : odlUpdateClass(_cls) { }
01154 virtual odlConvertClass *asConvertClass() {return this;}
01155 Status prePerform(Database *, Schema *);
01156 };
01157
01158
01159
01160
01161
01162
01163 extern int
01164 odl_generate_code(Database *, Schema *, ProgLang, LinkedList *,
01165 const char *package,
01166 const char *schname, const char *prefix,
01167 const char *db_prefix, const GenCodeHints &);
01168 extern int
01169 odl_realize(Database *, Schema *m, LinkedList *list,
01170 const char *prefix = "", const char *db_prefix = "",
01171 const char *package = "",
01172 Bool diff = False);
01173
01174 extern int
01175 odl_generate(Schema *m, const char *ofile);
01176
01177 extern void
01178 odl_prompt_init(FILE *);
01179
01180 extern void
01181 odl_prompt(const char *prompt = "> ");
01182
01183 extern void
01184 odl_skip_volatiles(Database *db, Schema *m);
01185
01186 extern LinkedList qseq_list;
01187 extern ProgLang odl_lang;
01188 extern int odl_diff;
01189 extern void odl_add_error(Status s);
01190 extern void odl_add_error(const char *fmt, ...);
01191 extern void odl_add_error(const std::string &s);
01192 extern Status odl_post_update(Database *db);
01193 extern Bool odl_dynamic_attr;
01194 extern Bool odl_system_class;
01195 extern Bool odl_rmv_undef_attrcomp;
01196 extern Bool odl_update_index;
01197 extern Bool odl_sch_rm;
01198 extern LinkedList odl_cls_rm;
01199 extern void odl_remove_component(Schema *m, ClassComponent *comp);
01200 extern void odl_add_component(Schema *m, ClassComponent *comp);
01201
01202 extern char odlMTHLIST[];
01203 extern char odlGENCOMP[];
01204 extern char odlGENCODE[];
01205 }
01206
01207 extern FILE *odlin;
01208
01209 #endif