Collection.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_COLLECTION_H
00026 #define _EYEDB_COLLECTION_H
00027 
00028 #define USE_VALUE_CACHE
00029 
00030 namespace eyedb {
00031 
00037   class ValueCache;
00038   class CollectionPeer;
00039   class CardinalityDescription;
00040   class IndexImpl;
00041 
00045   class Collection : public Instance {
00046 
00047     // ----------------------------------------------------------------------
00048     // Collection Interface
00049     // ----------------------------------------------------------------------
00050   public:
00051 
00052     typedef eyedblib::uint32 ItemId;
00053 
00058     int getCount() const;
00059 
00064     Bool isEmpty() const;
00065 
00070     const char *getName() const {return name;}
00071 
00076     void setName(const char *s);
00077 
00082     Status getStatus() const;
00083 
00084     static const Size defaultSize;
00085 
00092     virtual Status insert(const Value &v, Bool noDup = False);
00093 
00100     virtual Status suppress(const Value &item_value, Bool checkFirst = False);
00101 
00106     Status empty();
00107 
00108 
00116     virtual Status isIn(const Value &value, Bool &found,
00117                         Collection::ItemId *where = 0) const;
00118 
00124     Status getElements(OidArray &oid_array) const;
00125 
00132     Status getElements(ObjectPtrVector &obj_vect,
00133                        const RecMode *recmode = RecMode::NoRecurs) const;
00134 
00141     Status getElements(ObjectArray &obj_array,
00142                        const RecMode *recmode = RecMode::NoRecurs) const;
00143 
00150     Status getElements(ValueArray &value_array, Bool index = False) const;
00151 
00152 
00158     Status realize(const RecMode *recmod = RecMode::NoRecurs);
00159 
00165     Status remove(const RecMode *recmode = RecMode::NoRecurs);
00166 
00174     Status trace(FILE *fd = stdout, unsigned int flags = 0,
00175                  const RecMode *recmode = RecMode::FullRecurs) const;
00176 
00181     void setImplementation(const IndexImpl *idximpl);
00182 
00189     Status getImplementation(IndexImpl *&idximpl, Bool remote = False) const;
00190 
00199     Status getImplStats(std::string &xstats, Bool dspImpl = True,
00200                         Bool full = False, const char *indent = "");
00201 
00207     Status getImplStats(IndexStats *&stats);
00208 
00218     Status simulate(const IndexImpl &idximpl, std::string &xstats,
00219                     Bool dspImpl = True, Bool full = False,
00220                     const char *indent = "");
00221 
00228     Status simulate(const IndexImpl &idximpl, IndexStats *&stats);
00229 
00235     virtual Status setDatabase(Database *mdb);
00236 
00240     virtual void garbage();
00241 
00246     void setCardinalityConstraint(Object *card);
00247 
00252     CardinalityDescription *getCardinalityConstraint() const;
00253 
00258     Status checkCardinality() const;
00259 
00260     Status realizeCardinality();
00261 
00266     int getBottom() const;
00267 
00272     int getTop() const;
00273 
00278     virtual Collection *asCollection() {return this;}
00279 
00284     virtual const Collection *asCollection() const {return this;}
00285 
00291     Status getDefaultDataspace(const Dataspace *&dataspace) const;
00292 
00298     Status setDefaultDataspace(const Dataspace *dataspace);
00299 
00305     Status moveElements(const Dataspace *dataspace);
00306 
00307     Status getLocations(ObjectLocationArray &);
00308 
00309     Bool isLiteral() const {return is_literal;}
00310     Bool isPureLiteral() const {return is_pure_literal;}
00311     Bool isLiteralObject() const;
00312 
00313     Status setLiteralObject(bool force);
00314 
00315     virtual ~Collection();
00316 
00317     enum State {
00318       coherent = 1,
00319       added,
00320       removed,
00321       modified
00322     };
00323 
00324     // ----------------------------------------------------------------------
00325     // Collection Protected Part
00326     // ----------------------------------------------------------------------
00327   protected:
00328     eyedblib::int32 type;
00329     char *name;
00330     Bool ordered;
00331     Bool allow_dup;
00332     Bool string_coll;
00333     int bottom, top;
00334     Bool implModified;
00335 
00336     Class *coll_class;
00337     Bool isref;
00338     eyedblib::int16 dim;
00339     eyedblib::int16 item_size;
00340     Oid cl_oid;
00341 
00342     Bool locked;
00343     IndexImpl *idximpl;
00344     Oid inv_oid;
00345     eyedblib::int16 inv_item;
00346 
00347     Bool is_literal;
00348     Bool is_pure_literal;
00349     Oid literal_oid;
00350     Size idx_data_size;
00351     Data idx_data;
00352 
00353     CardinalityDescription *card;
00354     int card_bottom, card_bottom_excl, card_top, card_top_excl;
00355     Oid card_oid;
00356 
00357     Oid idx1_oid, idx2_oid;
00358     eyedbsm::Idx *idx1, *idx2; // back end only
00359     int p_items_cnt;
00360     int v_items_cnt;
00361     ValueCache *cache;
00362     Bool is_complete;
00363     void create_cache();
00364 
00365     struct ReadCache {
00366       ObjectArray *obj_arr;
00367       OidArray *oid_arr;
00368       ValueArray *val_arr;
00369     } read_cache;
00370 
00371     Status status;
00372     Data make_data(Data, Size, Bool swap = False) const;
00373     void decode(Data) const;
00374 
00375     Collection(const char *, Class * = NULL, Bool = True,
00376                const IndexImpl * = 0);
00377     Collection(const char *, Class *, int, const IndexImpl * = 0);
00378 
00379     Status check(const Oid&, const Class *, Error) const;
00380     Status check(const Oid&, Error) const;
00381     Status check(const Object*, Error) const;
00382     Status check(Data, Size, Error) const;
00383     Status check(const Value &, Error) const;
00384 
00385     Status trace_realize(FILE*, int, unsigned int, const RecMode *) const;
00386     Status trace_contents_realize(FILE*, int, unsigned int, const RecMode *) const;
00387     Status getIdxOid(Oid &idx1oid, Oid &idx2oid) const;
00388     void completeImplStats(IndexStats *stats) const;
00389 
00390     void isStringColl();
00391 
00392     Collection(const char *, Class *,
00393                const Oid&, const Oid&, int, int,
00394                int, const IndexImpl *,
00395                Object *, Bool, Bool, Data, Size);
00396     void make(const char *, Class *, Bool, const IndexImpl *);
00397     void make(const char *, Class *, int, const IndexImpl *);
00398     Status getOidElementsRealize();
00399     Status getObjElementsRealize(const RecMode * = RecMode::NoRecurs);
00400     Status getValElementsRealize(Bool index = False);
00401 
00402     // ----------------------------------------------------------------------
00403     // Collection Private Part
00404     // ----------------------------------------------------------------------
00405   private:
00406     Collection::State read_cache_state_oid, read_cache_state_object,
00407       read_cache_state_value;
00408     Bool read_cache_state_index;
00409     Bool inverse_valid;
00410     virtual Status cache_compile(Offset &, Size&, unsigned char **, const RecMode *);
00411     void _init(const IndexImpl *);
00412     Status init_idr();
00413     virtual const char *getClassName() const = 0;
00414     friend class CollectionPeer;
00415 
00416     Status codeIndexImpl(Data &, Offset &, Size &);
00417     Status setValue(Data);
00418     Status getValue(Data*) const;
00419     void cardCode(Data &, Offset &offset, Size &alloc_size);
00420     Status failedCardinality() const;
00421     Status create();
00422     Status update();
00423     Status updateLiteral();
00424     Status loadLiteral();
00425 
00426     enum {
00427       CollObject = 0,
00428       CollPureLiteral = 1,
00429       CollLiteral = 2
00430     };
00431     char codeLiteral() const;
00432     Status literalMake(Collection *o);
00433     std::string getStringType() const;
00434     Offset inv_oid_offset;
00435 
00436     // ----------------------------------------------------------------------
00437     // Collection Restricted Access (conceptually private)
00438     // ----------------------------------------------------------------------
00439   public:
00440     Collection(const Collection &);
00441     Collection& operator=(const Collection &);
00442     static Object *cardDecode(Database *, Data, Offset &);
00443     Status realizeInverse(const Oid&, int);
00444     void setInverse(const Oid&, int);
00445     void invalidateInverse() {inverse_valid = False;}
00446     void validateInverse() {inverse_valid = True;}
00447     void unvalidReadCache();
00448     void emptyReadCache();
00449     void setLiteral(Bool _is_literal);
00450     void setPureLiteral(Bool _is_pure_literal);
00451     Oid getLiteralOid() const {return literal_oid;}
00452     void setLiteralOid(Oid _literal_oid) {literal_oid = _literal_oid;}
00453     Oid& getOidC() {
00454       return is_literal ? literal_oid : oid;
00455     }
00456     const Oid& getOidC() const {
00457       return is_literal ? literal_oid : oid;
00458     }
00459 
00460     static void decodeLiteral(char c, Bool &is_literal, Bool &is_pure_literal);
00461     Bool isPartiallyStored() const;
00462     virtual Status setMasterObject(Object *_master_object);
00463     virtual Status releaseMasterObject();
00464 
00465     void makeValue(Value &);
00466 
00467     Status create_realize(const RecMode *);
00468     Status update_realize(const RecMode *);
00469     Status realizePerform(const Oid& cloid,
00470                           const Oid& objoid,
00471                           AttrIdxContext &idx_ctx,
00472                           const RecMode *);
00473     Status loadPerform(const Oid&,
00474                        LockMode lockmode,
00475                        AttrIdxContext &idx_ctx,
00476                        const RecMode* = RecMode::NoRecurs);
00477     Status removePerform(const Oid& cloid,
00478                          const Oid& objoid,
00479                          AttrIdxContext &idx_ctx,
00480                          const RecMode *);
00481     Status loadDeferred(LockMode lockmode = DefaultLock,
00482                         const RecMode * = RecMode::NoRecurs);
00483     Status postRealizePerform(const Oid& cloid,
00484                               const Oid& objoid,
00485                               AttrIdxContext &idx_ctx,
00486                               Bool&,
00487                               const RecMode *rcm);
00488     virtual Status insert_p(const Oid &item_oid, Bool noDup = False) = 0;
00489     virtual Status insert_p(const Object *o, Bool noDup = False) = 0;
00490     virtual Status insert_p(Data val, Bool noDup = False,
00491                             Size size = defaultSize) = 0;
00492     virtual Status suppress_p(const Oid &item_oid, Bool checkFirst = False);
00493     virtual Status suppress_p(const Object *item_o, Bool checkFirst = False);
00494     virtual Status suppress_p(Data data, Bool checkFirst = False,
00495                               Size size = defaultSize);
00496     virtual Status isIn_p(const Oid &item_oid, Bool &found,
00497                           Collection::ItemId *where = 0) const;
00498     virtual Status isIn_p(const Object *item_o, Bool &found,
00499                           Collection::ItemId *where = 0) const;
00500     Status isIn_p(Data data, Bool &found, Size size = defaultSize,
00501                   Collection::ItemId *where = 0) const;
00502 
00503   };
00504 
00505   class CollectionPtr : public InstancePtr {
00506 
00507   public:
00508     CollectionPtr(Collection *o = 0) : InstancePtr(o) { }
00509 
00510     Collection *getCollection() {return dynamic_cast<Collection *>(o);}
00511     const Collection *getCollection() const {return dynamic_cast<Collection *>(o);}
00512 
00513     Collection *operator->() {return dynamic_cast<Collection *>(o);}
00514     const Collection *operator->() const {return dynamic_cast<Collection *>(o);}
00515   };
00516 
00517   typedef std::vector<CollectionPtr> CollectionPtrVector;
00518 
00523 }
00524 
00525 #endif

Generated on Mon Dec 22 18:15:52 2008 for eyedb by  doxygen 1.5.3