Dataspace.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 <assert.h>
00026 #include <eyedb_p.h>
00027 
00028 namespace eyedb {
00029 
00030   const short Dataspace::DefaultDspid = eyedbsm::DefaultDspid;
00031 
00032   bool Dataspace::isValid() const
00033   {
00034     return *getName();
00035   }
00036 
00037   Status
00038   Dataspace::remove() const
00039   {
00040     RPCStatus rpc_status = deleteDataspace(db->getDbHandle(), id);
00041     return StatusMake(rpc_status);
00042   }
00043 
00044   Status
00045   Dataspace::rename(const char *newname) const
00046   {
00047     RPCStatus rpc_status =
00048       renameDataspace(db->getDbHandle(), id, newname);
00049     return StatusMake(rpc_status);
00050   }
00051 
00052   Status
00053   Dataspace::update(const Datafile **datafiles, unsigned int datafile_cnt) const
00054   {
00055     char **datids = makeDatid(datafiles, datafile_cnt);
00056     RPCStatus rpc_status = updateDataspace(db->getDbHandle(), id, datids, datafile_cnt);
00057     freeDatid(datids, datafile_cnt);
00058     return StatusMake(rpc_status);
00059   }
00060 
00061   Status
00062   Dataspace::setCurrentDatafile(const Datafile *datafile)
00063   {
00064     RPCStatus rpc_status = dataspaceSetCurrentDatafile(db->getDbHandle(), id, datafile->getId());
00065     if (!rpc_status)
00066       cur_datafile = datafile;
00067     return StatusMake(rpc_status);
00068   }
00069 
00070   Status
00071   Dataspace::getCurrentDatafile(const Datafile *&datafile) const
00072   {
00073     if (!cur_datafile) {
00074       int datid;
00075       RPCStatus rpc_status = dataspaceGetCurrentDatafile
00076         (db->getDbHandle(), id, &datid);
00077 
00078       if (rpc_status)
00079         return StatusMake(rpc_status);
00080 
00081       for (int i = 0; i < datafile_cnt; i++)
00082         if (datafiles[i]->getId() == datid) {
00083           const_cast<Dataspace *>(this)->cur_datafile = datafiles[i];
00084           break;
00085         }
00086     }
00087 
00088     datafile = cur_datafile;
00089     return Success;
00090   }
00091 
00092   extern void display_datsize(std::ostream &, unsigned long long);
00093 
00094   std::ostream& operator<<(std::ostream& os, const Dataspace &dsp)
00095   {
00096     if (!*dsp.getName())
00097       return os;
00098 
00099     os << "Dataspace #" << dsp.getId() << '\n';
00100     os << "Name " << dsp.getName() << '\n';
00101 
00102     unsigned int cnt;
00103     const Datafile **datafiles = dsp.getDatafiles(cnt);
00104     for (int i = 0; i < cnt; i++) {
00105       const Datafile *dat = datafiles[i];
00106       os << "   Datafile #" << dat->getId() << '\n';
00107       if (*dat->getName())
00108         os << "     Name     " << dat->getName() << '\n';
00109       os << "     File     " << dat->getFile() << '\n';
00110       os << "     Maxsize  ";
00111       display_datsize(os, (eyedblib::uint64)dat->getMaxsize() * 1024);
00112       os << "     Slotsize " << dat->getSlotsize() << '\n';
00113       os << "     Oid Type " << (dat->isPhysical() ? "Physical" : "Logical") <<
00114         '\n';
00115     }
00116     return os;
00117   }
00118 
00119   char **
00120   Dataspace::makeDatid(const Datafile **datafiles,
00121                        unsigned int datafile_cnt)
00122   {
00123     char **datids = new char *[datafile_cnt];
00124     for (int i = 0; i < datafile_cnt; i++)
00125       datids[i] = strdup(str_convert((long)datafiles[i]->getId()).c_str());
00126     return datids;
00127   }
00128 
00129   void
00130   Dataspace::freeDatid(char **datids, unsigned int datafile_cnt)
00131   {
00132     for (int i = 0; i < datafile_cnt; i++)
00133       free(datids[i]);
00134 
00135     delete [] datids;
00136   }
00137 
00138   Dataspace::~Dataspace()
00139   {
00140     free(name);
00141     delete [] datafiles;
00142   }
00143 
00144 }

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