CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CondCore/DBCommon/src/DbTransaction.cc

Go to the documentation of this file.
00001 // local includes
00002 #include "CondCore/DBCommon/interface/DbTransaction.h"
00003 #include "CondCore/ORA/interface/Transaction.h"
00004 // coral & pool includes
00005 #include "RelationalAccess/ISessionProxy.h"
00006 #include "RelationalAccess/ITransaction.h"
00007 
00008 cond::DbTransaction::DbTransaction( ora::Transaction& dbTrans ):
00009   m_dbTrans( dbTrans ),m_readOnly(true),m_clients(0){
00010 }
00011 
00012 cond::DbTransaction::~DbTransaction(){
00013   rollback();
00014 }
00015 
00016 int cond::DbTransaction::start(bool readOnly){
00017   if(!m_clients){
00018     m_dbTrans.start( readOnly );
00019     m_readOnly = readOnly;
00020   } else {
00021     if(readOnly != m_readOnly)
00022       return -1;
00023   }
00024   ++m_clients;
00025   return m_clients;
00026 }
00027 
00028 int cond::DbTransaction::commit(){
00029   if(!m_clients) return -1;
00030   else{
00031     --m_clients;
00032     if(m_clients == 0){
00033       m_dbTrans.commit();      
00034     }
00035   }
00036   return m_clients;
00037 }
00038 
00039 bool cond::DbTransaction::forceCommit(){
00040   bool doCommit = false;
00041   if(m_clients){
00042     m_dbTrans.commit();
00043     doCommit = true;
00044   }
00045   m_clients = 0;
00046   return doCommit;
00047 }
00048 
00049 bool cond::DbTransaction::rollback(){
00050   bool doRollBack = false;
00051   if(m_clients){
00052     m_dbTrans.rollback();
00053     doRollBack = true;
00054   }
00055   m_clients = 0;
00056   return doRollBack;
00057 }
00058 
00059 int cond::DbTransaction::isActive() const {
00060   if(!m_dbTrans.isActive()) return 0;
00061   return m_clients;
00062 }
00063 
00064 bool cond::DbTransaction::isReadOnly() const 
00065 {
00066   return m_dbTrans.isActive( true );
00067 }
00068