CollArray.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 #define TEMP_COLL_ARRAY_READ_CACHE
00031 
00032 // 15/08/06 : does not raise an exception when itemid in retrieveAt is
00033 // out of range
00034 #define NO_EXC_WHEN_OUT_OF_RANGE
00035 
00036 /* CollArray */
00037 
00038 namespace eyedb {
00039 
00040   void CollArray::init()
00041   {
00042     allow_dup = True;
00043     ordered = True;
00044     type = _CollArray_Type;
00045 
00046     read_arr_cache = new ValueCache(this);
00047 
00048     if (!status)
00049       setClass(CollArrayClass::make(coll_class, isref, dim, status));
00050   }
00051 
00052   CollArray::CollArray(const char *n, Class *_class,
00053                        const Oid& _idx1_oid,
00054                        const Oid& _idx2_oid,
00055                        int icnt,
00056                        int _bottom, int _top,
00057                        const IndexImpl *_idximpl,
00058                        Object *_card,
00059                        Bool _is_literal,
00060                        Bool _is_pure_literal,
00061                        Data _idx_data, Size _idx_data_size)
00062     : Collection(n, _class, _idx1_oid, _idx2_oid, icnt,
00063                  _bottom, _top, _idximpl, _card, _is_literal, _is_pure_literal, _idx_data, _idx_data_size)
00064   {
00065     init();
00066     setClass(_class);
00067   }
00068 
00069   CollArray::CollArray(const char *n, Class *mc, Bool _isref,
00070                        const IndexImpl *_idximpl) :
00071     Collection(n, mc, _isref, _idximpl)
00072   {
00073     init();
00074   }
00075 
00076   CollArray::CollArray(const char *n, Class *mc, int _dim,
00077                        const IndexImpl *_idximpl) :
00078     Collection(n, mc, _dim, _idximpl)
00079   {
00080     init();
00081   }
00082 
00083   CollArray::CollArray(Database *_db, const char *n, Class *mc,
00084                        Bool _isref, const IndexImpl *_idximpl) :
00085     Collection(n, mc, _isref, _idximpl)
00086   {
00087     init();
00088     if (!status)
00089       status = setDatabase(_db);
00090   }
00091 
00092   CollArray::CollArray(Database *_db, const char *n, Class *mc,
00093                        int _dim, const IndexImpl *_idximpl ) :
00094     Collection(n, mc, _dim, _idximpl)
00095   {
00096     init();
00097     if (!status)
00098       status = setDatabase(_db);
00099   }
00100 
00101   CollArray::CollArray(const CollArray& o) : Collection(o)
00102   {
00103     allow_dup = True;
00104     ordered = True;
00105     type = _CollArray_Type;
00106 
00107     read_arr_cache = new ValueCache(this);
00108   }
00109 
00110   CollArray& CollArray::operator=(const CollArray& o)
00111   {
00112     *(Collection *)this = (Collection &)o;
00113     allow_dup = True;
00114     ordered = True;
00115     type = _CollArray_Type;
00116 
00117     delete read_arr_cache;
00118     read_arr_cache = new ValueCache(this);
00119 
00120     return *this;
00121   }
00122 
00123   const char *CollArray::getClassName() const
00124   {
00125     return CollArray_Class->getName();
00126   }
00127 
00128   Status CollArray::insert_p(const Oid &item_oid, Bool)
00129   {
00130     return Exception::make(IDB_COLLECTION_ERROR,
00131                            "cannot use non indexed insertion in an array");
00132   }
00133 
00134   Status CollArray::insert_p(const Object *, Bool)
00135   {
00136     return Exception::make(IDB_COLLECTION_ERROR,
00137                            "cannot use non indexed insertion in an array");
00138   }
00139 
00140   Status CollArray::insert_p(Data val, Bool, Size size)
00141   {
00142     return Exception::make(IDB_COLLECTION_ERROR,
00143                            "cannot use non indexed insertion in an array");
00144   }
00145 
00146   Status CollArray::insert(const Value &v, Bool)
00147   {
00148     return Exception::make(IDB_COLLECTION_ERROR,
00149                            "cannot use non indexed insertion in an array");
00150   }
00151 
00152   Status CollArray::suppress_p(const Oid &item_oid, Bool checkFirst)
00153   {
00154     if (status)
00155       return Exception::make(status);
00156 
00157     Bool found;
00158     Collection::ItemId where;
00159     Status s = isIn(item_oid, found, &where);
00160     if (s) return s;
00161     if (!found && checkFirst) return Success;
00162     return suppressAt(where);
00163   }
00164 
00165   Status CollArray::suppress_p(const Object *item_o, Bool checkFirst)
00166   {
00167     if (status)
00168       return Exception::make(status);
00169 
00170     Bool found;
00171     Collection::ItemId where;
00172     Status s = isIn(item_o, found, &where);
00173     if (s) return s;
00174     if (!found && checkFirst) return Success;
00175     return suppressAt(where);
00176   }
00177 
00178   Status CollArray::suppress(const Value &item_value, Bool checkFirst)
00179   {
00180     if (status)
00181       return Exception::make(status);
00182 
00183     Bool found;
00184     Collection::ItemId where;
00185     Status s = isIn(item_value, found, &where);
00186     if (s) return s;
00187     if (!found && checkFirst) return Success;
00188     return suppressAt(where);
00189   }
00190 
00191   Status CollArray::suppress_p(Data, Bool, Size size)
00192   {
00193     return Exception::make(IDB_COLLECTION_ERROR,
00194                            "cannot use non indexed suppression in an array");
00195   }
00196 
00197   Status CollArray::insertAt_p(Collection::ItemId id, const Oid &item_oid)
00198   {
00199     if (status)
00200       return Exception::make(status);
00201 
00202     if (CollectionPeer::isLocked(this))
00203       return Exception::make(IDB_COLLECTION_LOCKED, "collection '%s' [%s] is locked for writing", name, oid.getString());
00204 
00205     if (item_oid.isValid()) {
00206       Status s = check(item_oid, IDB_COLLECTION_INSERT_ERROR);
00207       if (s) return s;
00208     }
00209 
00210     IDB_COLL_LOAD_DEFERRED();
00211     touch();
00212     ValueItem *item;
00213 
00214     create_cache();
00215 
00216     if (item = cache->get(id))
00217       cache->suppress(item);
00218     else
00219       v_items_cnt++;
00220 
00221     cache->insert(item_oid, id, added);
00222 
00223     if (id >= top)
00224       top = id+1;
00225 
00226     return Success;
00227   }
00228 
00229   Status CollArray::insertAt_p(Collection::ItemId id, const Object *item_o)
00230   {
00231     if (status)
00232       return Exception::make(status);
00233 
00234     if (!isref) {
00235       Status s = check(item_o, IDB_COLLECTION_INSERT_ERROR);
00236       if (s) return s;
00237       if (!item_o->getIDR())
00238         return Exception::make(IDB_COLLECTION_INSERT_ERROR, "%s object IDR is not allocated", item_o->getClass()->getName());
00239       return insertAt_p(id, item_o->getIDR() + IDB_OBJ_HEAD_SIZE);
00240     }
00241 
00242     if (CollectionPeer::isLocked(this))
00243       return Exception::make(IDB_COLLECTION_LOCKED, "collection '%s' [%s] is locked for writing", name, oid.getString());
00244 
00245     if (status)
00246       return Exception::make(status);
00247 
00248     Status s = check(item_o, IDB_COLLECTION_INSERT_ERROR);
00249     if (s) return s;
00250 
00251     IDB_COLL_LOAD_DEFERRED();
00252     touch();
00253     ValueItem *item;
00254 
00255     create_cache();
00256 
00257     if (item = cache->get(id))
00258       cache->suppress(item);
00259     else
00260       v_items_cnt++;
00261 
00262     cache->insert(item_o, id, added);
00263 
00264     if (id >= top)
00265       top = id+1;
00266 
00267     return Success;
00268   }
00269 
00270   Status CollArray::insertAt_p(Collection::ItemId id, Data val, Size size)
00271   {
00272     if (status)
00273       return Exception::make(status);
00274 
00275     if (CollectionPeer::isLocked(this))
00276       return Exception::make(IDB_COLLECTION_LOCKED, "collection '%s' [%s] is locked for writing", name, oid.getString());
00277 
00278     Status s = check(val, size, IDB_COLLECTION_INSERT_ERROR);
00279     if (s) return s;
00280 
00281     IDB_COLL_LOAD_DEFERRED();
00282     touch();
00283     Data item_data = make_data(val, size, True);
00284  
00285     ValueItem *item;
00286 
00287     create_cache();
00288 
00289     if (item = cache->get(id))
00290       cache->suppress(item);
00291     else
00292       v_items_cnt++;
00293 
00294     cache->insert(Value(item_data, item_size), id, added);
00295 
00296     if (id >= top)
00297       top = id+1;
00298 
00299     return Success;
00300   }
00301 
00302   Status CollArray::insertAt(Collection::ItemId id, const Value &v)
00303   {
00304     Status s = check(v, IDB_COLLECTION_INSERT_ERROR);
00305     if (s)
00306       return s;
00307 
00308     if (v.type == Value::tObject)
00309       return insertAt_p(id, v.o);
00310 
00311     if (v.type == Value::tObjectPtr)
00312       return insertAt_p(id, v.o_ptr->getObject());
00313 
00314     if (v.type == Value::tOid)
00315       return insertAt_p(id, Oid(*v.oid));
00316 
00317     Size size;
00318     Data data = v.getData(&size);
00319 
00320     return insertAt_p(id, data, size);
00321   }
00322 
00323   Status CollArray::suppressAt(Collection::ItemId id)
00324   {
00325     if (status)
00326       return Exception::make(status);
00327 
00328     ValueItem *item;
00329     IDB_COLL_LOAD_DEFERRED();
00330     touch();
00331     if (cache && (item = cache->get(id))) {
00332       int s = item->getState();
00333       if (s == removed)
00334         return Exception::make(IDB_COLLECTION_SUPPRESS_ERROR, "item index %d is already suppressed", id);
00335       else if (s == coherent)
00336         item->setState(removed);
00337       else if (s == added) {
00338         if (isref) {
00339           cache->suppressOid(item);
00340           cache->suppressObject(item);
00341         }
00342         else
00343           cache->suppressData(item);
00344       }
00345 
00346       v_items_cnt--;
00347       if (top == id+1)
00348         top--;
00349       return Success;
00350     }
00351       
00352     int found = 0;
00353       
00354     unsigned char *item_data = (unsigned char *)malloc(item_size);
00355 
00356     if (getOidC().isValid()) {
00357       RPCStatus rpc_status;
00358       rpc_status = collectionGetByInd(db->getDbHandle(), getOidC().getOid(),
00359                                       id, &found, item_data, item_size);
00360       if (rpc_status) {
00361         free(item_data);
00362         return StatusMake(rpc_status);
00363       }
00364     }
00365 
00366     if (!found) {
00367       free(item_data);
00368       return Exception::make(IDB_COLLECTION_SUPPRESS_ERROR, "no item found at index %d in collection '%s' [%s]", id, name, oid.getString());
00369     }
00370 
00371     create_cache();
00372     if (isref) {
00373       Oid item_oid;
00374       Offset offset = 0;
00375       oid_decode(item_data, &offset, item_oid.getOid());
00376       //memcpy(&item_oid, item_data, sizeof(Oid));
00377       cache->insert(item_oid, id, removed);
00378     }
00379     else
00380       cache->insert(Value(item_data, item_size), id, removed);
00381 
00382     v_items_cnt--;
00383 
00384     free(item_data);
00385     return Success;
00386   }
00387 
00388   Status CollArray::retrieveAt(Collection::ItemId id, Oid &item_oid) const
00389   {
00390     if (status)
00391       return Exception::make(status);
00392 
00393 #ifdef NO_EXC_WHEN_OUT_OF_RANGE
00394     if (id < getBottom() || id >= getTop()) {
00395       item_oid.invalidate();
00396       return Success;
00397     }
00398 #else
00399     if (id < getBottom() || id >= getTop())
00400       return Exception::make(IDB_COLLECTION_ERROR,
00401                              "index out of range #%d for collection array",
00402                              id, oid.toString());
00403 #endif
00404     ValueItem *item;
00405 
00406     // should take read_arr_cache into account and merge cache and read_arr_cache
00407     if (cache && (item = cache->get(id))) {
00408       if (item->getState() == added) {
00409         if (item->getValue().type == Value::tOid)
00410           item_oid = *item->getValue().oid;
00411         else if (item->getValue().type == Value::tObject)
00412           item_oid = item->getValue().o->getOid();
00413         else if (item->getValue().type == Value::tObjectPtr)
00414           item_oid = item->getValue().o_ptr->getObject()->getOid();
00415         else
00416           item_oid = Oid::nullOid;
00417       }
00418       else
00419         item_oid = Oid::nullOid;
00420 
00421       decode((Data)item_oid.getOid());
00422       return Success;
00423     }
00424       
00425     if (!getOidC().isValid()) {
00426       item_oid.invalidate();
00427       return Success;
00428     }
00429 
00430     int found;
00431     RPCStatus rpc_status;
00432 
00433     rpc_status = collectionGetByInd(db->getDbHandle(), getOidC().getOid(),
00434                                         id, &found, (Data)item_oid.getOid(),
00435                                         sizeof(eyedbsm::Oid));
00436 
00437     if (rpc_status)
00438       return StatusMake(rpc_status);
00439 
00440     if (found)
00441       decode((Data)item_oid.getOid());
00442     else
00443       item_oid.invalidate();
00444 
00445     //return StatusMake(IDB_COLLECTION_IS_IN_ERROR, rpc_status);
00446     return Success;
00447   }
00448 
00449   Status CollArray::retrieveAt(Collection::ItemId id, Object* &o, const RecMode *rcm) const
00450   {
00451     if (status)
00452       return Exception::make(status);
00453 
00454 #ifdef NO_EXC_WHEN_OUT_OF_RANGE
00455     if (id < getBottom() || id >= getTop()) {
00456       o = 0;
00457       return Success;
00458     }
00459 #else
00460     if (id < getBottom() || id >= getTop())
00461       return Exception::make(IDB_COLLECTION_ERROR,
00462                              "index out of range #%d for collection array",
00463                              id, oid.toString());
00464 #endif
00465 
00466     ValueItem *item;
00467     Oid item_oid;
00468 
00469 #ifdef TEMP_COLL_ARRAY_READ_CACHE
00470     item = read_arr_cache->get(id);
00471     if (!item && cache)
00472       item = cache->get(id);
00473     if (item) {
00474 #else
00475     if (cache && (item = cache->get(id))) {
00476 #endif
00477       if (item->getState() == added) {
00478         if (item->getValue().type == Value::tObject)
00479           o = item->getValue().o;
00480         else if (item->getValue().type == Value::tObjectPtr)
00481           o = item->getValue().o_ptr->getObject();
00482         else
00483           o = 0;
00484 
00485         if (o)
00486           return Success;
00487         
00488         if (item->getValue().type == Value::tOid)
00489           item_oid = *item->getValue().oid;
00490         else
00491           item_oid = Oid::nullOid;
00492         
00493         decode((Data)item_oid.getOid());
00494 
00495         if (item_oid.isValid()) {
00496           if (db)
00497             return db->loadObject(item_oid, o, rcm);
00498           return Exception::make(IDB_COLLECTION_ERROR,
00499                                  "database is not set in collection");
00500         }
00501       }
00502       
00503       item_oid.invalidate();
00504       return Success;
00505     }
00506       
00507     int found = 0;
00508 
00509     if (getOidC().isValid()) {
00510       RPCStatus rpc_status;
00511       rpc_status = collectionGetByInd(db->getDbHandle(), getOidC().getOid(),
00512                                       id, &found, (Data)item_oid.getOid(),
00513                                       sizeof(eyedbsm::Oid));
00514 
00515       if (rpc_status)
00516         return StatusMake(rpc_status);
00517     }
00518 
00519     if (found)
00520       decode((Data)item_oid.getOid());
00521     else {
00522       o = 0;
00523       return Success;
00524     }
00525 
00526     if (db) {
00527       Status s = db->loadObject(item_oid, o, rcm);
00528 #ifdef TEMP_COLL_ARRAY_READ_CACHE
00529       if (!s && o) {
00530         read_arr_cache->insert(o, id, added);
00531         o->decrRefCount();
00532       }
00533 #endif
00534       return s;
00535     }
00536 
00537     return Exception::make(IDB_COLLECTION_ERROR,
00538                            "database is not set in collection");
00539   }
00540 
00541   Status CollArray::retrieveAt_p(Collection::ItemId id, Data data, Size size) const
00542   {
00543     if (status)
00544       return Exception::make(status);
00545 
00546 #ifdef NO_EXC_WHEN_OUT_OF_RANGE
00547     if (id < getBottom() || id >= getTop()) {
00548       memset(data, 0, size);
00549       return Success;
00550     }
00551 #else
00552     if (id < getBottom() || id >= getTop())
00553       return Exception::make(IDB_COLLECTION_ERROR,
00554                              "index out of range #%d for collection array",
00555                              id, oid.toString());
00556 #endif
00557 
00558     if (size == defaultSize)
00559       size = item_size;
00560 
00561     if (size < 0 || size > item_size)
00562       return Exception::make(IDB_COLLECTION_ERROR, "data too long for collection search");
00563 
00564     ValueItem *item;
00565 
00566     if (cache && (item = cache->get(id)) && item->getState() != removed) {
00567       memcpy(data, item->getValue().getData(), size);
00568 
00569       decode(data);
00570 
00571       return Success;
00572     }
00573       
00574     if (!getOidC().isValid()) {
00575       memset(data, 0, size);
00576       return Success;
00577     }
00578 
00579     int found;
00580       
00581     RPCStatus rpc_status;
00582 
00583     size = (size = defaultSize ? item_size : size);
00584     rpc_status = collectionGetByInd(db->getDbHandle(), getOidC().getOid(),
00585                                         id, &found, (Data)data, size);
00586   
00587     if (found)
00588       decode(data);
00589     else
00590       memset(data, 0, size);
00591 
00592     return StatusMake(IDB_COLLECTION_IS_IN_ERROR, rpc_status);
00593   }
00594 
00595   Status CollArray::retrieveAt(Collection::ItemId id, Value &v) const
00596   {
00597     if (isref) {
00598       Oid _oid;
00599       Status s = retrieveAt(id, _oid);
00600       if (!s)
00601         v.set(_oid);
00602       return s;
00603     }
00604 
00605     if (!isref && !coll_class->asBasicClass() && !coll_class->asEnumClass()) {
00606       Object *o;
00607       Status s = retrieveAt(id, o);
00608       if (!s)
00609         v.set(o);
00610       return s;
00611     }
00612 
00613     if (string_coll) {
00614       char *str = new char[item_size];
00615       Status s = retrieveAt_p(id, (Data)str, item_size);
00616       if (!s)
00617         v.set(str);
00618       delete [] str;
00619       return s;
00620     }
00621 
00622     if (coll_class->asByteClass() && dim > 1) {
00623       unsigned char *data = new unsigned char[item_size];
00624       Status s = retrieveAt_p(id, data, item_size);
00625       if (!s)
00626         v.set(data, item_size);
00627       else
00628         delete [] data;
00629       return s;
00630     }
00631 
00632     if (coll_class->asCharClass()) {
00633       char c;
00634       Status s = retrieveAt_p(id, (Data)&c, item_size);
00635       if (!s)
00636         v.set(c);
00637       return s;
00638     }
00639 
00640     if (coll_class->asInt16Class()) {
00641       eyedblib::int16 i16;
00642       Status s = retrieveAt_p(id, (Data)&i16, item_size);
00643       if (!s)
00644         v.set(i16);
00645       return s;
00646     }
00647 
00648     if (coll_class->asInt32Class()) {
00649       eyedblib::int32 i32;
00650       Status s = retrieveAt_p(id, (Data)&i32, item_size);
00651       if (!s)
00652         v.set(i32);
00653       return s;
00654     }
00655 
00656     if (coll_class->asInt64Class()) {
00657       eyedblib::int64 i64;
00658       Status s = retrieveAt_p(id, (Data)&i64, item_size);
00659       if (!s)
00660         v.set(i64);
00661       return s;
00662     }
00663 
00664     if (coll_class->asFloatClass()) {
00665       double d;
00666       Status s = retrieveAt_p(id, (Data)&d, item_size);
00667       if (!s)
00668         v.set(d);
00669       return s;
00670     }
00671 
00672     return Exception::make(IDB_COLLECTION_ERROR, "invalid collection type");
00673   }
00674 
00675   Status CollArray::append_p(const Oid &item_oid, Bool noDup)
00676   {
00677     if (status)
00678       return Exception::make(status);
00679 
00680     if (!noDup)
00681       return insertAt_p(getTop(), item_oid);
00682 
00683     Bool found;
00684     Status s = isIn_p(item_oid, found);
00685     if (found)
00686       return Success;
00687 
00688     return insertAt_p(getTop(), item_oid);
00689   }
00690 
00691   Status CollArray::append_p(const Object *item_o, Bool noDup)
00692   {
00693     if (!noDup)
00694       return insertAt_p(getTop(), item_o);
00695 
00696     Bool found;
00697     Status s = isIn(item_o, found);
00698     if (found)
00699       return Success;
00700 
00701     return insertAt_p(getTop(), item_o);
00702   }
00703 
00704   Status CollArray::append_p(Data item_val, Bool noDup, Size size)
00705   {
00706     if (status)
00707       return Exception::make(status);
00708 
00709     if (!noDup)
00710       return insertAt_p(getTop(), item_val, size);
00711 
00712     Bool found;
00713     Status s = isIn_p(item_val, found, size);
00714     if (found)
00715       return Success;
00716 
00717     return insertAt_p(getTop(), item_val, size);
00718   }
00719 
00720   Status CollArray::append(const Value &v)
00721   {
00722     return insertAt(getTop(), v);
00723     /*
00724       if (status)
00725       return Exception::make(status);
00726 
00727       if (!noDup)
00728       return insertAt(getTop(), item_val);
00729 
00730       Bool found;
00731       Status s = isIn(item_val, found);
00732       if (found)
00733       return Success;
00734 
00735       return insertAt(getTop(), item_val);
00736     */
00737   }
00738 
00739   Status
00740   CollArray::getImplStats(std::string &xstats1, std::string &xstats2,
00741                           Bool dspImpl, Bool full,
00742                           const char *indent)
00743   {
00744     if (status)
00745       return Exception::make(status);
00746 
00747     IndexStats *stats1, *stats2;
00748     Status s = getImplStats(stats1, stats2);
00749     if (s) return s;
00750     xstats1 = (stats1 ? stats1->toString(dspImpl, full, indent) : std::string(""));
00751     xstats2 = (stats2 ? stats2->toString(dspImpl, full, indent) : std::string(""));
00752     delete stats1;
00753     delete stats2;
00754     return Success;
00755   }
00756 
00757   Status
00758   CollArray::getImplStats(IndexStats *&stats1, IndexStats *&stats2)
00759   {
00760     if (status)
00761       return Exception::make(status);
00762 
00763     RPCStatus rpc_status;
00764 
00765     Oid idx1oid, idx2oid;
00766     Status s = getIdxOid(idx1oid, idx2oid);
00767     if (s) return s;
00768 
00769     stats1 = stats2 = 0;
00770     Oid idxoids[] = {idx1oid, idx2oid};
00771     IndexStats **stats[] = {&stats1, &stats2};
00772 
00773     for (int n = 0; n < sizeof(idxoids)/sizeof(idxoids[0]); n++) {
00774       Oid xoid = idxoids[n];
00775       if (xoid.isValid()) {
00776         rpc_status = collectionGetImplStats
00777           (db->getDbHandle(), idximpl->getType(),
00778            xoid.getOid(), (Data *)stats[n]);
00779         if (rpc_status) return StatusMake(rpc_status);
00780         completeImplStats(*stats[n]);
00781       }
00782     }
00783 
00784     return Success;
00785   }
00786 
00787   Status
00788   CollArray::simulate(const IndexImpl &_idximpl,
00789                       std::string &xstats1, std::string &xstats2,
00790                       Bool dspImpl, Bool full, const char *indent)
00791   {
00792     IndexStats *stats1, *stats2;
00793     Status s = simulate(_idximpl, stats1, stats2);
00794     if (s) return s;
00795     xstats1 = (stats1 ? stats1->toString(dspImpl, full, indent) : std::string(""));
00796     xstats2 = (stats2 ? stats2->toString(dspImpl, full, indent) : std::string(""));
00797     delete stats1;
00798     delete stats2;
00799     return Success;
00800   }
00801 
00802   Status
00803   CollArray::simulate(const IndexImpl &_idximpl,
00804                       IndexStats *&stats1, IndexStats *&stats2)
00805   {
00806     Oid idx1oid, idx2oid;
00807     Status s = getIdxOid(idx1oid, idx2oid);
00808     if (s) return s;
00809 
00810     stats1 = stats2 = 0;
00811     RPCStatus rpc_status;
00812     Oid idxoids[] = {idx1oid, idx2oid};
00813     IndexStats **stats[] = {&stats1, &stats2};
00814     for (int n = 0; n < sizeof(idxoids)/sizeof(idxoids[0]); n++) {
00815       Oid xoid = idxoids[n];
00816       if (xoid.isValid()) {
00817         Data data;
00818         Offset offset = 0;
00819         Size size = 0;
00820         Status s = IndexImpl::code(data, offset, size, _idximpl);
00821         if (s) return s;
00822         rpc_status =
00823           collectionSimulImplStats(db->getDbHandle(), _idximpl.getType(),
00824                                        xoid.getOid(), data, size,
00825                                        (Data *)*stats[n]);
00826         if (rpc_status)
00827           return StatusMake(rpc_status);
00828       }
00829     }
00830 
00831     return Success;
00832   }
00833 
00834   void CollArray::garbage() 
00835   {
00836     delete read_arr_cache;
00837     Collection::garbage();
00838   }
00839 }
00840 

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