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

DatabaseHandler is a class taking care of the micro-connections and the micro transactions for a given database. More...

#include <DatabaseHandler.h>

Collaboration diagram for pool::DatabaseHandler:

Public Member Functions

 DatabaseHandler (IStorageSvc &storageSvc, long technology, const std::string &fid, const std::string &pfn, Io::IoFlag accessmode)
 Constructor. Connects to the database.
 ~DatabaseHandler ()
 Destructor. Disconnects from the database.
bool commitTransaction ()
 Commits the transaction.
bool commitAndHoldTransaction ()
 Commits and holds the transaction.
bool disconnectTransaction ()
 Disconnects the transaction.
std::vector< std::string > containers ()
 Gives the list of containers.
IContainer * container (const std::string &containerName)
 Returns a container handle.
const std::string & pfn () const
 Returns the physical file name.
const std::string & fid () const
 Returns the file identifier.
long technology () const
 Returns the technology identifier.
Io::IoFlag accessMode () const
 Returns the access mode.
Token * writeObject (const std::string &containerName, long minorTechnology, const void *object, const RootType &type)
 Writes an object and returns a token.
void * readObject (const Token &token, void *object=0)
 Reads an object given a token.
bool attribute (const std::string &attributeName, void *data, const std::type_info &typeInfo, const std::string &option)
 Returns an attribute.
bool setAttribute (const std::string &attributeName, const void *data, const std::type_info &typeInfo, const std::string &option)
 Sets an attrtibute.

Private Attributes

IStorageSvc & m_storageSvc
 IStorageSvc reference.
FileDescriptor m_fileDescriptor
 File descriptor for this database.
long m_technology
 Technology identifier.
Io::IoFlag m_accessMode
 Current access mode.

Detailed Description

DatabaseHandler is a class taking care of the micro-connections and the micro transactions for a given database.

It also gives access to the underlying containers.

Definition at line 30 of file DatabaseHandler.h.

Constructor & Destructor Documentation

◆ DatabaseHandler()

pool::DatabaseHandler::DatabaseHandler ( pool::IStorageSvc & storageSvc,
long technology,
const std::string & fid,
const std::string & pfn,
Io::IoFlag accessmode )

Constructor. Connects to the database.

Definition at line 20 of file DatabaseHandler.cxx.

24 :
25 m_storageSvc( storageSvc ),
28 m_accessMode( accessmode )
29{
30 if ( ! m_storageSvc.connect( m_accessMode, m_fileDescriptor ).isSuccess() ) {
31 throw std::runtime_error( "Could not connect to the database (APR: \" DatabaseHandler::DatabaseHandler \" from \" PersistencySvc \")" );
32 }
33}
FileDescriptor m_fileDescriptor
File descriptor for this database.
long m_technology
Technology identifier.
const std::string & pfn() const
Returns the physical file name.
long technology() const
Returns the technology identifier.
Io::IoFlag m_accessMode
Current access mode.
const std::string & fid() const
Returns the file identifier.
IStorageSvc & m_storageSvc
IStorageSvc reference.

◆ ~DatabaseHandler()

pool::DatabaseHandler::~DatabaseHandler ( )

Destructor. Disconnects from the database.

Definition at line 35 of file DatabaseHandler.cxx.

36{
37 Io::IoFlag mode = Io::INVALID;
38 if( m_storageSvc.openMode(m_fileDescriptor, mode).isSuccess() ) {
39 m_storageSvc.disconnect( m_fileDescriptor ).ignore();
40 }
41}

Member Function Documentation

◆ accessMode()

Io::IoFlag pool::DatabaseHandler::accessMode ( ) const

Returns the access mode.

Definition at line 120 of file DatabaseHandler.cxx.

121{
122 return m_accessMode;
123}

◆ attribute()

bool pool::DatabaseHandler::attribute ( const std::string & attributeName,
void * data,
const std::type_info & typeInfo,
const std::string & option )

Returns an attribute.

Definition at line 174 of file DatabaseHandler.cxx.

178{
179 pool::DbOption databaseOption( attributeName, option );
180 DbDatabase dbH( m_fileDescriptor.dbc()->handle() );
181 if( !dbH.getOption(databaseOption).isSuccess() ) return false;
182 return databaseOption.i_getValue(typeInfo, data).isSuccess();
183}

◆ commitAndHoldTransaction()

bool pool::DatabaseHandler::commitAndHoldTransaction ( )

Commits and holds the transaction.

Definition at line 53 of file DatabaseHandler.cxx.

◆ commitTransaction()

bool pool::DatabaseHandler::commitTransaction ( )

Commits the transaction.

Definition at line 45 of file DatabaseHandler.cxx.

◆ container()

pool::IContainer * pool::DatabaseHandler::container ( const std::string & containerName)

Returns a container handle.

Definition at line 84 of file DatabaseHandler.cxx.

85{
86 // Check the existence of a given container.
87 std::vector< std::string > allContainers = this->containers();
88 for ( std::vector< std::string >::const_iterator iName = allContainers.begin();
89 iName != allContainers.end(); ++iName ) {
90 if ( *iName == containerName ) {
91 return new pool::Container( m_fileDescriptor, containerName );
92 }
93 }
94 return 0;
95}
std::vector< std::string > containers()
Gives the list of containers.

