#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) |
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 () |
Handle< DatabaseContainer > | createContainer (const std::string &containerName, const Reflex::Type &type) |
DatabaseSession () | |
DatabaseSession (boost::shared_ptr< ConnectionPool > &connectionPool) | |
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 () |
void | setObjectName (const std::string &name, int containerId, int itemId) |
void | startTransaction (bool readOnly) |
SharedSession & | storageAccessSession () |
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 |
std::auto_ptr< IDatabaseSchema > | m_schema |
std::auto_ptr< TransactionCache > | m_transactionCache |
Definition at line 40 of file DatabaseSession.h.
ora::DatabaseSession::DatabaseSession | ( | ) |
Definition at line 40 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(){ // 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 54 of file DatabaseSession.cc.
: m_connectionPool( connectionPool ), m_dbSession(), m_connectionString( "" ), m_schema(), m_contIdSequence(), m_mappingDb(), m_transactionCache(), m_containerUpdateTable(), m_configuration(){ }
ora::DatabaseSession::~DatabaseSession | ( | ) | [virtual] |
Definition at line 66 of file DatabaseSession.cc.
{ disconnect(); }
ora::Handle< ora::DatabaseContainer > ora::DatabaseSession::addContainer | ( | const std::string & | containerName, |
const std::string & | className | ||
) |
Definition at line 173 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 79 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 114 of file DatabaseSession.cc.
{ if( m_transactionCache.get() ){ m_schema->containerHeaderTable().updateNumberOfObjects( m_containerUpdateTable.table() ); m_dbSession.get().transaction().commit(); clearTransaction(); } }
ora::Configuration & ora::DatabaseSession::configuration | ( | ) |
Definition at line 300 of file DatabaseSession.cc.
{ return m_configuration; }
bool ora::DatabaseSession::connect | ( | const std::string & | connectionString, |
bool | readOnly | ||
) |
Definition at line 70 of file DatabaseSession.cc.
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; } return isConnected(); }
boost::shared_ptr< ora::ConnectionPool > & ora::DatabaseSession::connectionPool | ( | ) |
Definition at line 308 of file DatabaseSession.cc.
{ return m_connectionPool; }
const std::string & ora::DatabaseSession::connectionString | ( | ) |
Definition at line 100 of file DatabaseSession.cc.
{ return m_connectionString; }
ora::Handle< ora::DatabaseContainer > ora::DatabaseSession::containerHandle | ( | int | contId | ) |
Definition at line 205 of file DatabaseSession.cc.
{ return m_transactionCache->getContainer( contId ); }
ora::Handle< ora::DatabaseContainer > ora::DatabaseSession::containerHandle | ( | const std::string & | name | ) |
Definition at line 201 of file DatabaseSession.cc.
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
{ return m_transactionCache->getContainer( name ); }
ora::NamedSequence & ora::DatabaseSession::containerIdSequence | ( | ) |
Definition at line 292 of file DatabaseSession.cc.
{ return *m_contIdSequence; }
const std::map< int, ora::Handle< ora::DatabaseContainer > > & ora::DatabaseSession::containers | ( | ) |
Definition at line 209 of file DatabaseSession.cc.
{ return m_transactionCache->containers(); }
ora::ContainerUpdateTable & ora::DatabaseSession::containerUpdateTable | ( | ) |
Definition at line 312 of file DatabaseSession.cc.
{ return m_containerUpdateTable; }
void ora::DatabaseSession::create | ( | ) |
Definition at line 148 of file DatabaseSession.cc.
{ m_schema->create(); m_transactionCache->setDbExists( true ); }
ora::Handle< ora::DatabaseContainer > ora::DatabaseSession::createContainer | ( | const std::string & | containerName, |
const Reflex::Type & | type | ||
) |
Definition at line 183 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 ); m_schema->containerHeaderTable().addContainer( newContId, containerName, newCont->className() ); newCont->create(); return newCont; }
void ora::DatabaseSession::disconnect | ( | void | ) |
Definition at line 87 of file DatabaseSession.cc.
{ if( isConnected() ){ if( isTransactionActive()) rollbackTransaction(); } clearTransaction(); m_dbSession.close(); m_connectionString.clear(); }
void ora::DatabaseSession::drop | ( | ) |
Definition at line 153 of file DatabaseSession.cc.
{ m_schema->drop(); m_transactionCache->setDbExists( false ); }
void ora::DatabaseSession::dropContainer | ( | const std::string & | name | ) |
Definition at line 194 of file DatabaseSession.cc.
References cont, and mergeVDriftHistosByStation::name.
{ Handle<DatabaseContainer> cont = m_transactionCache->getContainer( name ); cont->drop(); m_transactionCache->eraseContainer( cont->id(), name ); m_schema->containerHeaderTable().removeContainer( cont->id() ); }
bool ora::DatabaseSession::eraseAllNames | ( | ) |
Definition at line 223 of file DatabaseSession.cc.
{ return m_schema->namingServiceTable().eraseAllNames(); }
bool ora::DatabaseSession::eraseObjectName | ( | const std::string & | name | ) |
Definition at line 219 of file DatabaseSession.cc.
bool ora::DatabaseSession::exists | ( | ) |
Definition at line 141 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 227 of file DatabaseSession.cc.
References cont, and runTheMatrix::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 246 of file DatabaseSession.cc.
References cont, and runTheMatrix::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 237 of file DatabaseSession.cc.
bool ora::DatabaseSession::getNamesForContainer | ( | int | containerId, |
std::vector< std::string > & | destination | ||
) |
Definition at line 264 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 269 of file DatabaseSession.cc.
{ return m_schema->namingServiceTable().getNamesForObject( containerId, itemId, destination ); }
bool ora::DatabaseSession::isConnected | ( | ) |
Definition at line 96 of file DatabaseSession.cc.
{ return m_dbSession.isValid(); }
bool ora::DatabaseSession::isTransactionActive | ( | bool | checkIfReadOnly = false | ) |
Definition at line 129 of file DatabaseSession.cc.
References runTheMatrix::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 275 of file DatabaseSession.cc.
{ return m_schema->namingServiceTable().getAllNames( destination ); }
ora::MappingDatabase & ora::DatabaseSession::mappingDatabase | ( | ) |
Definition at line 296 of file DatabaseSession.cc.
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
{ return *m_mappingDb; }
void ora::DatabaseSession::open | ( | ) |
Definition at line 158 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_transactionCache->setLoaded(); } }
void ora::DatabaseSession::rollbackTransaction | ( | ) |
Definition at line 122 of file DatabaseSession.cc.
{ if( m_transactionCache.get() ){ m_dbSession.get().transaction().rollback(); clearTransaction(); } }
ora::IDatabaseSchema & ora::DatabaseSession::schema | ( | ) |
Definition at line 288 of file DatabaseSession.cc.
{ return *m_schema; }
void ora::DatabaseSession::setObjectName | ( | const std::string & | name, |
int | containerId, | ||
int | itemId | ||
) |
Definition at line 213 of file DatabaseSession.cc.
void ora::DatabaseSession::startTransaction | ( | bool | readOnly | ) |
Definition at line 104 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 ); } }
ora::SharedSession & ora::DatabaseSession::storageAccessSession | ( | ) |
Definition at line 304 of file DatabaseSession.cc.
{ return m_dbSession; }
ora::Handle< ora::DatabaseUtilitySession > ora::DatabaseSession::utility | ( | ) |
Definition at line 280 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 132 of file DatabaseSession.h.
boost::shared_ptr<ConnectionPool> ora::DatabaseSession::m_connectionPool [private] |
Definition at line 124 of file DatabaseSession.h.
Referenced by DatabaseSession().
std::string ora::DatabaseSession::m_connectionString [private] |
Definition at line 126 of file DatabaseSession.h.
Definition at line 131 of file DatabaseSession.h.
std::auto_ptr<NamedSequence> ora::DatabaseSession::m_contIdSequence [private] |
Definition at line 128 of file DatabaseSession.h.
Definition at line 125 of file DatabaseSession.h.
std::auto_ptr<MappingDatabase> ora::DatabaseSession::m_mappingDb [private] |
Definition at line 129 of file DatabaseSession.h.
std::auto_ptr<IDatabaseSchema> ora::DatabaseSession::m_schema [private] |
Definition at line 127 of file DatabaseSession.h.
std::auto_ptr<TransactionCache> ora::DatabaseSession::m_transactionCache [private] |
Definition at line 130 of file DatabaseSession.h.