| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- File List
- File Members

# PoolDbDataConnection.cpp

Go to the documentation of this file.

    00001 // $Id: PoolDbDataConnection.cpp,v 1.4 2008/02/21 18:01:54 hmd Exp $
    00002 //====================================================================
    00003 //      PoolDbDataConnection implementation
    00004 //--------------------------------------------------------------------
    00005 //
    00006 //  Description: Implementation of the POOL data storage
    00007 //
    00008 //      Author     : M.Frank
    00009 //
    00010 //====================================================================
    00011 // $Id: PoolDbDataConnection.cpp,v 1.4 2008/02/21 18:01:54 hmd Exp $
    00012 // Framework include files
    00013 #include "GaudiPoolDb/PoolDbDataConnection.h"
    00014 #include "GaudiUtils/IIODataManager.h"
    00015 #include "StorageSvc/DbInstanceCount.h"
    00016 #include "GaudiKernel/strcasecmp.h"
    00017 #include <stdexcept>
    00018 #include <iostream>
    00019
    00020 using namespace pool;
    00021
    00022 static pool::DbInstanceCount::Counter* s_connectionCount =
    00023   pool::DbInstanceCount::getCounter(typeid(PoolDbDataConnection));
    00024
    00025 static inline bool isEqualMode(int mode, int flag)  {
    00026   return (mode&flag)==flag;
    00027 }
    00028
    00030 PoolDbDataConnection::PoolDbDataConnection(IInterface* own, const std::string& nam, int typ, int mode, DbDomain& domH)
    00031 : IDataConnection(own,nam), m_type(typ), m_mode(mode), m_domH(domH)
    00032 {
    00033   s_connectionCount->increment();
    00034   if ( typ == Gaudi::IIODataManager::FID && strncmp(nam.c_str(),"FID:",4) != 0 ) {
    00035     m_name = "FID:"+nam;
    00036   }
    00037 }
    00038
    00040 PoolDbDataConnection::~PoolDbDataConnection()         {
    00041   s_connectionCount->decrement();
    00042 }
    00043
    00045 StatusCode PoolDbDataConnection::i_connect()  {
    00046   DbAccessMode mode = (DbAccessMode)m_mode;
    00047   bool open_existing = isEqualMode(mode,pool::READ)||isEqualMode(mode,pool::UPDATE)||(1<<4);
    00048   m_dbH = DbDatabase(m_domH.find(fid()));
    00049   if ( !m_dbH.isValid() )  {
    00050     std::string true_fid;
    00051     pool::DbStatus sc = m_dbH.open(m_domH, pfn(), fid(), mode);
    00052     if ( sc.isSuccess() && open_existing )  {
    00053       m_dbH.param("FID",true_fid);
    00054       if ( fid() == pfn() ) {
    00055         m_fid = true_fid;
    00056         m_dbH.close();
    00057         sc = m_dbH.open(m_domH, pfn(), fid(), mode);
    00058       }
    00059       else if ( strcasecmp(true_fid.c_str(),fid().c_str()) != 0 )  {
    00060         m_dbH.close();
    00061         throw std::runtime_error("FID mismatch:\n\t\t\t\tFID="+
    00062                                  fid()+" (catalog) <> \n\t\t\t\t"+
    00063                                  true_fid+" (file) for PFN="+pfn());
    00064         return BAD_DATA_CONNECTION;
    00065       }
    00066     }
    00067     else if ( open_existing ) {
    00068       return BAD_DATA_CONNECTION;
    00069     }
    00070     return sc.isSuccess() ? StatusCode::SUCCESS : StatusCode::FAILURE;
    00071   }
    00072   return StatusCode::SUCCESS;
    00073 }
    00074
    00076 StatusCode PoolDbDataConnection::disconnect()  {
    00077   if ( m_dbH.isValid() )  {
    00078     m_dbH.close();
    00079     m_dbH = DbDatabase(pool::POOL_StorageType);
    00080     return StatusCode::SUCCESS;
    00081   }
    00082   return StatusCode::FAILURE;
    00083 }