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

DbSession.cpp

Go to the documentation of this file.
00001 //====================================================================
00002 //      DbSession handle implementation
00003 //--------------------------------------------------------------------
00004 //
00005 //      Package    : DbCnv ( 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_DBSESSION_CPP
00018 
00019 #include "GaudiDb/DbSession.h"
00020 #include "GaudiDb/DbObject.h"
00021 #include "DbDataBaseObj.h"
00022 #include "DbContainerObj.h"
00023 #include "DbFederationObj.h"
00024 #include "DbSessionObj.h"
00025 
00026 // Attach session to handle
00027 void dbHandle<DbSession>::switchPtr(_DataType* obj)  const  {
00028   if (   obj ) obj->addRef();
00029   if ( m_ptr ) m_ptr->release();
00030   m_ptr = obj;
00031   if ( m_ptr )   {
00032     setType(m_ptr->type());
00033   }
00034 }
00035 
00036 // Handle constructor
00037 dbHandle<DbSession>::dbHandle<DbSession>(unsigned char type)    {
00038   m_mode = DbOOMs::READ;
00039   setType(type);
00040 }
00041 
00042 // Copy constructor
00043 dbHandle<DbSession>::dbHandle(const dbHandle<DbSession>& copy)     
00044 : dbHandleBase<DbSession>()
00045 {
00046   *this = copy;
00047 }
00048 
00049 // Standard Destructor
00050 dbHandle<DbSession>::~dbHandle()     {
00051   switchPtr( 0 );
00052 }
00053 
00054 // Assignment operator
00055 dbHandle<DbSession>& dbHandle<DbSession>::operator=(const dbHandle<DbSession>& copy)   {
00056   switchPtr( copy.m_ptr );
00057   m_mode = copy.m_mode;
00058   setType(copy.type());
00059   return *this;
00060 }
00061 
00062 // type name of session
00063 const char* dbHandle<DbSession>::typeName()    const  {
00064   return "DbSession";
00065 }
00066 
00067 // Access Session mode
00068 DbAccessMode dbHandle<DbSession>::openMode()   const   {
00069   return m_mode;
00070 }
00071 
00072 // Open session by handle
00073 DbResult dbHandle<DbSession>::open(IOODataBase* db, IMessageSvc* msg, DbAccessMode mode)   {
00074   m_mode = mode;
00075   if ( !m_ptr )   {
00076     switchPtr(new DbSession(db, msg, type()));
00077   }
00078   return (isValid()) ? m_ptr->open(m_mode) : DbOOMs::DbError;
00079 }
00080 
00081 // Close session by handle
00082 DbResult dbHandle<DbSession>::close()   const   {
00083   if ( m_ptr )     {
00084     m_ptr->clearEntries();
00085     m_ptr->close();
00086   }
00087   switchPtr(0);
00088   m_mode = DbOOMs::NOT_OPEN;
00089   return DbOOMs::DbSuccess;
00090 }
00091 
00092 // Add federation to session
00093 DbResult dbHandle<DbSession>::add(const std::string& name, DbFederation* fed)  const   {
00094   if ( isValid() && fed )    {
00095     return m_ptr->add(name, fed);
00096   }
00097   return DbOOMs::DbError;
00098 }
00099 
00100 // Find federation in session
00101 DbFederation* dbHandle<DbSession>::find(const std::string& name)  const    {
00102   if ( isValid() )    {
00103     return m_ptr->find(name);
00104   }
00105   return 0;
00106 }
00107 
00108 // Remove federation from current session
00109 DbResult dbHandle<DbSession>::remove(DbFederation* fed)   {
00110   if ( isValid() )    {
00111     return m_ptr->remove(fed);
00112   }
00113   return DbOOMs::DbError;
00114 }
00115 
00116 // Access implementation internals
00117 IDbSession* dbHandle<DbSession>::info()   const   {
00118   if ( isValid() )    {
00119     return m_ptr->info();
00120   }
00121   return 0;
00122 }
00123 
00124 // Allow access to the database implementation
00125 IOODataBase* dbHandle<DbSession>::db()    {
00126   if ( isValid() )    {
00127     return m_ptr->db();
00128   }
00129   return 0;
00130 }
00131 
00132 // Allow access to the message service
00133 IMessageSvc* dbHandle<DbSession>::msgSvc()    {
00134   if ( isValid() )    {
00135     return m_ptr->msgSvc();
00136   }
00137   return 0;
00138 }

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