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

DbContainer.cpp

Go to the documentation of this file.
00001 //====================================================================
00002 //      DbContainer handle implementation
00003 //--------------------------------------------------------------------
00004 //
00005 //      Package    : DbCnv ( The LHCb Offline System)
00006 //
00007 //  Description: Generic data persistency
00008 //
00009 //      Author     : M.Frank
00010 //====================================================================
00011 #define DBCNV_DBCONTAINER_CPP
00012 
00013 // Framework include files
00014 #include "GaudiDb/DbHandle.h"
00015 #include "GaudiDb/DbContainer.h"
00016 #include "DbContainerObj.h"
00017 #include "DbDataBaseObj.h"
00018 
00019 dbHandle<DbContainer>::dbHandle<DbContainer> (DbContainer* copy)   {
00020   switchPtr( copy );
00021   if ( copy )   {
00022     m_name = copy->name();
00023     m_mode = copy->mode();
00024     m_type = copy->type();
00025   }
00026 }
00027 
00028 
00030 long dbHandle<DbContainer>::addRef()  const  {
00031   if ( isValid() )    {
00032     return m_ptr->addRef();
00033   }
00034   return -1;
00035 }
00036 
00038 long dbHandle<DbContainer>::release()  const  {
00039   if ( isValid() )    {
00040     long cnt = m_ptr->release();
00041     if ( 0 >= cnt )  {
00042       m_ptr = 0;
00043     }
00044     return cnt;
00045   }
00046   return -1;
00047 }
00048 
00049 // Open container from handle
00050 DbResult dbHandle<DbContainer>::open(dbHandle<DbDataBase>& dbH, const std::string& name, const DbTypeInfo& info, DbAccessMode mode)  const   {
00051   m_name = name;
00052   m_mode = mode;
00053   if ( 0 == m_ptr )   {
00054     if ( dbH.isValid() )    {
00055       if ( !(dbH.openMode() == DbOOMs::READ && m_mode != DbOOMs::READ) )    {
00056         DbContainer* q = dbH->find(m_name);
00057         if ( q )   {
00058           switchPtr( q );
00059         }
00060         else  {
00061           switchPtr( new DbContainer(dbH, m_name, info, m_mode) );
00062         }
00063         return m_ptr->open();
00064       }
00065     }
00066     return DbOOMs::DbError;
00067   }
00068   return DbOOMs::DbSuccess;
00069 }
00070 
00071 // Open container from handle in READ mode
00072 DbResult dbHandle<DbContainer>::open(dbHandle<DbDataBase>& dbH, const std::string& name)  const   {
00073   if ( dbH.isValid() )    {
00074     const DbTypeInfo* info = dbH.objType(name);
00075     if ( 0 != info )    {
00076       return open(dbH, name, *info, DbOOMs::READ);
00077     }
00078   }
00079   return DbOOMs::DbError;
00080 }
00081 
00082 void dbHandle<DbContainer>::switchPtr(_DataType* obj)  const  {
00083   if (   obj      ) obj->addRef();
00084   if ( isValid()  ) m_ptr->release();
00085   m_ptr = obj;
00086   if ( m_ptr )  {
00087     m_type = obj->type();
00088   }
00089 }
00090 
00091 
00092 dbHandle<DbDataBase> dbHandle<DbContainer>::containedIn()    const   {
00093   if ( isValid() )   {
00094     return m_ptr->database();
00095   }
00096   dbHandle<DbDataBase> dbH(type());
00097   return dbH;
00098 }
00099 
00100 long dbHandle<DbContainer>::size()   const {
00101   if ( isValid() )    {
00102     return m_ptr->size();
00103   }
00104   return 0;
00105 }
00106 
00107 DbResult dbHandle<DbContainer>::i_addEntry(const dbHandle<DbObject>& objH)  {
00108   if ( isValid() )  {
00109     return m_ptr->addEntry(objH);
00110   }
00111   return DbOOMs::DbError;
00112 }
00113 
00114 DbResult dbHandle<DbContainer>::i_updateEntry(const dbHandle<DbObject>& objH)  {
00115   if ( isValid() )  {
00116     return m_ptr->updateEntry(objH);
00117   }
00118   return DbOOMs::DbError;
00119 }
00120 
00121 dbHandle<DbObject> dbHandle<DbContainer>::find(const dbHandle<DbLink>& link)    const   {
00122   dbHandle<DbObject> objH(type());
00123   if ( isValid() )  {
00124     m_ptr->find(*this, objH, link);
00125   }
00126   return objH;
00127 }
00128 
00129 // Close container object if handle is valid
00130 DbResult dbHandle<DbContainer>::close()    const   {
00131   if ( isValid() )  {
00132     DbResult res = m_ptr->close();
00133     switchPtr(0);
00134     return res;
00135   }
00136   return DbOOMs::DbError;
00137 }
00138 
00139 // Create iterator to loop over container elements
00140 IDbCursor* dbHandle<DbContainer>::makeCursor()  const  {
00141   if ( isValid() )    {
00142     return m_ptr->makeCursor();
00143   }
00144   return 0;
00145 }
00146 
00147 // Find federation in session
00148 DbResult dbHandle<DbContainer>::remove(dbHandle<DbObject>& objH)   {
00149   if ( isValid() )    {
00150     return m_ptr->remove(objH);
00151   }
00152   return DbOOMs::DbError;
00153 }
00154 
00155 // Perform selection
00156 DbResult dbHandle<DbContainer>::select(ISelectStatement* sel)  const   {
00157   if ( isValid() )    {
00158     return m_ptr->select(sel);
00159   }
00160   return DbOOMs::DbError;
00161 }
00162 
00163 // Reset selection
00164 DbResult dbHandle<DbContainer>::unselect()  const   {
00165   if ( isValid() )    {
00166     return m_ptr->unselect();
00167   }
00168   return DbOOMs::DbError;
00169 }
00170 
00171 // Access implementation internals
00172 IDbContainer* dbHandle<DbContainer>::info()   const   {
00173   if ( isValid() )    {
00174     return m_ptr->info();
00175   }
00176   return 0;
00177 }
00178 
00179 // Allow access to the database implementation
00180 IOODataBase* dbHandle<DbContainer>::db()    {
00181   if ( isValid() )    {
00182     return m_ptr->db();
00183   }
00184   return 0;
00185 }
00186 
00187 // Allow access to the message service
00188 IMessageSvc* dbHandle<DbContainer>::msgSvc()    {
00189   if ( isValid() )    {
00190     return m_ptr->msgSvc();
00191   }
00192   return 0;
00193 }
00194 
00195 // Allow access to the type information
00196 const DbTypeInfo* dbHandle<DbContainer>::typeInfo()  const  {
00197   if ( isValid() )    {
00198     return m_ptr->typeInfo();
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