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.
IContainercontainer (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.
TokenwriteObject (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

IStorageSvcm_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 122 of file DatabaseHandler.cxx.

123{
124 return m_accessMode;
125}

◆ 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 176 of file DatabaseHandler.cxx.

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

◆ 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,
93 containerName );
94 }
95 }
96 return 0;
97}
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 108 of file DatabaseHandler.cxx.

109{
110 return m_fileDescriptor.FID();
111}

◆ pfn()

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

Returns the physical file name.

Definition at line 101 of file DatabaseHandler.cxx.

102{
103 return m_fileDescriptor.PFN();
104}

◆ readObject()

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

Reads an object given a token.

Definition at line 158 of file DatabaseHandler.cxx.

159{
160 void* result( object );
161
162 // Get the persistent shape
163 const pool::Shape* shape = nullptr;
164 if( !m_storageSvc.getShape( m_fileDescriptor, token.classID(), shape ).isSuccess() ) {
165 return result;
166 }
167 if( !m_storageSvc.read( m_fileDescriptor, token, shape, &result ).isSuccess() ) {
168 return nullptr;
169 }
170
171 return result;
172}
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 189 of file DatabaseHandler.cxx.

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

◆ technology()

long pool::DatabaseHandler::technology ( ) const

Returns the technology identifier.

Definition at line 115 of file DatabaseHandler.cxx.

116{
117 return m_technology;
118}

◆ 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 129 of file DatabaseHandler.cxx.

133{
134 Token* token = 0;
135 if ( ! object ) return token;
136
137 // Get the persistent shape.
138 const pool::Shape* shape = nullptr;
139 Guid guid = DbReflex::guid(type);
140 if( !m_storageSvc.getShape( m_fileDescriptor, guid, shape ).isSuccess() ) {
141 shape = m_storageSvc.createShape( guid );
142 }
143 if ( shape ) {
144 if ( m_storageSvc.allocate( m_fileDescriptor,
145 containerName,
146 minorTechnology,
147 object,
148 shape,
149 token ).isSuccess() ) {
150 token->setClassID( shape->shapeID() );
151 }
152 }
153 return token;
154}
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: