ClassPeer.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 
00027 namespace eyedb {
00028 
00029 void ClassPeer::setParent(Class *cl, const Class *parent)
00030 {
00031   cl->parent = (Class *)parent;
00032 }
00033 
00034 Status
00035 ClassPeer::makeColl(Database *db, Collection **pcoll,
00036                        Data idr, Offset offset)
00037 {
00038   if (*pcoll)
00039     return Success;
00040 
00041   GBX_SUSPEND();
00042 
00043   *pcoll = (Collection *)1; // to avoid recurs
00044 
00045   eyedbsm::Oid _oid;
00046 
00047   oid_decode(idr, &offset, &_oid);
00048 
00049   Oid colloid(_oid);
00050   Status status;
00051 
00052   status = classCollectionMake(db, colloid, pcoll);
00053 
00054   if (status)
00055     {
00056       *pcoll = 0;
00057       return status;
00058     }
00059 
00060   if (!*pcoll)
00061     return status;
00062 
00063   if (status == Success)
00064     {
00065       status = (*pcoll)->setDatabase(db);
00066       if (status)
00067         return status;
00068       ObjectPeer::setOid(*pcoll, colloid);
00069     }
00070 
00071   if (status)
00072     *pcoll = 0;
00073 
00074   return status;
00075 }
00076 
00077 Status
00078 ClassPeer::makeColls(Database *db, Class *mc,
00079                         Data idr, Bool make_extent)
00080 {
00081   Status status;
00082 
00083   if (make_extent &&
00084       (status = makeColl(db, &mc->extent, idr, IDB_CLASS_EXTENT)))
00085     return status;
00086 
00087   return makeColl(db, &mc->components, idr, IDB_CLASS_COMPONENTS);
00088 }
00089 
00090 Status
00091 ClassPeer::makeColls(Database *db, Class *mc,
00092                         Data idr, const Oid *oid)
00093 {
00094   eyedbsm::Oid _oid[IDB_CLASS_COLLS_CNT];
00095   RPCStatus rpc_status;
00096 
00097   rpc_status = dataRead(db->getDbHandle(), IDB_CLASS_EXTENT,
00098                             IDB_CLASS_COLLS_CNT*sizeof(eyedbsm::Oid),
00099                             (Data)_oid, 0, oid->getOid());
00100 
00101   if (rpc_status == RPCSuccess)
00102     {
00103       Offset offset = IDB_CLASS_COLL_START;
00104       Size alloc_size = offset + IDB_CLASS_COLLS_CNT * sizeof(eyedbsm::Oid);
00105 
00106 #ifdef E_XDR
00107       for (int i = 0; i < IDB_CLASS_COLLS_CNT; i++)
00108         buffer_code(&idr, &offset, &alloc_size,
00109                         (unsigned char *)&_oid[i], sizeof(eyedbsm::Oid));
00110 #else
00111       for (int i = 0; i < IDB_CLASS_COLLS_CNT; i++)
00112         oid_code(&idr, &offset, &alloc_size, &_oid[i]);
00113 #endif
00114 
00115       return ClassPeer::makeColls(db, mc, idr, True);
00116     }
00117 
00118   return StatusMake(rpc_status);
00119 }
00120 
00121 void ClassPeer::newObjRealize(Class *cls, Object *o)
00122 {
00123   cls->newObjRealize(o);
00124 }
00125 
00126 void ClassPeer::setMType(Class *cls,
00127                                  Class::MType m_type)
00128 {
00129   cls->m_type = m_type;
00130 }
00131 
00132 void ClassPeer::setParent(Class *cls, Class *parent)
00133 {
00134   cls->parent = parent;
00135 }
00136 
00137 }

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