◆ containers()

std::vector< std::string > pool::DatabaseHandler::containers ( )

Gives the list of containers.

Definition at line 66 of file DatabaseHandler.cxx.

67{
68 std::vector< std::string > result;
69 std::vector<const Token*> containerTokens;
70 DbDatabase dbH( m_fileDescriptor.dbc()->handle() );
71 if( !dbH.containers(containerTokens, false).isSuccess() ) {
72 DbPrint log( m_fileDescriptor.PFN() );
73 log << MSG::ERROR << "Could not retrieve the list of containers." << endmsg;
74 }
75 for ( std::vector<const Token*>::const_iterator iToken = containerTokens.begin();
76 iToken != containerTokens.end(); ++iToken ) {
77 Token tok (*iToken);
78 result.push_back( m_storageSvc.getContName(m_fileDescriptor, tok) );
79 }
80 return result;
81}
#define endmsg

◆ disconnectTransaction()

bool pool::DatabaseHandler::disconnectTransaction ( )

Disconnects the transaction.

Definition at line 60 of file DatabaseHandler.cxx.

61{
62 return ( m_storageSvc.disconnect( m_fileDescriptor ).isSuccess() );
63}

◆ fid()

const std::string & pool::DatabaseHandler::fid ( ) const

Returns the file identifier.

Definition at line 106 of file DatabaseHandler.cxx.

107{
108 return m_fileDescriptor.FID();
109}

◆ pfn()

const std::string & pool::DatabaseHandler::pfn ( ) const

Returns the physical file name.

Definition at line 99 of file DatabaseHandler.cxx.

100{
101 return m_fileDescriptor.PFN();
102}

◆ readObject()

void * pool::DatabaseHandler::readObject ( const Token & token,
void * object = 0 )

Reads an object given a token.

Definition at line 156 of file DatabaseHandler.cxx.

157{
158 void* result( object );
159
160 // Get the persistent shape
161 const pool::Shape* shape = nullptr;
162 if( !m_storageSvc.getShape( m_fileDescriptor, token.classID(), shape ).isSuccess() ) {
163 return result;
164 }
165 if( !m_storageSvc.read( m_fileDescriptor, token, shape, &result ).isSuccess() ) {
166 return nullptr;
167 }
168
169 return result;
170}
const Guid & classID() const
Access database identifier.
Definition Token.h:74

◆ setAttribute()

bool pool::DatabaseHandler::setAttribute ( const std::string & attributeName,
const void * data,
const std::type_info & typeInfo,
const std::string & option )

Sets an attrtibute.

Definition at line 187 of file DatabaseHandler.cxx.

191{
192 pool::DbOption databaseOption( attributeName, option );
193 if( !databaseOption.i_setValue( typeInfo, const_cast<void*>( data ) ).isSuccess() ) return false;
194 DbDatabase dbH( m_fileDescriptor.dbc()->handle() );
195 return dbH.setOption(databaseOption).isSuccess();
196 }

◆ technology()

long pool::DatabaseHandler::technology ( ) const

Returns the technology identifier.

Definition at line 113 of file DatabaseHandler.cxx.

114{
115 return m_technology;
116}

◆ writeObject()

Token * pool::DatabaseHandler::writeObject ( const std::string & containerName,
long minorTechnology,
const void * object,
const RootType & type )

Writes an object and returns a token.

Definition at line 127 of file DatabaseHandler.cxx.

131{
132 Token* token = 0;
133 if ( ! object ) return token;
134
135 // Get the persistent shape.
136 const pool::Shape* shape = nullptr;
137 Guid guid = DbReflex::guid(type);
138 if( !m_storageSvc.getShape( m_fileDescriptor, guid, shape ).isSuccess() ) {
139 shape = m_storageSvc.createShape( guid );
140 }
141 if ( shape ) {
142 if ( m_storageSvc.allocate( m_fileDescriptor,
143 containerName,
144 minorTechnology,
145 object,
146 shape,
147 token ).isSuccess() ) {
148 token->setClassID( shape->shapeID() );
149 }
150 }
151 return token;
152}
Token & setClassID(const Guid &cl_id)
Access database identifier.
Definition Token.h:76
static Guid guid(const RootType &id)
Determine Guid (normalized string form) from reflection type.
const Guid & shapeID() const
Access database identifier.
Definition Shape.h:45

Member Data Documentation

◆ m_accessMode

Io::IoFlag pool::DatabaseHandler::m_accessMode
private

Current access mode.

Definition at line 98 of file DatabaseHandler.h.

◆ m_fileDescriptor

FileDescriptor pool::DatabaseHandler::m_fileDescriptor
private

File descriptor for this database.

Definition at line 94 of file DatabaseHandler.h.

◆ m_storageSvc

IStorageSvc& pool::DatabaseHandler::m_storageSvc
private

IStorageSvc reference.

Definition at line 92 of file DatabaseHandler.h.

◆ m_technology

long pool::DatabaseHandler::m_technology
private

Technology identifier.

Definition at line 96 of file DatabaseHandler.h.


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