CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

ora::Database Class Reference

#include <Database.h>

List of all members.

Public Member Functions

Configurationconfiguration ()
bool connect (const std::string &connectionString, bool readOnly=false)
const std::string & connectionString ()
Container containerHandle (const std::string &name)
Container containerHandle (int contId)
std::set< std::string > containers ()
bool create ()
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)
Databaseoperator= (const Database &rhs)
void setObjectName (const std::string &name, const OId &oid)
SharedSessionstorageAccessSession ()
Transactiontransaction ()
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< DatabaseImplm_impl

Detailed Description

Definition at line 28 of file Database.h.


Constructor & Destructor Documentation

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();
}

Member Function Documentation

void ora::Database::checkTransaction ( ) [private]

Definition at line 115 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 );
}
const std::string & ora::Database::connectionString ( )

Definition at line 104 of file Database.cc.

                                               {
  return m_impl->m_session->connectionString();
}
ora::Container ora::Database::containerHandle ( const std::string &  name)

Definition at line 236 of file Database.cc.

References cont, and ora::throwException().

Referenced by cond::IOVService::deleteAll(), cond::DbSession::getTypedObject(), cond::DbSession::storeObject(), and cond::DbSession::updateObject().

                                                                {
  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 246 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 165 of file Database.cc.

References Association::map.

                                            {
  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 ( )

Definition at line 129 of file Database.cc.

                        {
  bool created = false;
  if( !exists()){
    m_impl->m_session->create();
    created = true;
  }
  return created;
}
ora::Container ora::Database::createContainer ( const std::string &  className,
std::string  name = "" 
)

Definition at line 200 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 176 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 188 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 );
}
template<typename T >
ora::Container ora::Database::createContainer ( const std::string &  name) [inline]

Definition at line 188 of file Database.h.

References createContainer().

                                                                {
  return createContainer( name, typeid(T) );
}
template<typename T >
ora::Container ora::Database::createContainer ( ) [inline]

Definition at line 194 of file Database.h.

Referenced by createContainer().

                                         {
  return createContainer( typeid(T) );
}
void ora::Database::disconnect ( void  )

Definition at line 96 of file Database.cc.

                            {
  m_impl->m_session->disconnect();
}
bool ora::Database::drop ( )

Definition at line 138 of file Database.cc.

References edm::productstatus::dropped(), and Association::map.

                      {
  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 227 of file Database.cc.

                                                      {
  open();
  if( !m_impl->m_session->containerHandle( name ) ){
    return false;
  }  
  m_impl->m_session->dropContainer( name );
  return true;
}
void ora::Database::erase ( const OId oid)

Definition at line 278 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 303 of file Database.cc.

                               {
  open();
  return m_impl->m_session->eraseAllNames();
}
bool ora::Database::eraseObjectName ( const std::string &  name)

Definition at line 298 of file Database.cc.

                                                        {
  open();
  return m_impl->m_session->eraseObjectName( name );  
}
bool ora::Database::exists ( )

Definition at line 124 of file Database.cc.

                        {
  checkTransaction();
  return m_impl->m_session->exists();
}
template<typename T >
boost::shared_ptr< T > ora::Database::fetch ( const OId oid) [inline]

Definition at line 200 of file Database.h.

References cont, ora::OId::containerId(), ora::Container::fetch(), and ora::OId::itemId().

                                                       {
  Container cont = containerHandle( oid.containerId() );
  return cont.fetch<T>( oid.itemId() );
}
template<typename T >
boost::shared_ptr< T > ora::Database::fetchByName ( const std::string &  name) [inline]

Definition at line 232 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 258 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 319 of file Database.cc.

                                                             {
  open();
  return  m_impl->m_session->fetchObjectByName( name );
}
void ora::Database::flush ( )

Definition at line 284 of file Database.cc.

References Association::map.

Referenced by cond::DbSession::storeObject().

                       {
  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::string &  name,
const std::type_info &  typeInfo 
) [private]

Definition at line 213 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 );
}
ora::Container ora::Database::getContainer ( const std::type_info &  typeInfo) [private]

Definition at line 220 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);
}
bool ora::Database::getItemId ( const std::string &  name,
ora::OId destination 
)

Definition at line 308 of file Database.cc.

                                                                       {
  open();
  return m_impl->m_session->getItemId( name, destination );  
}
bool ora::Database::getNamesForObject ( const OId oid,
std::vector< std::string > &  destination 
)

Definition at line 324 of file Database.cc.

References ora::OId::containerId(), and ora::OId::itemId().

                                                                          {
  open();
  return m_impl->m_session->getNamesForObject( oid.containerId(), oid.itemId(), destination );
}
boost::shared_ptr< void > ora::Database::getTypedObjectByName ( const std::string &  name,
const std::type_info &  typeInfo 
) [private]

Definition at line 313 of file Database.cc.

References ora::ClassUtils::lookupDictionary().

                                                                                                            {
  open();
  Reflex::Type objType = ClassUtils::lookupDictionary( typeInfo );
  return m_impl->m_session->fetchTypedObjectByName( name, objType );
}
template<typename T >
ora::OId ora::Database::insert ( const std::string &  containerName,
const T &  data 
) [inline]

Definition at line 207 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 );
}
template<typename T >
ora::OId ora::Database::insert ( const T &  data) [inline]

Definition at line 216 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 );  
}
ora::OId ora::Database::insertItem ( const std::string &  containerName,
const Object data 
)

Definition at line 263 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 100 of file Database.cc.

                              {
  return m_impl->m_session->isConnected();
}
bool ora::Database::listObjectNames ( std::vector< std::string > &  destination)

Definition at line 330 of file Database.cc.

                                                                    {
  open();
  return m_impl->m_session->listObjectNames( destination );
}
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]

Definition at line 62 of file Database.cc.

References className().

                                                                   {
  return className;
}
void ora::Database::open ( bool  writingAccess = false) [private]

Definition at line 153 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;
}
void ora::Database::setObjectName ( const std::string &  name,
const OId oid 
)

Definition at line 293 of file Database.cc.

References ora::OId::containerId(), and ora::OId::itemId().

                                                                      {
  open( true );
  m_impl->m_session->setObjectName( name, oid.containerId(), oid.itemId() );
}
ora::SharedSession & ora::Database::storageAccessSession ( )

Definition at line 341 of file Database.cc.

                                                   {
  return m_impl->m_session->storageAccessSession();
}
ora::Transaction & ora::Database::transaction ( )

Definition at line 108 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;
}
template<typename T >
void ora::Database::update ( const OId oid,
const T &  data 
) [inline]

Definition at line 224 of file Database.h.

References cont, ora::OId::containerId(), runTheMatrix::data, ora::OId::itemId(), and ora::Container::update().

                                           {
  Container cont = containerHandle( oid.containerId() );
  cont.update( oid.itemId(), data );
}
void ora::Database::updateItem ( const OId oid,
const Object data 
)

Definition at line 271 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 335 of file Database.cc.

                                       {
  checkTransaction();
  Handle<DatabaseUtilitySession> utilSession = m_impl->m_session->utility();
  return DatabaseUtility( utilSession );
}

Member Data Documentation

boost::shared_ptr<DatabaseImpl> ora::Database::m_impl [private]

Definition at line 185 of file Database.h.

Referenced by operator=().