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

DbFederationObj.cpp

Go to the documentation of this file.
00001 //====================================================================
00002 //      DbFederation 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_DBFEDERATION_CPP
00012 
00013 // Framework include files
00014 #include "GaudiDb/DbOOMs.h"
00015 #include "GaudiDb/IOODataBase.h"
00016 #include "GaudiDb/DbFederation.h"
00017 #include "GaudiDb/DbDataBase.h"
00018 #include "GaudiDb/DbAccessObj.h"
00019 #include "GaudiDb/DbSession.h"
00020 #include "GaudiDb/DbObject.h"
00021 #include "DbFederationObj.h"
00022 #include "DbDataBaseObj.h"
00023 #include "DbContainerObj.h"
00024 
00025 // Gaudi Header files
00026 #include "GaudiKernel/System.h"
00027 #include "GaudiKernel/MsgStream.h"
00028 
00030 DbFederation::DbFederation(const dbHandle<DbSession>& sessionH, const std::string& name, DbAccessMode mode)
00031 : m_session(sessionH)
00032 {
00033   m_name    = name;
00034   m_mode    = mode;
00035   m_info    = 0;
00036   m_type    = m_session.type();
00037   m_dbOOMs  = m_session.db();
00038   m_msgSvc  = m_session.msgSvc();
00039   if ( 0 == m_dbOOMs )    {
00040     MsgStream log(m_msgSvc, m_name);
00041     log << MSG::ERROR
00042         << "--> Access   DbFederation "
00043         << " Type:" << "UNKNOWN" 
00044         << " Mode:" << DbOOMs::accessMode(m_mode) 
00045         << " impossible. Cannot link to implementation."
00046         << endreq;
00047     return;
00048   }
00049   m_info = m_dbOOMs->createFederation();
00050   DbResult res = m_session.add( m_name, this );
00051   if ( DbOOMs::DbError == res )    {
00052     MsgStream log(m_msgSvc,m_name);
00053     log << MSG::ERROR
00054         << "--> Access   DbFederation "
00055         << " Type:" << m_dbOOMs->name() 
00056         << " Mode:" << DbOOMs::accessMode(m_mode) 
00057         << " impossible. Error inserting Federation!"
00058         << endreq;
00059     return;
00060   }
00061   MsgStream log(m_msgSvc,m_name);
00062   log << MSG::INFO
00063       << "--> Access   DbFederation "
00064       << " Type:" << m_dbOOMs->name() 
00065       << " Mode:" << DbOOMs::accessMode(m_mode) 
00066       << endreq;
00067 }
00068 
00070 DbFederation::~DbFederation()  {
00071   clearEntries();
00072   if ( m_session.isValid() )    {
00073     DbFederation* p = m_session.find(m_name);
00074     if ( p )   {
00075       m_session.remove ( p );
00076     }
00077   }
00078   if ( 0 != m_info )    {
00079     m_info->release();
00080   }
00081   MsgStream log(m_msgSvc,m_name);
00082   std::string dbtyp((m_dbOOMs) ? m_dbOOMs->name() : "UNKNOWN");
00083   log << MSG::INFO
00084       << "--> Deaccess DbFederation "
00085       << " Type:" << dbtyp
00086       << " Mode:" << DbOOMs::accessMode(m_mode) 
00087       << endreq;
00088 }
00089 
00090 bool DbFederation::existsDbase( const std::string& name )   const   {
00091   return (m_info) ? m_info->existsDbase( name ) : false;
00092 }
00093 
00094 DbResult DbFederation::open()   const   {
00095   return (m_info) ? m_info->open( m_session, m_name, m_mode ) : DbOOMs::DbError;
00096 }
00097 
00098 DbResult DbFederation::closeDataBases()  const  {
00099   DbFederation* fed = const_cast<DbFederation*>(this);
00100   iterator i = fed->begin(), stop = fed->end();
00101   while ( i != stop )   {
00102     (*i)->close();
00103     i = fed->begin();
00104     stop = fed->end();
00105   }
00106   if ( m_info )    {
00107     m_info->close();
00108   }
00109   return DbOOMs::DbSuccess;
00110 }
00111 
00112 DbResult DbFederation::close()   const   {
00113   if ( m_session.isValid() )    {
00114     closeDataBases();
00115     //std::cout << "--> Close    DbFederation  " << m_name << std::endl;
00116     DbFederation* p = m_session.find(m_name);
00117     if ( p )   {
00118       m_session.remove ( p );
00119     }
00120     m_session = dbHandle<DbSession>(m_type);
00121     return DbOOMs::DbSuccess;
00122   }
00123   return DbOOMs::DbError;
00124 }

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