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

DbContainerObj.cpp

Go to the documentation of this file.
00001 //====================================================================
00002 //      DbContainer class implementation
00003 //--------------------------------------------------------------------
00004 //
00005 //      Package    : DbCnv ( The LHCb Offline System)
00006 //
00007 //  Description: Generic data persistency
00008 //
00009 //      Author     : M.Frank
00010 //====================================================================
00011 
00012 // Framework include files
00013 #include "GaudiKernel/System.h"
00014 #include "GaudiKernel/MsgStream.h"
00015 #include "GaudiDb/IOODataBase.h"
00016 #include "GaudiDb/DbHandle.h"
00017 #include "GaudiDb/DbTypeInfo.h"
00018 #include "GaudiDb/DbContainer.h"
00019 #include "DbContainerObj.h"
00020 
00021 // Constructor
00022 DbContainer::DbContainer(dbHandle<DbDataBase>& dbH, const std::string& name, const DbTypeInfo& info, DbAccessMode mode)   
00023 : m_info(0), m_typeInfo(info)
00024 {
00025   m_isOpen    = false;
00026   m_type      = m_typeInfo.type();
00027   m_dbOOMs    = dbH.db();
00028   m_msgSvc    = dbH.msgSvc();
00029   if ( 0 != m_dbOOMs && dbH.isValid() && m_typeInfo.name().length() > 0 )    {
00030     if ( dbH.add( name, this) )    {
00031       m_database = dbH;
00032       m_name     = name;
00033       m_mode     = mode;
00034       if ( mode & DbOOMs::UPDATE ) {
00035         m_mode |= DbOOMs::CREATE;
00036       }
00037       m_info     = m_dbOOMs->createContainer();
00038       m_database.addRef();
00039       /*
00040       MsgStream log(m_msgSvc,dbH.name());
00041       log << MSG::DEBUG
00042           << "--> Access   DbContainer  "
00043           << " Type:" << m_dbOOMs->name() 
00044           << " Mode:" << DbOOMs::accessMode(m_mode) 
00045           << "  " << m_name
00046           << endreq;
00047       */
00048       MsgStream log(m_msgSvc, dbH.name());
00049       log << MSG::DEBUG
00050           << "--> Access   DbContainer  " << DbOOMs::accessMode(m_mode) << " " << m_name
00051           << endreq;
00052       return;
00053     }
00054   }
00055   MsgStream err(m_msgSvc,System::moduleName());
00056   err << MSG::ERROR
00057       << "--> Access   DbContainer  "
00058       << " Mode:" << DbOOMs::accessMode(mode) 
00059       << "  " << name
00060       << " impossible. Cannot link to implementation."
00061       << endreq;
00062 }
00063 
00064 // Destructor
00065 DbContainer::~DbContainer()    {
00066   std::string identifier = m_database.isValid() ? m_database.name() : System::moduleName();
00067   clearEntries();
00068   if ( 0 != m_info )    {
00069     m_info->release();
00070     m_info = 0;
00071   }
00072   DbContainer* p = m_database.find(name());
00073   if ( p )   {
00074     m_database.remove ( p );
00075   }
00076   m_database.release();
00077   MsgStream log(m_msgSvc, identifier);
00078   /*
00079   std::string dbtyp((m_dbOOMs) ? m_dbOOMs->name() : "UNKNOWN");
00080   log << MSG::DEBUG
00081       << "--> Deaccess DbContainer  "
00082       << " Type:" << dbtyp
00083       << " Mode:" << DbOOMs::accessMode(m_mode) 
00084       << "  " << m_name
00085       << endreq;
00086   */
00087   log << MSG::DEBUG
00088       << "--> Deaccess DbContainer  " << DbOOMs::accessMode(m_mode) << " " << m_name
00089       << endreq;
00090 }
00091 
00092 // Retrieve container size
00093 long DbContainer::size()    const   {
00094   if ( 0 == m_info )    {
00095     std::string identifier = m_database.isValid() ? m_database.name() : System::moduleName();
00096     MsgStream log(m_msgSvc, identifier);
00097     log << MSG::ERROR
00098         << "--> Access   DbContainer::size()" 
00099         << "  " << m_name
00100         << " impossible - invalid object!"
00101         << endreq;
00102     return -1;
00103   }
00104   return m_info->size();
00105 }
00106 
00107 // Open database container
00108 DbResult DbContainer::open()    const   {
00109   if ( !m_isOpen )    {
00110     if ( 0 != m_info )    {
00111       if ( m_info->open(m_database, m_name, m_typeInfo, m_mode) )   {
00112         m_isOpen = true;
00113         return DbOOMs::DbSuccess;
00114       }
00115     }
00116     return DbOOMs::DbError;
00117   }
00118   return DbOOMs::DbSuccess;
00119 }
00120 
00121 // Close database container
00122 DbResult DbContainer::close()    const   {
00123   if ( m_isOpen )    {
00124     if ( 0 != m_info )    {
00125       //DbContainer* thisPtr = const_cast<DbContainer*>(this);
00126       //thisPtr->clearEntries();
00127       //release();
00128       if ( m_info->close() )   {
00129         m_isOpen = false;
00130         DbContainer* p = m_database.find(m_name);
00131         if ( p )   {
00132           m_database.remove ( p );
00133         }
00134         //std::cout << "internam release:" << m_name << std::endl;
00135         return DbOOMs::DbSuccess;
00136       }
00137     }
00138     return DbOOMs::DbError;
00139   }
00140   else if ( m_database.isValid() )   {
00141     DbContainer* p = m_database.find(m_name);
00142     if ( p )   {
00143       m_database.remove ( p );
00144     }
00145   }
00146   return DbOOMs::DbSuccess;
00147 }
00148 
00149 // Add entry to container
00150 DbResult DbContainer::addEntry(const dbHandle<DbObject>& objH)   {
00151   objH.setType(type());
00152   if ( m_isOpen && m_info && m_mode != DbOOMs::READ )   {
00153     if ( m_info->addEntry(objH) )   {
00154       return m_database.addType(m_name, m_typeInfo);
00155     }
00156   }
00157   return DbOOMs::DbError;
00158 }
00159 
00160 // Add entry to container
00161 DbResult DbContainer::updateEntry(const dbHandle<DbObject>& objH)   {
00162   objH.setType(type());
00163   if ( m_isOpen && m_info && m_mode != DbOOMs::READ )   {
00164     return m_info->updateEntry(objH);
00165   }
00166   return DbOOMs::DbError;
00167 }
00168 
00169 // Find entry in container
00170 DbResult DbContainer::find(const dbHandle<DbContainer>& cntH, dbHandle<DbObject>& objH, const dbHandle<DbLink>& linkH)  const {
00171   if ( m_isOpen )   {
00172     objH.setType(m_database.type());
00173     if ( m_info )   {
00174       return m_info->find(cntH, objH, linkH);
00175     }
00176   }
00177   return DbOOMs::DbError;
00178 }
00179 
00181 DbResult DbContainer::remove(dbHandle<DbObject>& element)   {
00182   if ( element.isValid() && m_isOpen )    {
00183     DbObject* it = _Base::find(element.ptr());
00184     if ( it )    {
00185       element = dbHandle<DbObject>(m_database.type());
00186       return _Base::remove(it) ? DbOOMs::DbError : DbOOMs::DbSuccess;
00187     }
00188   }
00189   return DbOOMs::DbError;
00190 }
00191 
00192 // Perform selection
00193 DbResult DbContainer::select(ISelectStatement* sel)  const   {
00194   if ( m_info )    {
00195     return m_info->select(sel);
00196   }
00197   return DbOOMs::DbError;
00198 }
00199 
00200 // Reset selection
00201 DbResult DbContainer::unselect()  const   {
00202   if ( m_info )    {
00203     return m_info->unselect();
00204   }
00205   return DbOOMs::DbError;
00206 }
00207 
00209 IDbCursor* DbContainer::makeCursor()  const  {
00210   if ( m_info )    {
00211     return m_info->makeCursor();
00212   }
00213   return 0;
00214 }

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