ATLAS Offline Software
Loading...
Searching...
No Matches
pool::MicroSessionManager Class Reference

MicroSessionManager is a class taking care of starting sessions for a given major technology and managing the individual database connections. More...

#include <MicroSessionManager.h>

Collaboration diagram for pool::MicroSessionManager:

Public Member Functions

 MicroSessionManager (DatabaseRegistry &registry, long technology)
 Constructor.
virtual ~MicroSessionManager ()
 Destructor.
bool connect (Io::IoFlag transType, int ageLimit)
 Connects to the storage service.
DatabaseHandler * connect (Io::IoFlag transType, const std::string &fid, const std::string &pfn)
 Connects to a database.
void disconnect (DatabaseHandler *database)
 Disconnects from a database.
bool disconnectAll ()
 Disconnects from all the databases.
std::string fidForPfn (const std::string &pfn)
 Fetches the FID by trying to temporatily connect to a database.
IStorageSvc & getStorageSvc ()
 Return StorageSvc.
virtual bool attributeOfType (const std::string &attributeName, void *data, const std::type_info &typeInfo, const std::string &option)
virtual bool setAttributeOfType (const std::string &attributeName, const void *data, const std::type_info &typeInfo, const std::string &option)

Private Attributes

DatabaseRegistry & m_registry
IStorageSvc * m_storageSvc
bool m_inSession
long m_technology
std::set< DatabaseHandler * > m_databaseHandlers

Detailed Description

MicroSessionManager is a class taking care of starting sessions for a given major technology and managing the individual database connections.

Definition at line 30 of file MicroSessionManager.h.

Constructor & Destructor Documentation

◆ MicroSessionManager()

pool::MicroSessionManager::MicroSessionManager ( pool::DatabaseRegistry & registry,
long technology )

Constructor.

Definition at line 18 of file MicroSessionManager.cxx.

18 :
19 m_registry( registry ),
20 m_storageSvc( 0 ),
21 m_inSession( false ),
22 m_technology( technology ),
24{
25 m_storageSvc = createStorageSvc("StorageSvc");
26 if ( ! m_storageSvc ) {
27 throw std::runtime_error( "Could not create a StorageSvc object (APR: \" MicroSessionManager::MicroSessionManager \" from \" PersistencySvc \"" );
28 }
29}
std::set< DatabaseHandler * > m_databaseHandlers
IStorageSvc * createStorageSvc(const std::string &componentName)

◆ ~MicroSessionManager()

pool::MicroSessionManager::~MicroSessionManager ( )
virtual

Destructor.

Definition at line 32 of file MicroSessionManager.cxx.

33{
34 this->disconnectAll();
35 m_storageSvc->release();
36}
bool disconnectAll()
Disconnects from all the databases.

Member Function Documentation

◆ attributeOfType()

bool pool::MicroSessionManager::attributeOfType ( const std::string & attributeName,
void * data,
const std::type_info & typeInfo,
const std::string & option )
virtual

Definition at line 150 of file MicroSessionManager.cxx.

154{
155 if( !m_inSession ) {
156 return false;
157 }
158 pool::DbOption domainOption( attributeName, option );
159 if( !m_storageSvc->getDomainOption(domainOption).isSuccess() ) return false;
160 return domainOption.i_getValue(typeInfo, data).isSuccess();
161}

◆ connect() [1/2]

pool::DatabaseHandler * pool::MicroSessionManager::connect ( Io::IoFlag transType,
const std::string & fid,
const std::string & pfn )

Connects to a database.

Definition at line 50 of file MicroSessionManager.cxx.

53{
54 if( mode == Io::INVALID ) return 0;
55 if( m_databaseHandlers.empty() ) {
56 if( !m_inSession ) {
57 if( !m_storageSvc->startSession(mode, m_technology).isSuccess() ) {
58 return nullptr;
59 }
60 m_inSession = true;
61 }
62 }
63
64 pool::DatabaseHandler* db = 0;
65 try {
66 db = new pool::DatabaseHandler( *m_storageSvc, m_technology, fid, pfn, mode );
67 m_registry.registerDatabaseHandler( db );
68 m_databaseHandlers.insert( db );
69 } catch( const std::runtime_error& /* error */) {
70 delete db;
71 m_storageSvc->endSession().ignore();
72 m_inSession = false;
73 return nullptr;
74 }
75
76 if( m_databaseHandlers.empty() && m_inSession ) {
77 m_storageSvc->endSession().ignore();
78 m_inSession = false;
79 }
80 return db;
81}

◆ connect() [2/2]

bool pool::MicroSessionManager::connect ( Io::IoFlag transType,
int ageLimit )

