Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

DbDataBase.cpp

Go to the documentation of this file.
00001 //====================================================================
00002 //      DbDataBase handle implementation
00003 //--------------------------------------------------------------------
00004 //
00005 //      Package    : System ( The LHCb Offline System)
00006 //
00007 //  Description: Generic data persistency
00008 //
00009 //      Author     : M.Frank
00010 //  History    :
00011 // +---------+----------------------------------------------+---------
00012 // |    Date |                 Comment                      | Who     
00013 // +---------+----------------------------------------------+---------
00014 // | 11/07/99| Initial version                              | MF
00015 // +---------+----------------------------------------------+---------
00016 //====================================================================
00017 #define DBCNV_DBDATABASE_CPP
00018 
00019 #include "GaudiDb/DbDataBase.h"
00020 #include "GaudiDb/DbObject.h"
00021 #include "GaudiDb/DbHandle.h"
00022 #include "DbContainerObj.h"
00023 #include "DbDataBaseObj.h"
00024 
00026 dbHandle<DbDataBase>::dbHandle(DbDataBase* obj)    {
00027   switchPtr( obj );
00028   if ( m_ptr )    {
00029     m_name = m_ptr->name();
00030     m_mode = m_ptr->mode();
00031     m_type = m_ptr->type();
00032   }
00033 }
00034 
00036 long dbHandle<DbDataBase>::addRef()  const  {
00037   if ( isValid() )    {
00038     return m_ptr->addRef();
00039   }
00040   return -1;
00041 }
00042 
00043 // Decrease reference count on object; if 0, invalidate handle
00044 long dbHandle<DbDataBase>::release()  const  {
00045   if ( isValid() )    {
00046     long cnt = m_ptr->release();
00047     if ( 0 >= cnt )  {
00048       m_ptr = 0;
00049     }
00050     return cnt;
00051   }
00052   return -1;
00053 }
00054 
00055 dbHandle<DbFederation> dbHandle<DbDataBase>::containedIn()    const   {
00056   dbHandle<DbFederation> handle;
00057   return (0 == m_ptr) ? handle : m_ptr->federation();
00058 }
00059 
00060 void dbHandle<DbDataBase>::switchPtr(DbDataBase* obj)  const  {
00061   if (   obj ) obj->addRef();
00062   if ( m_ptr ) m_ptr->release();
00063   m_ptr = obj;
00064   if ( m_ptr )  {
00065     setType(obj->type());
00066   }
00067 }
00068 
00069 // Check if database exisst within scope of federation
00070 bool dbHandle<DbDataBase>::exist(const dbHandle<DbFederation>& fedH, const std::string& name)  const   {
00071   if ( fedH.isValid() )   {
00072     return fedH.existsDbase(name);
00073   }
00074   return false;
00075 }
00076 
00077 // Open database
00078 DbResult dbHandle<DbDataBase>::open(const dbHandle<DbFederation>& fedH, const std::string& name, DbAccessMode mode)  const  {
00079   if ( fedH.isValid() )   {
00080     dbHandle<DbDataBase> db = fedH.find(name);
00081     if ( !db.isValid() )   {
00082       db = new DbDataBase(fedH, name, mode);
00083       if ( DbOOMs::DbSuccess != db->open() )    {
00084         switchPtr(0);
00085         db.switchPtr(0);
00086         return DbOOMs::DbError;
00087       }
00088     }
00089     switchPtr(db.ptr());
00090     m_mode = db.openMode();
00091     m_name = name;
00092     m_type = fedH.type();
00093     return DbOOMs::DbSuccess;
00094   }
00095   return DbOOMs::DbError;
00096 }
00097 
00098 // Close database
00099 DbResult dbHandle<DbDataBase>::close()  const  {
00100   if ( isValid() )    {
00101     m_ptr->close();
00102   }
00103   switchPtr(0);  
00104   return DbOOMs::DbSuccess;
00105 }
00106 
00107 // Add federation to session
00108 DbResult dbHandle<DbDataBase>::add(const std::string& name, DbContainer* cnt)  const    {
00109   if ( isValid() && cnt )    {
00110     return m_ptr->add(name, cnt);
00111   }
00112   return DbOOMs::DbError;
00113 }
00114 
00115 // Find federation in session
00116 DbContainer* dbHandle<DbDataBase>::find(const std::string& name)  const    {
00117   if ( isValid() )    {
00118     return m_ptr->find(name);
00119   }
00120   return 0;
00121 }
00122 
00123 // Find federation in session
00124 DbResult dbHandle<DbDataBase>::remove( DbContainer* cnt)   {
00125   if ( isValid() )    {
00126     return m_ptr->remove(cnt);
00127   }
00128   return DbOOMs::DbError;
00129 }
00130 
00132 DbResult dbHandle<DbDataBase>::addType (const std::string& cntName, const DbTypeInfo& refType)   {
00133   if ( isValid() )    {
00134     return m_ptr->addType(cntName, refType);
00135   }
00136   return DbOOMs::DbError;
00137 }
00138 
00140 const DbTypeInfo* dbHandle<DbDataBase>::objType(const std::string& name) const    {
00141   if ( isValid() )    {
00142     return m_ptr->objType(name);
00143   }
00144   return 0;
00145 }
00146 
00147 // Add association link to link container
00148 DbResult dbHandle<DbDataBase>::addAssocEntry(const std::string& db, const std::string& cnt, const std::string& obj, dbHandle<DbLink>& to)   {
00149   if ( isValid() )    {
00150     return m_ptr->addAssocEntry(db, cnt, obj, to);
00151   }
00152   return DbOOMs::DbError;
00153 }
00154 
00155 // Retrieve the number of all contained object types
00156 long dbHandle<DbDataBase>::numAssocEntries()  const     {
00157   if ( isValid() )    {
00158     return m_ptr->numAssocEntries();
00159   }
00160   return -1;
00161 }
00162 
00163 // Retrieve association link from link container
00164 DbResult dbHandle<DbDataBase>::assocEntry(const dbHandle<DbLink>& which, std::string& db, std::string& cnt, std::string& obj)  const   {
00165   if ( isValid() )    {
00166     return m_ptr->assocEntry(which, db, cnt, obj);
00167   }
00168   return DbOOMs::DbError;
00169 }
00170 
00171 // Retrieve association link from link container
00172 DbResult dbHandle<DbDataBase>::assocEntry(long id, dbHandle<DbLink>& which, std::string& db, std::string& cnt, std::string& obj)  const   {
00173   if ( isValid() )    {
00174     return m_ptr->assocEntry(id, which, db, cnt, obj);
00175   }
00176   return DbOOMs::DbError;
00177 }
00178 
00179 // Access implementation internals
00180 IDbDataBase* dbHandle<DbDataBase>::info()   const   {
00181   if ( isValid() )    {
00182     return m_ptr->info();
00183   }
00184   return 0;
00185 }
00186 
00187 // Allow access to the database implementation
00188 IOODataBase* dbHandle<DbDataBase>::db()    {
00189   if ( isValid() )    {
00190     return m_ptr->db();
00191   }
00192   return 0;
00193 }
00194 
00195 // Allow access to the message service
00196 IMessageSvc* dbHandle<DbDataBase>::msgSvc()    {
00197   if ( isValid() )    {
00198     return m_ptr->msgSvc();
00199   }
00200   return 0;
00201 }

Generated at Wed Nov 21 12:22:19 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000