Schema.h

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #ifndef _EYEDB_SCHEMA_H
00026 #define _EYEDB_SCHEMA_H
00027 
00028 namespace eyedb {
00029 
00035   class SchemaHashList;
00036   class SchemaHashTable;
00037 
00038   enum ProgLang {
00039     ProgLang_C = 1,
00040     ProgLang_Java
00041   };
00042 
00046   class Schema : public Instance {
00047 
00048     // ----------------------------------------------------------------------
00049     // Schema Interface
00050     // ----------------------------------------------------------------------
00051   public:
00055     Schema();
00056 
00061     Schema(const Schema &sch);
00062 
00068     Schema& operator=(const Schema &sch);
00069 
00074     virtual Object *clone() const {return new Schema(*this);}
00075 
00080     const LinkedList *getClassList() const;
00081 
00082 
00089     Class *getClass(const Oid &poid, Bool perform_load = False);
00090 
00096     Class *getClass(const char *name);
00097 
00103     Class *getClass(int num);
00104 
00112     Status trace(FILE *fd = stdout, unsigned int flags = 0,
00113                  const RecMode *recmode = RecMode::FullRecurs) const;
00114 
00119     Status update();
00120 
00126     Status realize(const RecMode *recmode = RecMode::NoRecurs);
00127 
00132     Status storeName();
00133 
00134 
00140     Status setValue(Data data);
00141 
00147     Status getValue(Data *data) const;
00148 
00155     Status init(Database *database = NULL, Bool create = False);
00156 
00162     Status addClass(Class *mc);
00163 
00170     Status addClass_nocheck(Class *mc, Bool atall = False);
00171 
00177     Status suppressClass(Class *mc);
00178 
00193     Status generateCode(ProgLang lang,
00194                         const char *package, const char *schname,
00195                         const char *c_namespace,
00196                         const char *prefix,
00197                         const char *db_prefix,
00198                         const GenCodeHints &hints,
00199                         Bool _export,
00200                         Class *superclass,
00201                         LinkedList *incl_file_list = 0);
00202 
00209     Status complete(Bool setup, Bool force = False);
00210 
00216     Status setup(Bool reload);
00217 
00222     const char *getName() const {return name;}
00223 
00228     void setName(const char *_name);
00229 
00234     virtual void garbage();
00235 
00236     Status deferredCollRegisterRealize(DbHandle *);
00237 
00243     void deferredCollRegister(const char *clname, const eyedbsm::Oid *oid);
00244 
00249     virtual Schema *asSchema() {return this;}
00250 
00255     virtual const Schema *asSchema() const {return this;}
00256 
00257 
00263     void genODL(FILE *fd, unsigned int flags = 0) const;
00264 
00265     Class
00266     *Object_Class,
00267     
00268       *Class_Class,
00269       *BasicClass_Class,
00270       *EnumClass_Class,
00271       *AgregatClass_Class,
00272       *StructClass_Class,
00273       *UnionClass_Class,
00274     
00275       *Instance_Class,
00276       *Basic_Class,
00277       *Enum_Class,
00278       *Agregat_Class,
00279       *Struct_Class,
00280       *Union_Class,
00281       *Schema_Class,
00282       *Bool_Class,
00283     
00284       *CollectionClass_Class,
00285       *CollSetClass_Class,
00286       *CollBagClass_Class,
00287       *CollListClass_Class,
00288       *CollArrayClass_Class,
00289     
00290       *Collection_Class,
00291       *CollSet_Class,
00292       *CollBag_Class,
00293       *CollList_Class,
00294       *CollArray_Class;
00295 
00296     CharClass    *Char_Class;
00297     ByteClass    *Byte_Class;
00298     OidClass    *OidP_Class;
00299     Int16Class   *Int16_Class;
00300     Int32Class   *Int32_Class;
00301     Int64Class   *Int64_Class;
00302     FloatClass   *Float_Class;
00303 
00304     static Status displaySchemaDiff(Database *db, const char *odlfile,
00305                                     const char *package,
00306                                     const char *db_prefix = 0,
00307                                     FILE *fd = stdout,
00308                                     const char *cpp_cmd = 0,
00309                                     const char *cpp_flags = 0);
00310 
00311 #ifdef SUPPORT_CORBA
00312     static Status genIDL(Database *db, const char *odlfile,
00313                          const char *package,
00314                          const char *module,
00315                          const char *schname,
00316                          const char *prefix,
00317                          const char *db_prefix,
00318                          const char *idltarget,
00319                          const char *imdlfile,
00320                          Bool no_generic_idl,
00321                          const char *generic_idl,
00322                          Bool no_factory,
00323                          Bool imdl_synchro,
00324                          GenCodeHints *hints = 0,
00325                          Bool comments = True,
00326                          const char *cpp_cmd=0, const char *cpp_flags=0,
00327                          const char *ofile = 0);
00328 
00329     static Status genORB(const char *orb,
00330                          Database *db, const char *odlfile,
00331                          const char *package,
00332                          const char *module,
00333                          const char *schname,
00334                          const char *prefix,
00335                          const char *db_prefix,
00336                          const char *idltarget,
00337                          const char *imdlfile,
00338                          Bool no_generic_idl,
00339                          const char *generic_idl,
00340                          Bool no_factory,
00341                          Bool imdl_synchro,
00342                          GenCodeHints *hints = 0,
00343                          Bool comments = True,
00344                          const char *cpp_cmd=0, const char *cpp_flags=0);
00345 #endif
00346 
00347     static Status genC_API(Database *db, const char *odlfile,
00348                            const char *package,
00349                            const char *schname = 0,
00350                            const char *c_namespace = 0,
00351                            const char *prefix = 0,
00352                            const char *db_prefix = 0,
00353                            Bool _export = False,
00354                            GenCodeHints *hints = 0,
00355                            const char *cpp_cmd=0, const char *cpp_flags=0);
00356 
00357     static Status genJava_API(Database *db, const char *odlfile,
00358                               const char *package,
00359                               const char *schname = 0,
00360                               const char *prefix = 0,
00361                               const char *db_prefix = 0,
00362                               Bool _export = False,
00363                               GenCodeHints *hints = 0,
00364                               const char *cpp_cmd=0, const char *cpp_flags=0);
00365 
00366     static Status genODL(Database *db,
00367                          const char *odlfile,
00368                          const char *package,
00369                          const char *schname = 0,
00370                          const char *prefix = 0,
00371                          const char *db_prefix = 0,
00372                          const char *ofile = 0,
00373                          const char *cpp_cmd=0, const char *cpp_flags=0);
00374 
00375     static Status checkODL(const char *odlfile, const char *package,
00376                            const char *cpp_cmd=0, const char *cpp_flags=0);
00377 
00378     virtual ~Schema();
00379 
00380     // ----------------------------------------------------------------------
00381     // Schema Private Part
00382     // ----------------------------------------------------------------------
00383   private:
00384     LinkedList *_class;
00385 
00386     SchemaHashTable *hash;
00387     char *name;
00388     Bool reversal;
00389     int class_cnt;
00390     Class **classes;
00391 
00392     Status create();
00393     Status remove(const RecMode* = RecMode::NoRecurs);
00394     void sort_classes();
00395     void sort_realize(const Class *, LinkedList *);
00396     void postComplete();
00397 
00398     friend class BasicClass;
00399     friend class AgregatClass;
00400     friend Status
00401     schemaClassLoad(Database *, const Oid *, Object **,
00402                     const RecMode *, const ObjectHeader *);
00403     Status trace_realize(FILE*, int, unsigned int, const RecMode *) const;
00404     void class_make(Class **, int, Class *);
00405     void bool_class_make(Class **);
00406     LinkedList *deferred_list;
00407     void hashTableInvalidate();
00408 
00409     const char *generateStubs_C(Bool, Class *, const char *,
00410                                 const char *, const GenCodeHints &hints);
00411 
00412     Status generateCode_C(const char *package, const char *schname,
00413                           const char *c_namespace,
00414                           const char *prefix,
00415                           const char *db_prefix,
00416                           const GenCodeHints &,
00417                           Bool _export,
00418                           Class *,
00419                           LinkedList *incl_file_list = 0);
00420 
00421     const char *generateStubs_Java(Bool, Class *, const char *,
00422                                    const char *);
00423 
00424     Status generateCode_Java(const char *package, const char *schname,
00425                              const char *prefix,
00426                              const char *db_prefix,
00427                              const GenCodeHints &,
00428                              Bool _export,
00429                              Class *,
00430                              LinkedList *incl_file_list = 0);
00431 
00432     //Status completeIndexes();
00433 
00434     // ----------------------------------------------------------------------
00435     // Schema Restricted Access (conceptually private)
00436     // ----------------------------------------------------------------------
00437   public:
00438     void purge();
00439     void computeHashTable();
00440     void setReversal(Bool on_off);
00441     Bool isReversalSet() const;
00442     void revert(Bool rev);
00443     Status manageClassDeferred(Class *);
00444     Bool dont_delete_comps;
00445     Status checkDuplicates();
00446     Bool checkClass(const Class *cl);
00447     Status clean(Database *db);
00448   };
00449 
00450   class SchemaPtr : public InstancePtr {
00451 
00452   public:
00453     SchemaPtr(Schema *o = 0) : InstancePtr(o) { }
00454 
00455     Schema *getSchema() {return dynamic_cast<Schema *>(o);}
00456     const Schema *getSchema() const {return dynamic_cast<Schema *>(o);}
00457 
00458     Schema *operator->() {return dynamic_cast<Schema *>(o);}
00459     const Schema *operator->() const {return dynamic_cast<Schema *>(o);}
00460   };
00461 
00462   typedef std::vector<SchemaPtr> SchemaPtrVector;
00463 
00468 }
00469 
00470 #endif

Generated on Mon Dec 22 18:16:07 2008 for eyedb by  doxygen 1.5.3