ATLAS Offline Software
Loading...
Searching...
No Matches
DatabaseHandler Class Referencefinal

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 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.
Container * 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.
FileDescriptor & fileDescriptor ()
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 28 of file DatabaseHandler.h.

Constructor & Destructor Documentation

◆ DatabaseHandler()

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

Constructor. Connects to the database.

Definition at line 16 of file DatabaseHandler.cxx.

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

◆ ~DatabaseHandler()

DatabaseHandler::~DatabaseHandler ( )

Destructor. Disconnects from the database.

Definition at line 30 of file DatabaseHandler.cxx.

30 {
31 Io::IoFlag mode = Io::INVALID;
32 if( m_storageSvc.openMode(m_fileDescriptor, mode).isSuccess() ) {
33 m_storageSvc.disconnect( m_fileDescriptor ).ignore();
34 }
35}

Member Function Documentation

◆ accessMode()

Io::IoFlag DatabaseHandler::accessMode ( ) const

Returns the access mode.

Definition at line 89 of file DatabaseHandler.cxx.

89 {
90 return m_accessMode;
91}

◆ attribute()

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

Returns an attribute.

Definition at line 117 of file DatabaseHandler.cxx.

120 {
121 DbOption databaseOption( attributeName, option );
122 DbDatabase dbH( m_fileDescriptor.dbc()->handle() );
123 if( !dbH.getOption(databaseOption).isSuccess() ) return false;
124 return databaseOption.i_getValue(typeInfo, data).isSuccess();
125}

◆ commitAndHoldTransaction()

bool DatabaseHandler::commitAndHoldTransaction ( )

Commits and holds the transaction.

Definition at line 42 of file DatabaseHandler.cxx.

◆ commitTransaction()

bool DatabaseHandler::commitTransaction ( )

Commits the transaction.

Definition at line 37 of file DatabaseHandler.cxx.

37 {
38 return m_storageSvc.endTransaction( m_fileDescriptor, Transaction::TRANSACT_COMMIT ).isSuccess() &&
39 m_storageSvc.endTransaction( m_fileDescriptor, Transaction::TRANSACT_FLUSH ).isSuccess();
40}

◆ container()

Container * DatabaseHandler::container ( const std::string & containerName)

Returns a container handle.

Definition at line 65 of file DatabaseHandler.cxx.

65 {
66 // Check the existence of a given container.
67 std::vector< std::string > allContainers = this->containers();
68 for ( std::vector< std::string >::const_iterator iName = allContainers.begin();
69 iName != allContainers.end(); ++iName ) {
70 if ( *iName == containerName ) {
71 return new Container( m_fileDescriptor, containerName );
72 }
73 }
74 return 0;
75}
std::vector< std::string > containers()
Gives the list of containers.

◆ containers()

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

Gives the list of containers.

Definition at line 50 of file DatabaseHandler.cxx.

50 {
51 std::vector< std::string > result;
52 std::vector<const Token*> containerTokens;
53 DbDatabase dbH( m_fileDescriptor.dbc()->handle() );
54 if( !dbH.containers(containerTokens, false).isSuccess() ) {
55 return result;
56 }
57 for ( std::vector<const Token*>::const_iterator iToken = containerTokens.begin();
58 iToken != containerTokens.end(); ++iToken ) {
59 Token tok (*iToken);
60 result.push_back( m_storageSvc.getContName(m_fileDescriptor, tok) );
61 }
62 return result;
63}

◆ disconnectTransaction()

bool DatabaseHandler::disconnectTransaction ( )

Disconnects the transaction.

Definition at line 46 of file DatabaseHandler.cxx.

46 {
47 return ( m_storageSvc.disconnect( m_fileDescriptor ).isSuccess() );
48}

◆ fid()

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

Returns the file identifier.

Definition at line 81 of file DatabaseHandler.cxx.

81 {
82 return m_fileDescriptor.FID();
83}

◆ fileDescriptor()

FileDescriptor & DatabaseHandler::fileDescriptor ( )
inline

Definition at line 68 of file DatabaseHandler.h.

68{ return m_fileDescriptor; }

◆ pfn()

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

Returns the physical file name.

Definition at line 77 of file DatabaseHandler.cxx.

77 {
78 return m_fileDescriptor.PFN();
79}

◆ readObject()

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

Reads an object given a token.

Definition at line 109 of file DatabaseHandler.cxx.

109 {
110 void* result( object );
111 if( !m_storageSvc.read( m_fileDescriptor, token, &result ).isSuccess() ) {
112 return nullptr;
113 }
114 return result;
115}

◆ setAttribute()

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

Sets an attrtibute.

Definition at line 127 of file DatabaseHandler.cxx.

130 {
131 DbOption databaseOption( attributeName, option );
132 if( !databaseOption.i_setValue( typeInfo, const_cast<void*>( data ) ).isSuccess() ) return false;
133 DbDatabase dbH( m_fileDescriptor.dbc()->handle() );
134 return dbH.setOption(databaseOption).isSuccess();
135}

◆ technology()

long DatabaseHandler::technology ( ) const

Returns the technology identifier.

Definition at line 85 of file DatabaseHandler.cxx.

85 {
86 return m_technology;
87}

◆ writeObject()

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

Writes an object and returns a token.

Definition at line 93 of file DatabaseHandler.cxx.

96 {
97 Token* token = nullptr;
99 containerName,
100 minorTechnology,
101 object,
102 type,
103 token ).isSuccess() ) {
104 return nullptr;
105 }
106 return token;
107}

Member Data Documentation

◆ m_accessMode

Io::IoFlag DatabaseHandler::m_accessMode
private

Current access mode.

Definition at line 99 of file DatabaseHandler.h.

◆ m_fileDescriptor

FileDescriptor DatabaseHandler::m_fileDescriptor
private

File descriptor for this database.

Definition at line 95 of file DatabaseHandler.h.

◆ m_storageSvc

IStorageSvc& DatabaseHandler::m_storageSvc
private

IStorageSvc reference.

Definition at line 93 of file DatabaseHandler.h.

◆ m_technology

long DatabaseHandler::m_technology
private

Technology identifier.

Definition at line 97 of file DatabaseHandler.h.


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