#include <DatabaseSession.h>
Public Member Functions | |
Handle< ora::DatabaseContainer > | addContainer (const std::string &containerName, const std::string &className) |
void | commitTransaction () |
Configuration & | configuration () |
bool | connect (const std::string &connectionString, bool readOnly) |
bool | connect (const std::string &connectionString, const std::string &asRole, bool readOnly) |
boost::shared_ptr < ConnectionPool > & | connectionPool () |
const std::string & | connectionString () |
Handle< DatabaseContainer > | containerHandle (const std::string &name) |
Handle< DatabaseContainer > | containerHandle (int contId) |
NamedSequence & | containerIdSequence () |
const std::map< int, Handle < DatabaseContainer > > & | containers () |
ContainerUpdateTable & | containerUpdateTable () |
void | create (const std::string &userSchemaVersion=std::string("")) |
Handle< DatabaseContainer > | createContainer (const std::string &containerName, const Reflex::Type &type) |
DatabaseSession (boost::shared_ptr< ConnectionPool > &connectionPool) | |
DatabaseSession () | |
void | disconnect () |
void | drop () |
void | dropContainer (const std::string &name) |
bool | eraseAllNames () |
bool | eraseObjectName (const std::string &name) |
bool | exists () |
Object | fetchObjectByName (const std::string &name) |
boost::shared_ptr< void > | fetchTypedObjectByName (const std::string &name, const Reflex::Type &asType) |
bool | getItemId (const std::string &name, OId &destination) |
bool | getNamesForContainer (int containerId, std::vector< std::string > &destination) |
bool | getNamesForObject (int containerId, int itemId, std::vector< std::string > &destination) |
bool | isConnected () |
bool | isTransactionActive (bool checkIfReadOnly=false) |
bool | listObjectNames (std::vector< std::string > &destination) |
MappingDatabase & | mappingDatabase () |
void | open () |
void | rollbackTransaction () |
IDatabaseSchema & | schema () |
std::string | schemaVersion (bool userSchema) |
void | setAccessPermission (const std::string &principal, bool forWrite) |
void | setObjectName (const std::string &name, int containerId, int itemId) |
void | startTransaction (bool readOnly) |
SharedSession & | storageAccessSession () |
bool | testDropPermission () |
Handle< DatabaseUtilitySession > | utility () |
virtual | ~DatabaseSession () |
Private Member Functions | |
void | clearTransaction () |
Private Attributes | |
Configuration | m_configuration |
boost::shared_ptr< ConnectionPool > | m_connectionPool |
std::string | m_connectionString |
ContainerUpdateTable | m_containerUpdateTable |
std::auto_ptr< NamedSequence > | m_contIdSequence |
SharedSession | m_dbSession |
std::auto_ptr< MappingDatabase > | m_mappingDb |
SessionMonitoringData * | m_monitoring |
std::auto_ptr< IDatabaseSchema > | m_schema |
std::auto_ptr< TransactionCache > | m_transactionCache |
Definition at line 42 of file DatabaseSession.h.
ora::DatabaseSession::DatabaseSession | ( | ) |
Definition at line 45 of file DatabaseSession.cc.
References m_connectionPool.
: m_connectionPool( new ConnectionPool ), m_dbSession(), m_connectionString( "" ), m_schema(), m_contIdSequence(), m_mappingDb(), m_transactionCache(), m_containerUpdateTable(), m_configuration(), m_monitoring(0){ // for the private connection pool does not make sense to have a real pool... m_connectionPool->configuration().setConnectionTimeOut(0); }
ora::DatabaseSession::DatabaseSession | ( | boost::shared_ptr< ConnectionPool > & | connectionPool | ) | [explicit] |
Definition at line 60 of file DatabaseSession.cc.
: m_connectionPool( connectionPool ), m_dbSession(), m_connectionString( "" ), m_schema(), m_contIdSequence(), m_mappingDb(), m_transactionCache(), m_containerUpdateTable(), m_configuration(), m_monitoring(0){ }
ora::DatabaseSession::~DatabaseSession | ( | ) | [virtual] |
Definition at line 73 of file DatabaseSession.cc.
{ disconnect(); }
ora::Handle< ora::DatabaseContainer > ora::DatabaseSession::addContainer | ( | const std::string & | containerName, |
const std::string & | className | ||
) |
Definition at line 237 of file DatabaseSession.cc.
{ int newContId = m_contIdSequence->getNextId( true ); m_schema->containerHeaderTable().addContainer( newContId, containerName, className ); Handle<DatabaseContainer> container( new DatabaseContainer( newContId, containerName, className, 0, *this ) ); m_transactionCache->addContainer( newContId, containerName, container ); return container; }
void ora::DatabaseSession::clearTransaction | ( | ) | [private] |
Definition at line 102 of file DatabaseSession.cc.
{ m_transactionCache.reset(); m_mappingDb.reset(); m_contIdSequence.reset(); m_schema.reset(); m_containerUpdateTable.clear(); }
void ora::DatabaseSession::commitTransaction | ( | ) |
Definition at line 141 of file DatabaseSession.cc.
{ if( m_transactionCache.get() ){ m_schema->containerHeaderTable().updateNumberOfObjects( m_containerUpdateTable.table() ); m_dbSession.get().transaction().commit(); clearTransaction(); if(m_monitoring) { m_monitoring->stopTransaction(); } } }
ora::Configuration & ora::DatabaseSession::configuration | ( | ) |
Definition at line 363 of file DatabaseSession.cc.
{ return m_configuration; }
bool ora::DatabaseSession::connect | ( | const std::string & | connectionString, |
const std::string & | asRole, | ||
bool | readOnly | ||
) |
Definition at line 89 of file DatabaseSession.cc.
References reco::get(), and ora::Monitoring::isEnabled().
{ m_dbSession = m_connectionPool->connect( connectionString, asRole, readOnly?coral::ReadOnly:coral::Update ); if(m_dbSession.isValid()) { m_connectionString = connectionString; if( ora::Monitoring::isEnabled() ){ m_monitoring = ora::Monitoring::get().startSession( connectionString ); } } return isConnected(); }
bool ora::DatabaseSession::connect | ( | const std::string & | connectionString, |
bool | readOnly | ||
) |
Definition at line 77 of file DatabaseSession.cc.
References reco::get(), and ora::Monitoring::isEnabled().
Referenced by ora::DatabaseUtilitySession::importContainer(), and ora::DatabaseUtilitySession::importContainerSchema().
{ m_dbSession = m_connectionPool->connect( connectionString, readOnly?coral::ReadOnly:coral::Update ); if(m_dbSession.isValid()) { m_connectionString = connectionString; if( ora::Monitoring::isEnabled() ){ m_monitoring = ora::Monitoring::get().startSession( connectionString ); } } return isConnected(); }
boost::shared_ptr< ora::ConnectionPool > & ora::DatabaseSession::connectionPool | ( | ) |
Definition at line 371 of file DatabaseSession.cc.
{ return m_connectionPool; }
const std::string & ora::DatabaseSession::connectionString | ( | ) |
Definition at line 124 of file DatabaseSession.cc.
{ return m_connectionString; }
ora::Handle< ora::DatabaseContainer > ora::DatabaseSession::containerHandle | ( | const std::string & | name | ) |
Definition at line 264 of file DatabaseSession.cc.
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
{ return m_transactionCache->getContainer( name ); }
ora::Handle< ora::DatabaseContainer > ora::DatabaseSession::containerHandle | ( | int | contId | ) |
Definition at line 268 of file DatabaseSession.cc.
{ return m_transactionCache->getContainer( contId ); }
ora::NamedSequence & ora::DatabaseSession::containerIdSequence | ( | ) |
Definition at line 355 of file DatabaseSession.cc.
{ return *m_contIdSequence; }
const std::map< int, ora::Handle< ora::DatabaseContainer > > & ora::DatabaseSession::containers | ( | ) |
Definition at line 272 of file DatabaseSession.cc.
{ return m_transactionCache->containers(); }
ora::ContainerUpdateTable & ora::DatabaseSession::containerUpdateTable | ( | ) |
Definition at line 375 of file DatabaseSession.cc.
{ return m_containerUpdateTable; }
void ora::DatabaseSession::create | ( | const std::string & | userSchemaVersion = std::string("") | ) |
Definition at line 181 of file DatabaseSession.cc.
{ m_schema->create( userSchemaVersion ); m_contIdSequence->create(); m_mappingDb->setUp(); m_transactionCache->setDbExists( true ); }
ora::Handle< ora::DatabaseContainer > ora::DatabaseSession::createContainer | ( | const std::string & | containerName, |
const Reflex::Type & | type | ||
) |
Definition at line 248 of file DatabaseSession.cc.
{ // create the container int newContId = m_contIdSequence->getNextId( true ); Handle<DatabaseContainer> newCont ( new DatabaseContainer( newContId, containerName, type, *this ) ); m_transactionCache->addContainer( newContId, containerName, newCont ); newCont->create(); return newCont; }
void ora::DatabaseSession::disconnect | ( | void | ) |
Definition at line 110 of file DatabaseSession.cc.
{ if( isConnected() ){ if( isTransactionActive()) rollbackTransaction(); } clearTransaction(); m_dbSession.close(); m_connectionString.clear(); if(m_monitoring) m_monitoring->stop(); }
void ora::DatabaseSession::drop | ( | ) |
Definition at line 188 of file DatabaseSession.cc.
References ora::throwException().
{ if(!testDropPermission()){ throwException("Drop permission has been denied for the current user.", "DatabaseSession::drop"); } m_schema->drop(); m_transactionCache->dropDatabase(); }
void ora::DatabaseSession::dropContainer | ( | const std::string & | name | ) |
Definition at line 258 of file DatabaseSession.cc.
References cont, and mergeVDriftHistosByStation::name.
{ Handle<DatabaseContainer> cont = m_transactionCache->getContainer( name ); m_transactionCache->eraseContainer( cont->id(), name ); cont->drop(); }
bool ora::DatabaseSession::eraseAllNames | ( | ) |
Definition at line 286 of file DatabaseSession.cc.
{ return m_schema->namingServiceTable().eraseAllNames(); }
bool ora::DatabaseSession::eraseObjectName | ( | const std::string & | name | ) |
Definition at line 282 of file DatabaseSession.cc.
bool ora::DatabaseSession::exists | ( | ) |
Definition at line 174 of file DatabaseSession.cc.
{ if(!m_transactionCache->dbExistsLoaded()){ m_transactionCache->setDbExists( m_schema->exists() ); } return m_transactionCache->dbExists(); }
ora::Object ora::DatabaseSession::fetchObjectByName | ( | const std::string & | name | ) |
Definition at line 290 of file DatabaseSession.cc.
References cont, and run_regression::ret.
{ ora::Object ret; std::pair<int,int> oid; if( m_schema->namingServiceTable().getObjectByName( name, oid ) ){ ora::Handle<ora::DatabaseContainer> cont = containerHandle( oid.first ); if( cont ) ret = Object( cont->fetchItem( oid.second ), cont->type() ); } return ret; }
boost::shared_ptr< void > ora::DatabaseSession::fetchTypedObjectByName | ( | const std::string & | name, |
const Reflex::Type & | asType | ||
) |
Definition at line 309 of file DatabaseSession.cc.
References cont, and run_regression::ret.
{ boost::shared_ptr<void> ret = m_transactionCache->getNamedReference( name ); if( !ret.get() ){ std::pair<int,int> oid; if( m_schema->namingServiceTable().getObjectByName( name, oid ) ){ ora::Handle<ora::DatabaseContainer> cont = containerHandle( oid.first ); void* ptr = 0; if( cont ) { ptr = cont->fetchItemAsType( oid.second, asType ); if( ptr) ret = boost::shared_ptr<void>( ptr, RflxDeleter( cont->type() ) ); } } if( ret.get() ) m_transactionCache->setNamedReference( name, ret ); } return ret; }
bool ora::DatabaseSession::getItemId | ( | const std::string & | name, |
ora::OId & | destination | ||
) |
Definition at line 300 of file DatabaseSession.cc.
bool ora::DatabaseSession::getNamesForContainer | ( | int | containerId, |
std::vector< std::string > & | destination | ||
) |
Definition at line 327 of file DatabaseSession.cc.
{ return m_schema->namingServiceTable().getNamesForContainer( containerId, destination ); }
bool ora::DatabaseSession::getNamesForObject | ( | int | containerId, |
int | itemId, | ||
std::vector< std::string > & | destination | ||
) |
Definition at line 332 of file DatabaseSession.cc.
{ return m_schema->namingServiceTable().getNamesForObject( containerId, itemId, destination ); }
bool ora::DatabaseSession::isConnected | ( | ) |
Definition at line 120 of file DatabaseSession.cc.
{ return m_dbSession.isValid(); }
bool ora::DatabaseSession::isTransactionActive | ( | bool | checkIfReadOnly = false | ) |
Definition at line 162 of file DatabaseSession.cc.
References run_regression::ret.
{ bool ret = false; if( m_dbSession.get().transaction().isActive() ){ if( checkIfReadOnly ){ if( m_dbSession.get().transaction().isReadOnly() ) ret = true; } else { ret = true; } } return ret; }
bool ora::DatabaseSession::listObjectNames | ( | std::vector< std::string > & | destination | ) |
Definition at line 338 of file DatabaseSession.cc.
{ return m_schema->namingServiceTable().getAllNames( destination ); }
ora::MappingDatabase & ora::DatabaseSession::mappingDatabase | ( | ) |
Definition at line 359 of file DatabaseSession.cc.
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
{ return *m_mappingDb; }
void ora::DatabaseSession::open | ( | ) |
Definition at line 209 of file DatabaseSession.cc.
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
{ if(!m_transactionCache->isLoaded()){ std::map<std::string, ContainerHeaderData> containersData; m_schema->containerHeaderTable().getContainerData( containersData ); for(std::map<std::string, ContainerHeaderData>::iterator iC = containersData.begin(); iC != containersData.end(); ++iC){ Handle<DatabaseContainer> container( new DatabaseContainer( iC->second.id, iC->first, iC->second.className, iC->second.numberOfObjects, *this ) ); m_transactionCache->addContainer( iC->second.id, iC->first, container ); } m_schema->mainTable().getParameters( m_transactionCache->dbParams() ); m_transactionCache->setLoaded(); } }
void ora::DatabaseSession::rollbackTransaction | ( | ) |
Definition at line 152 of file DatabaseSession.cc.
{ if( m_transactionCache.get() ){ m_dbSession.get().transaction().rollback(); clearTransaction(); if(m_monitoring) { m_monitoring->stopTransaction(false); } } }
ora::IDatabaseSchema & ora::DatabaseSession::schema | ( | ) |
Definition at line 351 of file DatabaseSession.cc.
{ return *m_schema; }
std::string ora::DatabaseSession::schemaVersion | ( | bool | userSchema | ) |
Definition at line 225 of file DatabaseSession.cc.
References ora::IMainTable::userSchemaVersionParameterName(), BeamSplash_cfg::version, and ora::IMainTable::versionParameterName().
{ std::map<std::string,std::string>& params = m_transactionCache->dbParams(); std::string version(""); std::string paramName = IMainTable::versionParameterName(); if(userSchema ) paramName = IMainTable::userSchemaVersionParameterName(); std::map<std::string,std::string>::const_iterator iPar = params.find( paramName ); if( iPar != params.end() ){ version = iPar->second; } return version; }
void ora::DatabaseSession::setAccessPermission | ( | const std::string & | principal, |
bool | forWrite | ||
) |
Definition at line 197 of file DatabaseSession.cc.
void ora::DatabaseSession::setObjectName | ( | const std::string & | name, |
int | containerId, | ||
int | itemId | ||
) |
Definition at line 276 of file DatabaseSession.cc.
void ora::DatabaseSession::startTransaction | ( | bool | readOnly | ) |
Definition at line 128 of file DatabaseSession.cc.
References ora::IDatabaseSchema::createSchemaHandle(), and ora::MappingRules::sequenceNameForContainerId().
{ if( !m_transactionCache.get() ){ m_dbSession.get().transaction().start( readOnly ); m_schema.reset( IDatabaseSchema::createSchemaHandle( m_dbSession.get().nominalSchema() )); m_contIdSequence.reset( new NamedSequence( MappingRules::sequenceNameForContainerId(), *m_schema )); m_mappingDb.reset( new MappingDatabase( *m_schema )); m_transactionCache.reset( new TransactionCache ); if(m_monitoring) { m_monitoring->newTransaction(); } } }
ora::SharedSession & ora::DatabaseSession::storageAccessSession | ( | ) |
Definition at line 367 of file DatabaseSession.cc.
{ return m_dbSession; }
bool ora::DatabaseSession::testDropPermission | ( | ) |
Definition at line 202 of file DatabaseSession.cc.
{ if(!m_transactionCache->dropPermissionLoaded()){ m_transactionCache->setDropPermission( m_schema->testDropPermission() ); } return m_transactionCache->dropPermission(); }
ora::Handle< ora::DatabaseUtilitySession > ora::DatabaseSession::utility | ( | ) |
Definition at line 343 of file DatabaseSession.cc.
{ if( !m_transactionCache->utility() ){ Handle<DatabaseUtilitySession> util ( new DatabaseUtilitySession( *this ) ); m_transactionCache->setUtility( util ); } return m_transactionCache->utility(); }
Definition at line 141 of file DatabaseSession.h.
boost::shared_ptr<ConnectionPool> ora::DatabaseSession::m_connectionPool [private] |
Definition at line 133 of file DatabaseSession.h.
Referenced by DatabaseSession().
std::string ora::DatabaseSession::m_connectionString [private] |
Definition at line 135 of file DatabaseSession.h.
Definition at line 140 of file DatabaseSession.h.
std::auto_ptr<NamedSequence> ora::DatabaseSession::m_contIdSequence [private] |
Definition at line 137 of file DatabaseSession.h.
Definition at line 134 of file DatabaseSession.h.
std::auto_ptr<MappingDatabase> ora::DatabaseSession::m_mappingDb [private] |
Definition at line 138 of file DatabaseSession.h.
Definition at line 142 of file DatabaseSession.h.
std::auto_ptr<IDatabaseSchema> ora::DatabaseSession::m_schema [private] |
Definition at line 136 of file DatabaseSession.h.
std::auto_ptr<TransactionCache> ora::DatabaseSession::m_transactionCache [private] |
Definition at line 139 of file DatabaseSession.h.