CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CondCore/DBCommon/src/DbScopedTransaction.cc

Go to the documentation of this file.
00001 // local includes
00002 #include "CondCore/DBCommon/interface/DbSession.h"
00003 #include "CondCore/DBCommon/interface/DbTransaction.h"
00004 #include "CondCore/DBCommon/interface/DbScopedTransaction.h"
00005 
00006 cond::DbScopedTransaction::DbScopedTransaction( cond::DbSession& session ):
00007   m_session(session),m_locallyActive(false){
00008 }
00009 
00010 cond::DbScopedTransaction::~DbScopedTransaction(){
00011   if(m_locallyActive) {
00012     m_session.transaction().rollback();
00013   }
00014 }
00015 
00016 int cond::DbScopedTransaction::start(bool readOnly){
00017   if(m_locallyActive) return -1;
00018   int ret = m_session.transaction().start( readOnly );
00019   m_locallyActive = true;
00020   return ret;
00021 }
00022 
00023 int cond::DbScopedTransaction::commit(){
00024   if(!m_locallyActive) return -1;
00025   int ret = m_session.transaction().commit();
00026   m_locallyActive = false;
00027   return ret;
00028 }
00029 
00030 bool cond::DbScopedTransaction::rollback(){
00031   if(!m_locallyActive) return false;
00032   bool ret = m_session.transaction().rollback();
00033   m_locallyActive = false;
00034   return ret;
00035 }
00036 
00037 bool cond::DbScopedTransaction::isLocallyActive() const {
00038   return m_locallyActive;
00039 }
00040 
00041 int cond::DbScopedTransaction::isActive() const {
00042   return m_session.transaction().isActive();
00043 }
00044 
00045 bool cond::DbScopedTransaction::isReadOnly() const 
00046 {
00047   return m_session.transaction().isReadOnly();
00048 }
00049