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 (pool::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.
pool::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

pool::IStorageSvc & m_storageSvc
 IStorageSvc reference.
pool::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 31 of file DatabaseHandler.h.

Constructor & Destructor Documentation

◆ DatabaseHandler()

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

23 :
24 m_storageSvc( storageSvc ),
27 m_accessMode( accessmode )
28{
29 if ( ! m_storageSvc.connect( m_accessMode, m_fileDescriptor ).isSuccess() ) {
30 throw std::runtime_error( "Could not connect to the database (APR: \" DatabaseHandler::DatabaseHandler \" from \" PersistencySvc \")" );
31 }
32}
long technology() const
Returns the technology identifier.
long m_technology
Technology identifier.
pool::FileDescriptor m_fileDescriptor
File descriptor for this database.
pool::IStorageSvc & m_storageSvc
IStorageSvc reference.
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 34 of file DatabaseHandler.cxx.

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

Member Function Documentation

◆ accessMode()

Io::IoFlag DatabaseHandler::accessMode ( ) const

Returns the access mode.

Definition at line 118 of file DatabaseHandler.cxx.

119{
120 return m_accessMode;
121}

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

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

◆ commitAndHoldTransaction()

bool DatabaseHandler::commitAndHoldTransaction ( )

Commits and holds the transaction.

Definition at line 52 of file DatabaseHandler.cxx.

◆ commitTransaction()

bool DatabaseHandler::commitTransaction ( )

Commits the transaction.

Definition at line 44 of file DatabaseHandler.cxx.

◆ container()

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

Returns a container handle.

Definition at line 82 of file DatabaseHandler.cxx.

83{
84 // Check the existence of a given container.
85 std::vector< std::string > allContainers = this->containers();
86 for ( std::vector< std::string >::const_iterator iName = allContainers.begin();
87 iName != allContainers.end(); ++iName ) {
88 if ( *iName == containerName ) {
89 return new Container( m_fileDescriptor, containerName );
90 }
91 }
92 return 0;
93}
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 65 of file DatabaseHandler.cxx.

66{
67 std::vector< std::string > result;
68 std::vector<const Token*> containerTokens;
69 pool::DbDatabase dbH( m_fileDescriptor.dbc()->handle() );
70 if( !dbH.containers(containerTokens, false).isSuccess() ) {
71 return result;
72 }
73 for ( std::vector<const Token*>::const_iterator iToken = containerTokens.begin();
74 iToken != containerTokens.end(); ++iToken ) {
75 Token tok (*iToken);
76 result.push_back( m_storageSvc.getContName(m_fileDescriptor, tok) );
77 }
78 return result;
79}

◆ disconnectTransaction()

bool DatabaseHandler::disconnectTransaction ( )

Disconnects the transaction.

Definition at line 59 of file DatabaseHandler.cxx.

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

◆ fid()

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

Returns the file identifier.

Definition at line 104 of file DatabaseHandler.cxx.

105{
106 return m_fileDescriptor.FID();
107}

◆ fileDescriptor()

pool::FileDescriptor & DatabaseHandler::fileDescriptor ( )
inline

Definition at line 71 of file DatabaseHandler.h.

71{ return m_fileDescriptor; }

◆ pfn()

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

Returns the physical file name.

Definition at line 97 of file DatabaseHandler.cxx.

98{
99 return m_fileDescriptor.PFN();
100}

◆ readObject()

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

Reads an object given a token.

Definition at line 154 of file DatabaseHandler.cxx.

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

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

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

◆ technology()

long DatabaseHandler::technology ( ) const

Returns the technology identifier.

Definition at line 111 of file DatabaseHandler.cxx.

112{
113 return m_technology;
114}

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

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

Current access mode.

Definition at line 102 of file DatabaseHandler.h.

◆ m_fileDescriptor

pool::FileDescriptor DatabaseHandler::m_fileDescriptor
private

File descriptor for this database.

Definition at line 98 of file DatabaseHandler.h.

◆ m_storageSvc

pool::IStorageSvc& DatabaseHandler::m_storageSvc
private

IStorageSvc reference.

Definition at line 96 of file DatabaseHandler.h.

◆ m_technology

long DatabaseHandler::m_technology
private

Technology identifier.

Definition at line 100 of file DatabaseHandler.h.


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