#include <Database.h>
Public Member Functions | |
Configuration & | configuration () |
bool | connect (const std::string &connectionString, bool readOnly=false) |
bool | connect (const std::string &connectionString, const std::string &asRole, bool readOnly=false) |
const std::string & | connectionString () |
Container | containerHandle (const std::string &name) |
Container | containerHandle (int contId) |
std::set< std::string > | containers () |
bool | create (std::string userSchemaVersion=std::string("")) |
template<typename T > | |
Container | createContainer (const std::string &name) |
template<typename T > | |
Container | createContainer () |
Container | createContainer (const std::string &className, std::string name="") |
Database (const Database &rhs) | |
Database (boost::shared_ptr< ConnectionPool > &connectionPool) | |
Database () | |
void | disconnect () |
bool | drop () |
bool | dropContainer (const std::string &name) |
void | erase (const OId &oid) |
bool | eraseAllNames () |
bool | eraseObjectName (const std::string &name) |
bool | exists () |
template<typename T > | |
boost::shared_ptr< T > | fetch (const OId &oid) |
template<typename T > | |
boost::shared_ptr< T > | fetchByName (const std::string &name) |
Object | fetchItem (const OId &oid) |
Object | fetchItemByName (const std::string &name) |
void | flush () |
bool | getItemId (const std::string &name, OId &destination) |
bool | getNamesForObject (const OId &oid, std::vector< std::string > &destination) |
template<typename T > | |
OId | insert (const std::string &containerName, const T &data) |
template<typename T > | |
OId | insert (const T &data) |
OId | insertItem (const std::string &containerName, const Object &data) |
bool | isConnected () |
bool | listObjectNames (std::vector< std::string > &destination) |
bool | lockContainer (const std::string &name) |
Database & | operator= (const Database &rhs) |
ora::Version | schemaVersion (bool userSchema=false) |
void | setAccessPermission (const std::string &principal, bool forWrite) |
void | setObjectName (const std::string &name, const OId &oid) |
SharedSession & | storageAccessSession () |
Transaction & | transaction () |
template<typename T > | |
void | update (const OId &oid, const T &data) |
void | updateItem (const OId &oid, const Object &data) |
DatabaseUtility | utility () |
virtual | ~Database () |
Static Public Member Functions | |
static std::string | nameForContainer (const std::type_info &typeInfo) |
static std::string | nameForContainer (const std::string &className) |
Private Member Functions | |
void | checkTransaction () |
Container | createContainer (const std::type_info &typeInfo) |
Container | createContainer (const std::string &name, const std::type_info &typeInfo) |
Container | getContainer (const std::string &name, const std::type_info &typeInfo) |
Container | getContainer (const std::type_info &typeInfo) |
boost::shared_ptr< void > | getTypedObjectByName (const std::string &name, const std::type_info &typeInfo) |
void | open (bool writingAccess=false) |
Private Attributes | |
boost::shared_ptr< DatabaseImpl > | m_impl |
Definition at line 30 of file Database.h.
ora::Database::Database | ( | ) |
Definition at line 66 of file Database.cc.
: m_impl( new DatabaseImpl ){ }
ora::Database::Database | ( | const Database & | rhs | ) |
Definition at line 70 of file Database.cc.
: m_impl( rhs.m_impl ){ }
ora::Database::Database | ( | boost::shared_ptr< ConnectionPool > & | connectionPool | ) |
Definition at line 74 of file Database.cc.
: m_impl( new DatabaseImpl( connectionPool) ){ }
ora::Database::~Database | ( | ) | [virtual] |
Definition at line 78 of file Database.cc.
{ disconnect(); }
void ora::Database::checkTransaction | ( | ) | [private] |
Definition at line 121 of file Database.cc.
References ora::throwException().
{ if(!m_impl->m_session->isConnected()) { throwException("No database storage connected.","Database::checkTransaction"); } if(!m_impl->m_transaction->isActive()) { throwException("Transaction is not active.","Database::checkTransaction"); } }
ora::Configuration & ora::Database::configuration | ( | ) |
Definition at line 87 of file Database.cc.
{ return m_impl->m_session->configuration(); }
bool ora::Database::connect | ( | const std::string & | connectionString, |
bool | readOnly = false |
||
) |
Definition at line 91 of file Database.cc.
{ return m_impl->m_session->connect( connectionString, readOnly ); }
bool ora::Database::connect | ( | const std::string & | connectionString, |
const std::string & | asRole, | ||
bool | readOnly = false |
||
) |
Definition at line 96 of file Database.cc.
{ return m_impl->m_session->connect( connectionString, asRole, readOnly ); }
const std::string & ora::Database::connectionString | ( | ) |
Definition at line 110 of file Database.cc.
Referenced by cond::IOVSchemaUtility::createIOVContainer(), cond::IOVSchemaUtility::createPayloadContainer(), cond::IOVSchemaUtility::dropAll(), cond::IOVSchemaUtility::dropIOVContainer(), and cond::IOVSchemaUtility::dropPayloadContainer().
{ return m_impl->m_session->connectionString(); }
ora::Container ora::Database::containerHandle | ( | const std::string & | name | ) |
Definition at line 272 of file Database.cc.
References cont, and ora::throwException().
Referenced by cond::DbSession::importObject().
{ open(); Handle<DatabaseContainer> cont = m_impl->m_session->containerHandle( name ); if( !cont ){ throwException("Container \""+name+"\" does not exist in the database.", "Database::containerHandle"); } return Container( cont ); }
ora::Container ora::Database::containerHandle | ( | int | contId | ) |
Definition at line 282 of file Database.cc.
References cont, and ora::throwException().
{ open(); Handle<DatabaseContainer> cont = m_impl->m_session->containerHandle( contId ); if( !cont ){ std::stringstream messg; messg << "Container with id=" << contId << " not found in the database."; throwException(messg.str(), "Database::containerHandle"); } return Container( cont ); }
std::set< std::string > ora::Database::containers | ( | ) |
Definition at line 191 of file Database.cc.
References Association::map.
Referenced by cond::IOVSchemaUtility::createIOVContainer(), cond::IOVSchemaUtility::createPayloadContainer(), cond::IOVSchemaUtility::dropIOVContainer(), cond::IOVSchemaUtility::dropPayloadContainer(), and cond::IOVSchemaUtility::existsIOVContainer().
{ open(); std::set< std::string > contList; const std::map<int, Handle<DatabaseContainer> >& conts = m_impl->m_session->containers(); for(std::map<int, Handle<DatabaseContainer> >::const_iterator iC = conts.begin(); iC != conts.end(); iC++ ){ contList.insert( iC->second->name() ); } return contList; }
bool ora::Database::create | ( | std::string | userSchemaVersion = std::string("") | ) |
Definition at line 135 of file Database.cc.
Referenced by cond::IOVSchemaUtility::createIOVContainer().
ora::Container ora::Database::createContainer | ( | const std::string & | name | ) | [inline] |
Definition at line 201 of file Database.h.
References createContainer().
Referenced by cond::IOVSchemaUtility::createIOVContainer(), and cond::IOVSchemaUtility::createPayloadContainer().
{ return createContainer( name, typeid(T) ); }
ora::Container ora::Database::createContainer | ( | ) | [inline] |
Definition at line 207 of file Database.h.
Referenced by createContainer().
{ return createContainer( typeid(T) ); }
ora::Container ora::Database::createContainer | ( | const std::string & | className, |
std::string | name = "" |
||
) |
Definition at line 226 of file Database.cc.
References cont, ora::ClassUtils::lookupDictionary(), and ora::throwException().
{ open( true ); Reflex::Type contType = ClassUtils::lookupDictionary( className ); if( name.empty() ) name = nameForContainer( className ); if( m_impl->m_session->containerHandle( name ) ){ throwException("Container with name \""+name+"\" already exists in the database.", "Database::createContainer"); } Handle<DatabaseContainer> cont = m_impl->m_session->createContainer( name, contType ); return Container( cont ); }
ora::Container ora::Database::createContainer | ( | const std::string & | name, |
const std::type_info & | typeInfo | ||
) | [private] |
Definition at line 202 of file Database.cc.
References cont, ora::ClassUtils::lookupDictionary(), and ora::throwException().
{ open( true ); if( m_impl->m_session->containerHandle( name ) ){ throwException("Container with name \""+name+"\" already exists in the database.", "Database::createContainer"); } Reflex::Type contType = ClassUtils::lookupDictionary( typeInfo ); Handle<DatabaseContainer> cont = m_impl->m_session->createContainer( name, contType ); return Container( cont ); }
ora::Container ora::Database::createContainer | ( | const std::type_info & | typeInfo | ) | [private] |
Definition at line 214 of file Database.cc.
References cont, ora::ClassUtils::lookupDictionary(), ora::nameFromClass(), and ora::throwException().
{ open( true ); Reflex::Type contType = ClassUtils::lookupDictionary( typeInfo ); std::string name = nameFromClass( contType ); if( m_impl->m_session->containerHandle( name ) ){ throwException("Container with name \""+name+"\" already exists in the database.", "Database::createContainer"); } Handle<DatabaseContainer> cont = m_impl->m_session->createContainer( name, contType ); return Container( cont ); }
void ora::Database::disconnect | ( | void | ) |
Definition at line 102 of file Database.cc.
{ m_impl->m_session->disconnect(); }
bool ora::Database::drop | ( | ) |
Definition at line 144 of file Database.cc.
References Association::map.
Referenced by cond::IOVSchemaUtility::dropAll().
{ bool dropped = false; if( exists()){ open(); const std::map<int, Handle<DatabaseContainer> >& conts = m_impl->m_session->containers(); for(std::map<int, Handle<DatabaseContainer> >::const_iterator iC = conts.begin(); iC != conts.end(); iC++ ){ iC->second->drop(); } m_impl->m_session->drop(); dropped = true; } return dropped; }
bool ora::Database::dropContainer | ( | const std::string & | name | ) |
Definition at line 253 of file Database.cc.
Referenced by cond::IOVSchemaUtility::dropIOVContainer(), and cond::IOVSchemaUtility::dropPayloadContainer().
void ora::Database::erase | ( | const OId & | oid | ) |
Definition at line 314 of file Database.cc.
References cont, ora::OId::containerId(), ora::Container::erase(), and ora::OId::itemId().
{ open(); Container cont = containerHandle( oid.containerId() ); cont.erase( oid.itemId() ); }
bool ora::Database::eraseAllNames | ( | ) |
Definition at line 339 of file Database.cc.
bool ora::Database::eraseObjectName | ( | const std::string & | name | ) |
Definition at line 334 of file Database.cc.
bool ora::Database::exists | ( | ) |
Definition at line 130 of file Database.cc.
Referenced by cond::IOVSchemaUtility::createIOVContainer(), and cond::IOVSchemaUtility::existsIOVContainer().
{ checkTransaction(); return m_impl->m_session->exists(); }
Definition at line 213 of file Database.h.
References cont, ora::OId::containerId(), ora::Container::fetch(), and ora::OId::itemId().
Referenced by cond::DbSession::getTypedObject().
{ Container cont = containerHandle( oid.containerId() ); return cont.fetch<T>( oid.itemId() ); }
boost::shared_ptr< T > ora::Database::fetchByName | ( | const std::string & | name | ) | [inline] |
Definition at line 245 of file Database.h.
{ return boost::static_pointer_cast<T>( getTypedObjectByName( name, typeid(T) ) ); }
ora::Object ora::Database::fetchItem | ( | const OId & | oid | ) |
Definition at line 294 of file Database.cc.
References cont, ora::OId::containerId(), ora::Container::fetchItem(), and ora::OId::itemId().
{ Container cont = containerHandle( oid.containerId() ); return cont.fetchItem( oid.itemId() ); }
ora::Object ora::Database::fetchItemByName | ( | const std::string & | name | ) |
Definition at line 355 of file Database.cc.
void ora::Database::flush | ( | ) |
Definition at line 320 of file Database.cc.
References Association::map.
Referenced by cond::DbSession::storeObject(), and cond::DbSession::updateObject().
{ open(); const std::map<int,Handle<DatabaseContainer> >& containers = m_impl->m_session->containers(); for( std::map<int,Handle<DatabaseContainer> >::const_iterator iCont = containers.begin(); iCont != containers.end(); ++iCont ){ iCont->second->flush(); } }
ora::Container ora::Database::getContainer | ( | const std::type_info & | typeInfo | ) | [private] |
Definition at line 246 of file Database.cc.
References ora::getContainerFromSession(), ora::ClassUtils::lookupDictionary(), and ora::nameFromClass().
{ open( true ); Reflex::Type objType = ClassUtils::lookupDictionary( typeInfo ); std::string contName = nameFromClass( objType ); return getContainerFromSession( contName, objType, *m_impl->m_session); }
ora::Container ora::Database::getContainer | ( | const std::string & | name, |
const std::type_info & | typeInfo | ||
) | [private] |
Definition at line 239 of file Database.cc.
References ora::getContainerFromSession(), and ora::ClassUtils::lookupDictionary().
{ open( true ); Reflex::Type objType = ClassUtils::lookupDictionary( typeInfo ); return getContainerFromSession( containerName, objType, *m_impl->m_session ); }
bool ora::Database::getItemId | ( | const std::string & | name, |
ora::OId & | destination | ||
) |
Definition at line 344 of file Database.cc.
bool ora::Database::getNamesForObject | ( | const OId & | oid, |
std::vector< std::string > & | destination | ||
) |
Definition at line 360 of file Database.cc.
References ora::OId::containerId(), and ora::OId::itemId().
boost::shared_ptr< void > ora::Database::getTypedObjectByName | ( | const std::string & | name, |
const std::type_info & | typeInfo | ||
) | [private] |
Definition at line 349 of file Database.cc.
References ora::ClassUtils::lookupDictionary().
{ open(); Reflex::Type objType = ClassUtils::lookupDictionary( typeInfo ); return m_impl->m_session->fetchTypedObjectByName( name, objType ); }
ora::OId ora::Database::insert | ( | const std::string & | containerName, |
const T & | data | ||
) | [inline] |
Definition at line 220 of file Database.h.
References cont, ora::Container::id(), and ora::Container::insert().
Referenced by cond::DbSession::storeObject().
{ Container cont = getContainer( containerName, typeid(data) ); int itemId = cont.insert( data ); return OId( cont.id(), itemId ); }
Definition at line 229 of file Database.h.
References cont, ora::Container::id(), and ora::Container::insert().
{ Container cont = getContainer( typeid(data) ); int itemId = cont.insert( data ); return OId( cont.id(), itemId ); }
Definition at line 299 of file Database.cc.
References cont, ora::getContainerFromSession(), ora::Container::id(), ora::Container::insertItem(), and ora::Object::type().
{ open( true ); Container cont = getContainerFromSession( containerName, dataObject.type(), *m_impl->m_session ); int itemId = cont.insertItem( dataObject ); return OId( cont.id(), itemId ); }
bool ora::Database::isConnected | ( | ) |
Definition at line 106 of file Database.cc.
{ return m_impl->m_session->isConnected(); }
bool ora::Database::listObjectNames | ( | std::vector< std::string > & | destination | ) |
Definition at line 366 of file Database.cc.
bool ora::Database::lockContainer | ( | const std::string & | name | ) |
Definition at line 262 of file Database.cc.
References cont, and ora::throwException().
Referenced by cond::ExportIOVUtilities::execute().
{ open(); Handle<DatabaseContainer> cont = m_impl->m_session->containerHandle( name ); if( !cont ){ throwException("Container \""+name+"\" does not exist in the database.", "Database::lockContainer"); } return cont->lock(); }
std::string ora::Database::nameForContainer | ( | const std::type_info & | typeInfo | ) | [static] |
Definition at line 57 of file Database.cc.
References ora::ClassUtils::lookupDictionary(), and ora::nameFromClass().
{ Reflex::Type contType = ClassUtils::lookupDictionary( typeInfo ); return nameFromClass( contType ); }
std::string ora::Database::nameForContainer | ( | const std::string & | className | ) | [static] |
void ora::Database::open | ( | bool | writingAccess = false | ) | [private] |
Definition at line 171 of file Database.cc.
References ora::Configuration::automaticDatabaseCreation(), and ora::throwException().
{ checkTransaction(); if( !m_impl->m_session->exists() ){ if( writingAccess && m_impl->m_session->configuration().properties().getFlag( Configuration::automaticDatabaseCreation() ) ){ m_impl->m_session->create(); } else { throwException("Database does not exists in \""+m_impl->m_session->connectionString()+"\"","Database::open"); } } m_impl->m_session->open(); }
ora::Database & ora::Database::operator= | ( | const Database & | rhs | ) |
Definition at line 82 of file Database.cc.
References m_impl.
{ if( this != &rhs ) m_impl = rhs.m_impl; return *this; }
ora::Version ora::Database::schemaVersion | ( | bool | userSchema = false | ) |
Definition at line 183 of file Database.cc.
References ora::Version::fromString(), and ora::throwException().
{ checkTransaction(); if( !m_impl->m_session->exists() ){ throwException("Database does not exists in \""+m_impl->m_session->connectionString()+"\"","Database::schemaVersion"); } return Version::fromString( m_impl->m_session->schemaVersion( userSchema ) ); }
void ora::Database::setAccessPermission | ( | const std::string & | principal, |
bool | forWrite | ||
) |
Definition at line 159 of file Database.cc.
References Association::map.
{ if( exists()){ open(); m_impl->m_session->setAccessPermission( principal, forWrite ); const std::map<int, Handle<DatabaseContainer> >& conts = m_impl->m_session->containers(); for(std::map<int, Handle<DatabaseContainer> >::const_iterator iC = conts.begin(); iC != conts.end(); iC++ ){ iC->second->setAccessPermission( principal, forWrite ); } } }
void ora::Database::setObjectName | ( | const std::string & | name, |
const OId & | oid | ||
) |
Definition at line 329 of file Database.cc.
References ora::OId::containerId(), and ora::OId::itemId().
ora::SharedSession & ora::Database::storageAccessSession | ( | ) |
Definition at line 377 of file Database.cc.
{ return m_impl->m_session->storageAccessSession(); }
ora::Transaction & ora::Database::transaction | ( | ) |
Definition at line 114 of file Database.cc.
References ora::throwException().
{ if(!m_impl->m_session->isConnected()) { throwException("No database storage connected.","Database::transaction"); } return *m_impl->m_transaction; }
Definition at line 237 of file Database.h.
References cont, ora::OId::containerId(), AlCaHLTBitMon_QueryRunRegistry::data, ora::OId::itemId(), and ora::Container::update().
Referenced by cond::DbSession::updateObject().
{ Container cont = containerHandle( oid.containerId() ); cont.update( oid.itemId(), data ); }
Definition at line 307 of file Database.cc.
References cont, ora::OId::containerId(), ora::OId::itemId(), and ora::Container::updateItem().
{ open(); Container cont = containerHandle( oid.containerId() ); cont.updateItem( oid.itemId(), dataObject ); }
ora::DatabaseUtility ora::Database::utility | ( | ) |
Definition at line 371 of file Database.cc.
{ checkTransaction(); Handle<DatabaseUtilitySession> utilSession = m_impl->m_session->utility(); return DatabaseUtility( utilSession ); }
boost::shared_ptr<DatabaseImpl> ora::Database::m_impl [private] |
Definition at line 199 of file Database.h.
Referenced by operator=().