Connects to the storage service.

Definition at line 40 of file MicroSessionManager.cxx.

41{
42 if( !m_inSession ) {
43 m_inSession = m_storageSvc->startSession(mode, m_technology, ageLimit).isSuccess();
44 }
45 return m_inSession;
46}

◆ disconnect()

void pool::MicroSessionManager::disconnect ( pool::DatabaseHandler * database)

Disconnects from a database.

Definition at line 85 of file MicroSessionManager.cxx.

86{
87 std::set< pool::DatabaseHandler* >::iterator idb = m_databaseHandlers.find( database );
88 if ( idb != m_databaseHandlers.end() ) {
89 m_registry.deregisterDatabaseHandler( *idb );
90 delete *idb;
91 m_databaseHandlers.erase( idb );
92 }
93 if( m_databaseHandlers.empty() && m_inSession ) {
94 m_storageSvc->endSession().ignore();
95 m_inSession = false;
96 }
97}

◆ disconnectAll()

bool pool::MicroSessionManager::disconnectAll ( )

Disconnects from all the databases.

Definition at line 101 of file MicroSessionManager.cxx.

102{
103 bool ret = true;
104 for ( std::set< pool::DatabaseHandler* >::iterator idb = m_databaseHandlers.begin();
105 idb != m_databaseHandlers.end(); ++idb ) {
106 m_registry.deregisterDatabaseHandler( *idb );
107 ret = (*idb)->disconnectTransaction();
108 delete *idb;
109 }
110 m_databaseHandlers.clear();
111
112 if( m_inSession ) {
113 ret = ret and m_storageSvc->endSession().isSuccess();
114 m_inSession = false;
115 }
116 return ret;
117}

◆ fidForPfn()

std::string pool::MicroSessionManager::fidForPfn ( const std::string & pfn)

Fetches the FID by trying to temporatily connect to a database.

Definition at line 120 of file MicroSessionManager.cxx.

121{
122 if ( m_databaseHandlers.empty() ) {
123 Io::IoFlag mode = Io::READ;
124 if( !m_storageSvc->startSession(mode, m_technology).isSuccess() ) {
125 return "";
126 }
127 }
128
129 std::string fid = "";
130 pool::FileDescriptor fd( pfn, pfn );
131 // this is only a temporary FID so use a special pattern to make that clear
132 fd.setFID( fd.FID().substr(0,24) + "0FF0FF0FF0FF" );
133 if( m_storageSvc->existsConnection(fd).isSuccess() ) {
134 if ( m_storageSvc->connect(Io::READ, fd).isSuccess() ) {
135 DbDatabase dbH( fd.dbc()->handle() );
136 if ( ! dbH.param( "FID", fid ).isSuccess() ) fid = "";
137 m_storageSvc->disconnect( fd ).ignore();
138 }
139 }
140
141 if( m_databaseHandlers.empty() ) {
142 m_storageSvc->endSession().ignore();
143 m_inSession = false;
144 }
145
146 return fid;
147}

◆ getStorageSvc()

IStorageSvc & pool::MicroSessionManager::getStorageSvc ( )
inline

Return StorageSvc.

Definition at line 55 of file MicroSessionManager.h.

55{ return *m_storageSvc; }

◆ setAttributeOfType()

bool pool::MicroSessionManager::setAttributeOfType ( const std::string & attributeName,
const void * data,
const std::type_info & typeInfo,
const std::string & option )
virtual

Definition at line 164 of file MicroSessionManager.cxx.

168{
169 if( !m_inSession ) {
170 return false;
171 }
172 pool::DbOption domainOption( attributeName, option );
173 if( !domainOption.i_setValue( typeInfo, const_cast<void*>( data ) ).isSuccess() ) return false;
174 return m_storageSvc->setDomainOption(domainOption).isSuccess();
175}

Member Data Documentation

◆ m_databaseHandlers

std::set<DatabaseHandler*> pool::MicroSessionManager::m_databaseHandlers
private

Definition at line 74 of file MicroSessionManager.h.

◆ m_inSession

bool pool::MicroSessionManager::m_inSession
private

Definition at line 72 of file MicroSessionManager.h.

◆ m_registry

DatabaseRegistry& pool::MicroSessionManager::m_registry
private

Definition at line 70 of file MicroSessionManager.h.

◆ m_storageSvc

IStorageSvc* pool::MicroSessionManager::m_storageSvc
private

Definition at line 71 of file MicroSessionManager.h.

◆ m_technology

long pool::MicroSessionManager::m_technology
private

Definition at line 73 of file MicroSessionManager.h.


The documentation for this class was generated from the following files: