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_utility(),
00010 m_loaded( false ),
00011 m_namedRefCache(){
00012 }
00013
00014 ora::TransactionCache::~TransactionCache(){
00015 clear();
00016 }
00017
00018 void ora::TransactionCache::clear(){
00019 m_dbExists.first = false;
00020 m_dbExists.second = false;
00021 for( std::map<int, Handle<DatabaseContainer> >::iterator iCont = m_containersById.begin();
00022 iCont != m_containersById.end(); iCont++ ){
00023 iCont->second.clear();
00024 }
00025 m_utility.clear();
00026 m_containersById.clear();
00027 m_containersByName.clear();
00028 m_loaded = false;
00029 m_namedRefCache.clear();
00030 }
00031
00032 void ora::TransactionCache::setDbExists( bool exists ){
00033 m_dbExists.first = true;
00034 m_dbExists.second = exists;
00035 }
00036
00037 bool ora::TransactionCache::dbExistsLoaded(){
00038 return m_dbExists.first;
00039 }
00040
00041 bool ora::TransactionCache::dbExists(){
00042 return m_dbExists.second;
00043 }
00044
00045 void ora::TransactionCache::addContainer( int id,
00046 const std::string& name,
00047 Handle<DatabaseContainer>& contPtr ){
00048 m_containersById.insert( std::make_pair( id, contPtr ) );
00049 m_containersByName.insert( std::make_pair( name, id ) );
00050 }
00051
00052 void ora::TransactionCache::eraseContainer( int id,
00053 const std::string& name ){
00054 m_containersById.erase( id );
00055 m_containersByName.erase( name );
00056 }
00057
00058 ora::Handle<ora::DatabaseContainer> ora::TransactionCache::getContainer( int id ){
00059 Handle<DatabaseContainer> instance;
00060 std::map<int, Handle<DatabaseContainer> >::iterator iCont = m_containersById.find( id );
00061 if( iCont != m_containersById.end() ){
00062 instance = iCont->second;
00063 }
00064 return instance;
00065 }
00066
00067 ora::Handle<ora::DatabaseContainer> ora::TransactionCache::getContainer( const std::string& name ){
00068 Handle<DatabaseContainer> instance;
00069 std::map<std::string, int>::iterator iId = m_containersByName.find( name );
00070 if( iId == m_containersByName.end() ){
00071 return instance;
00072 }
00073 return getContainer( iId->second );
00074 }
00075
00076 const std::map<int,ora::Handle<ora::DatabaseContainer> >& ora::TransactionCache::containers(){
00077 return m_containersById;
00078 }
00079
00080 void ora::TransactionCache::setUtility( Handle<DatabaseUtilitySession>& utility ){
00081 m_utility = utility;
00082 }
00083
00084 ora::Handle<ora::DatabaseUtilitySession> ora::TransactionCache::utility(){
00085 return m_utility;
00086 }
00087
00088 bool ora::TransactionCache::isLoaded(){
00089 return m_loaded;
00090 }
00091
00092 void ora::TransactionCache::setLoaded(){
00093 m_loaded = true;
00094 }
00095
00096 void ora::TransactionCache::cleanUpNamedRefCache(){
00097 std::vector<std::string> namesToDelete;
00098 for( std::map<std::string,boost::weak_ptr<void> >::const_iterator iEntry = m_namedRefCache.begin();
00099 iEntry != m_namedRefCache.end(); iEntry++ ){
00100 if( iEntry->second.expired() ) namesToDelete.push_back( iEntry->first );
00101 }
00102 for( std::vector<std::string>::const_iterator iName = namesToDelete.begin();
00103 iName != namesToDelete.end(); iName++ ){
00104 m_namedRefCache.erase( *iName );
00105 }
00106 }
00107
00108 void ora::TransactionCache::setNamedReference( const std::string& name,
00109 boost::shared_ptr<void>& data ){
00110 m_namedRefCache.insert( std::make_pair( name, boost::weak_ptr<void>(data) ) );
00111 }
00112
00113 boost::shared_ptr<void> ora::TransactionCache::getNamedReference( const std::string& name ){
00114 cleanUpNamedRefCache();
00115 boost::shared_ptr<void> ret;
00116 std::map<std::string,boost::weak_ptr<void> >::const_iterator iEntry = m_namedRefCache.find( name );
00117 if( iEntry != m_namedRefCache.end() ){
00118 ret = iEntry->second.lock();
00119 }
00120 return ret;
00121 }