CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondCore/ORA/src/TransactionCache.cc

Go to the documentation of this file.
00001 #include "TransactionCache.h"
00002 #include "DatabaseContainer.h"
00003 #include "DatabaseUtilitySession.h"
00004 
00005 ora::TransactionCache::TransactionCache():
00006   m_dbExists(false,false),
00007   m_containersByName(),
00008   m_containersById(),
00009   m_dbParams(),
00010   m_utility(),
00011   m_loaded( false ),
00012   m_namedRefCache(),
00013   m_dropPermission(false,false){
00014 }
00015 
00016 ora::TransactionCache::~TransactionCache(){
00017   clear();
00018 }
00019 
00020 void ora::TransactionCache::clear(){
00021   m_dbExists.first = false;
00022   m_dbExists.second = false;
00023   for( std::map<int, Handle<DatabaseContainer> >::iterator iCont = m_containersById.begin();
00024        iCont != m_containersById.end(); iCont++ ){
00025     iCont->second.clear();
00026   }
00027   m_utility.clear();
00028   m_containersById.clear();
00029   m_containersByName.clear();
00030   m_dbParams.clear();
00031   m_loaded = false;
00032   m_namedRefCache.clear();
00033   m_dropPermission.first = false;
00034   m_dropPermission.second = false;
00035 }
00036 
00037 void ora::TransactionCache::setDbExists( bool exists ){
00038   m_dbExists.first = true;
00039   m_dbExists.second = exists;  
00040 }
00041 
00042 bool ora::TransactionCache::dbExistsLoaded(){
00043   return m_dbExists.first;  
00044 }
00045 
00046 bool ora::TransactionCache::dbExists(){
00047   return m_dbExists.second;
00048 }
00049 
00050 void ora::TransactionCache::addContainer( int id,
00051                                           const std::string& name,
00052                                           Handle<DatabaseContainer>& contPtr ){
00053   m_containersById.insert( std::make_pair( id, contPtr ) );
00054   m_containersByName.insert( std::make_pair( name, id ) );
00055 }
00056 
00057 void ora::TransactionCache::eraseContainer( int id,
00058                                             const std::string& name ){
00059   m_containersById.erase( id );
00060   m_containersByName.erase( name );
00061 }
00062       
00063 ora::Handle<ora::DatabaseContainer> ora::TransactionCache::getContainer( int id ){
00064   Handle<DatabaseContainer> instance;
00065   std::map<int, Handle<DatabaseContainer> >::iterator iCont = m_containersById.find( id );
00066   if( iCont != m_containersById.end() ){
00067     instance = iCont->second;
00068   }
00069   return instance;
00070 }
00071 
00072 ora::Handle<ora::DatabaseContainer> ora::TransactionCache::getContainer( const std::string& name ){
00073   Handle<DatabaseContainer> instance;
00074   std::map<std::string, int>::iterator iId = m_containersByName.find( name );
00075   if( iId == m_containersByName.end() ){
00076     return instance;
00077   }
00078   return getContainer( iId->second );
00079 }
00080 
00081 const std::map<int,ora::Handle<ora::DatabaseContainer> >& ora::TransactionCache::containers(){
00082   return m_containersById;  
00083 }
00084 
00085 void ora::TransactionCache::dropDatabase(){
00086   m_dbExists.second = true;
00087   m_dbExists.second = false;
00088   m_containersById.clear();
00089   m_containersByName.clear();
00090   m_dbParams.clear();
00091   m_namedRefCache.clear();  
00092   m_dropPermission.first = false;
00093   m_dropPermission.second = false;
00094 }
00095 
00096 std::map<std::string,std::string>& ora::TransactionCache::dbParams(){
00097   return m_dbParams;
00098 }
00099 
00100 void ora::TransactionCache::setUtility( Handle<DatabaseUtilitySession>& utility ){
00101   m_utility = utility;
00102 }
00103 
00104 ora::Handle<ora::DatabaseUtilitySession> ora::TransactionCache::utility(){
00105   return m_utility;
00106 }
00107 
00108 bool ora::TransactionCache::isLoaded(){
00109   return m_loaded;
00110 }
00111 
00112 void ora::TransactionCache::setLoaded(){
00113   m_loaded = true;
00114 }
00115 
00116 void ora::TransactionCache::cleanUpNamedRefCache(){
00117   std::vector<std::string> namesToDelete;
00118   for( std::map<std::string,boost::weak_ptr<void> >::const_iterator iEntry = m_namedRefCache.begin();
00119        iEntry != m_namedRefCache.end(); iEntry++ ){
00120     if( iEntry->second.expired() ) namesToDelete.push_back( iEntry->first );
00121   }
00122   for( std::vector<std::string>::const_iterator iName = namesToDelete.begin();
00123        iName != namesToDelete.end(); iName++ ){
00124     m_namedRefCache.erase( *iName );
00125   }
00126 }
00127 
00128 void ora::TransactionCache::setNamedReference( const std::string& name, 
00129                                                boost::shared_ptr<void>& data ){
00130   m_namedRefCache.insert( std::make_pair( name, boost::weak_ptr<void>(data) ) );  
00131 }
00132 
00133 boost::shared_ptr<void> ora::TransactionCache::getNamedReference( const std::string& name ){
00134   cleanUpNamedRefCache();
00135   boost::shared_ptr<void> ret;
00136   std::map<std::string,boost::weak_ptr<void> >::const_iterator iEntry = m_namedRefCache.find( name );
00137   if( iEntry != m_namedRefCache.end() ){
00138     ret = iEntry->second.lock();
00139   }
00140   return ret;
00141 }
00142 
00143 void ora::TransactionCache::setDropPermission( bool allowed ){
00144   m_dropPermission.first = true;
00145   m_dropPermission.second = allowed;
00146 }
00147 
00148 bool ora::TransactionCache::dropPermissionLoaded(){
00149   return m_dropPermission.first;
00150 }
00151 
00152 bool ora::TransactionCache::dropPermission(){
00153   return m_dropPermission.second;
00154 }