CollBag.cc

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 #include "eyedb_p.h"
00026 #include "ValueCache.h"
00027 #include <assert.h>
00028 #include "AttrNative.h"
00029 
00030 /* CollBag */
00031 
00032 namespace eyedb {
00033 
00034   void CollBag::init()
00035   {
00036     allow_dup = True;
00037     ordered = False;
00038     type = _CollBag_Type;
00039     if (!status)
00040       setClass(CollBagClass::make(coll_class, isref, dim, status));
00041   }
00042 
00043   CollBag::CollBag(const char *n, Class *_class,
00044                    const Oid& _idx1_oid,
00045                    const Oid& _idx2_oid,
00046                    int icnt,
00047                    int _bottom, int _top,
00048                    const IndexImpl *_idximpl,
00049                    Object *_card,
00050                    Bool _is_literal,
00051                    Bool _is_pure_literal,
00052                    Data _idx_data, Size _idx_data_size)
00053     : Collection(n, _class, _idx1_oid, _idx2_oid, icnt, 
00054                  _bottom, _top, _idximpl, _card, _is_literal, _is_pure_literal, _idx_data, _idx_data_size)
00055   {
00056     init();
00057     setClass(_class);
00058   }
00059 
00060   CollBag::CollBag(const char *n, Class *mc, Bool _isref,
00061                    const IndexImpl *_idximpl) :
00062     Collection(n, mc, _isref, _idximpl)
00063   {
00064     init();
00065   }
00066 
00067   CollBag::CollBag(const char *n, Class *mc, int _dim,
00068                    const IndexImpl *_idximpl) :
00069     Collection(n, mc, _dim, _idximpl)
00070   {
00071     init();
00072   }
00073 
00074   CollBag::CollBag(Database *_db, const char *n, Class *mc,
00075                    Bool _isref, const IndexImpl *_idximpl) :
00076     Collection(n, mc, _isref, _idximpl)
00077   {
00078     init();
00079     if (!status)
00080       status = setDatabase(_db);
00081   }
00082 
00083   CollBag::CollBag(Database *_db, const char *n, Class *mc,
00084                    int _dim, const IndexImpl *_idximpl) :
00085     Collection(n, mc, _dim, _idximpl)
00086   {
00087     init();
00088     if (!status)
00089       status = setDatabase(_db);
00090   }
00091 
00092   CollBag::CollBag(const CollBag& o) : Collection(o)
00093   {
00094     allow_dup = True;
00095     ordered = False;
00096     type = _CollBag_Type;
00097   }
00098 
00099   CollBag& CollBag::operator=(const CollBag& o)
00100   {
00101     *(Collection *)this = (Collection &)o;
00102     allow_dup = True;
00103     ordered = False;
00104     type = _CollBag_Type;
00105     return *this;
00106   }
00107 
00108   const char *CollBag::getClassName() const
00109   {
00110     return CollBag_Class->getName();
00111   }
00112 
00113   Status CollBag::insert_p(const Oid& item_oid, Bool noDup)
00114   {
00115     if (status)
00116       return Exception::make(status);
00117 
00118     /*
00119       1/ on regarde si oid est present dans la cache: si oui -> return error
00120       2/ si la collection est realize'e (oid valid) on fait:
00121       collectionGetByValue() -> si found -> return error
00122       3/ on insere dans le cache avec le state `added'
00123       v_items_cnt++;
00124     */
00125 
00126     if (CollectionPeer::isLocked(this))
00127       return Exception::make(IDB_COLLECTION_LOCKED, "collection '%s' is locked for writing", name);
00128 
00129     Status s = check(item_oid, IDB_COLLECTION_INSERT_ERROR);
00130     if (s) return s;
00131 
00132     IDB_COLL_LOAD_DEFERRED();
00133     touch();
00134     if (noDup)
00135       {
00136         Bool is_in;
00137         Status s = isIn(item_oid, is_in);
00138         if (s || is_in) return s;
00139       }
00140 
00141     /*
00142       printf("CollBag::insert(%s) -> %s\n", item_oid.toString(),
00143       getOid().toString());
00144     */
00145     create_cache();
00146     //    cache->insert(item_oid, v_items_cnt, added);
00147     cache->insert(item_oid, ValueCache::DefaultItemID, added);
00148     v_items_cnt++;
00149 
00150     return Success;
00151   }
00152 
00153   Status CollBag::insert_p(const Object *item_o, Bool noDup)
00154   {
00155     if (status)
00156       return Exception::make(status);
00157 
00158     if (!isref) {
00159       Status s = check(item_o, IDB_COLLECTION_INSERT_ERROR);
00160       if (s) return s;
00161       return insert_p(item_o->getIDR() + IDB_OBJ_HEAD_SIZE, noDup);
00162     }
00163 
00164     if (CollectionPeer::isLocked(this))
00165       return Exception::make(IDB_COLLECTION_LOCKED, "collection '%s' is locked for writing", name);
00166 
00167     Status s = check(item_o, IDB_COLLECTION_INSERT_ERROR);
00168     if (s) return s;
00169 
00170     IDB_COLL_LOAD_DEFERRED();
00171     touch();
00172     if (noDup)
00173       {
00174         Bool is_in;
00175         Status s = isIn(item_o, is_in);
00176         if (s || is_in) return s;
00177       }
00178 
00179     /*
00180       printf("CollBag::insert(%s) -> %s\n", item_o->getOid().toString(),
00181       getOid().toString());
00182     */
00183 
00184     create_cache();
00185     //cache->insert(item_o, v_items_cnt, added);
00186     cache->insert(item_o, ValueCache::DefaultItemID, added);
00187     v_items_cnt++;
00188 
00189     return Success;
00190   }
00191 
00192   Status CollBag::insert_p(Data val, Bool noDup, Size size)
00193   {
00194     if (status)
00195       return Exception::make(status);
00196 
00197     if (CollectionPeer::isLocked(this))
00198       return Exception::make(IDB_COLLECTION_LOCKED, "collection '%s' is locked for writing", name);
00199 
00200     Status s = check(val, size, IDB_COLLECTION_INSERT_ERROR);
00201     if (s) return s;
00202 
00203     IDB_COLL_LOAD_DEFERRED();
00204     touch();
00205     if (noDup)
00206       {
00207         Bool is_in;
00208         Status s = isIn_p(val, is_in, size);
00209         if (s || is_in) return s;
00210       }
00211 
00212     Data item_data = make_data(val, size, True);
00213 
00214     create_cache();
00215     //    cache->insert(Value(item_data, item_size), v_items_cnt, added);
00216     cache->insert(Value(item_data, item_size), ValueCache::DefaultItemID, added);
00217 
00218     v_items_cnt++;
00219 
00220     return Success;
00221   }
00222 }

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