CMS 3D CMS Logo

Public Member Functions | Private Attributes

ora::DatabaseContainer Class Reference

#include <DatabaseContainer.h>

List of all members.

Public Member Functions

const std::string & className ()
void create ()
 DatabaseContainer (int contId, const std::string &containerName, const Reflex::Type &containerType, DatabaseSession &session)
 DatabaseContainer (int contId, const std::string &containerName, const std::string &className, unsigned int containerSize, DatabaseSession &session)
void drop ()
void erase (int itemId)
void extendSchema (const Reflex::Type &dependentType)
void * fetchItem (int itemId)
void * fetchItemAsType (int itemId, const Reflex::Type &asType)
void flush ()
bool getNames (std::vector< std::string > &destination)
int id ()
int insertItem (const void *data, const Reflex::Type &type)
bool isLocked ()
Handle< IteratorBufferiteratorBuffer ()
bool lock ()
const std::string & mappingVersion ()
const std::string & name ()
void setAccessPermission (const std::string &principal, bool forWrite)
void setItemName (const std::string &name, int itemId)
size_t size ()
const Reflex::Type & type ()
void updateItem (int itemId, const void *data, const Reflex::Type &type)
virtual ~DatabaseContainer ()

Private Attributes

ContainerUpdateTablem_containerUpdateTable
IDatabaseSchemam_dbSchema
std::auto_ptr< DeleteBufferm_deleteBuffer
Handle< IteratorBufferm_iteratorBuffer
bool m_lock
std::auto_ptr< ReadBufferm_readBuffer
std::auto_ptr< ContainerSchemam_schema
size_t m_size
std::auto_ptr< UpdateBufferm_updateBuffer
std::auto_ptr< WriteBufferm_writeBuffer

Detailed Description

Definition at line 51 of file DatabaseContainer.h.


Constructor & Destructor Documentation

ora::DatabaseContainer::DatabaseContainer ( int  contId,
const std::string &  containerName,
const std::string &  className,
unsigned int  containerSize,
DatabaseSession session 
)

Definition at line 309 of file DatabaseContainer.cc.

                                                                     :
  m_dbSchema( session.schema() ),
  m_schema( new ContainerSchema(contId, containerName, className, session) ),
  m_writeBuffer(),
  m_updateBuffer(),
  m_readBuffer(),
  m_deleteBuffer(),
  m_iteratorBuffer(),
  m_size( containerSize ),
  m_containerUpdateTable( session.containerUpdateTable() ),
  m_lock( false ){
}
ora::DatabaseContainer::DatabaseContainer ( int  contId,
const std::string &  containerName,
const Reflex::Type &  containerType,
DatabaseSession session 
)

Definition at line 326 of file DatabaseContainer.cc.

                                                                     :
  m_dbSchema( session.schema() ),
  m_schema( new ContainerSchema(contId, containerName, containerType, session) ),
  m_writeBuffer(),
  m_updateBuffer(),
  m_readBuffer(),
  m_deleteBuffer(),
  m_iteratorBuffer(),
  m_size(0),
  m_containerUpdateTable( session.containerUpdateTable() ),
  m_lock( false ) {
}
ora::DatabaseContainer::~DatabaseContainer ( ) [virtual]

Definition at line 342 of file DatabaseContainer.cc.

                                        {
  m_iteratorBuffer.clear();
}

Member Function Documentation

const std::string & ora::DatabaseContainer::className ( )

Definition at line 354 of file DatabaseContainer.cc.

                                                {
  return m_schema->className();
}
void ora::DatabaseContainer::create ( )

Definition at line 396 of file DatabaseContainer.cc.

                                 {
  m_schema->create();
}
void ora::DatabaseContainer::drop ( )

Definition at line 400 of file DatabaseContainer.cc.

References ora::throwException().

                               {
  if(!m_schema->dbSession().testDropPermission()){
    throwException("Drop permission has been denied for the current user.",
                   "DatabaseContainer::drop");
  }
  m_schema->drop();
  m_containerUpdateTable.remove( m_schema->containerId() );
}
void ora::DatabaseContainer::erase ( int  itemId)

Definition at line 473 of file DatabaseContainer.cc.

                                            {
  if(!m_deleteBuffer.get()){
    m_deleteBuffer.reset( new DeleteBuffer( *m_schema ) );
  }
  m_deleteBuffer->registerForDelete( itemId );
}
void ora::DatabaseContainer::extendSchema ( const Reflex::Type &  dependentType)

Definition at line 409 of file DatabaseContainer.cc.

                                                                        {
  m_schema->extendIfRequired( dependentType );
}
void * ora::DatabaseContainer::fetchItem ( int  itemId)

Definition at line 418 of file DatabaseContainer.cc.

                                               {

  if(!m_readBuffer.get()){
    m_readBuffer.reset( new ReadBuffer( *m_schema ) );
  }
  return m_readBuffer->read( itemId );
}
void * ora::DatabaseContainer::fetchItemAsType ( int  itemId,
const Reflex::Type &  asType 
)

Definition at line 426 of file DatabaseContainer.cc.

References ora::ClassUtils::isType(), and ora::throwException().

                                                                       {
  if(!m_readBuffer.get()){
    m_readBuffer.reset( new ReadBuffer( *m_schema ) );
  }
  if( !ClassUtils::isType( type(), asType ) ){
    throwException("Provided output object type \""+asType.Name(Reflex::SCOPED)+"\" does not match with the container type \""+
                   type().Name(Reflex::SCOPED)+"\"","DatabaseContainer::fetchItemAsType");
  } 
  return m_readBuffer->read( itemId );
}
void ora::DatabaseContainer::flush ( )

Definition at line 480 of file DatabaseContainer.cc.

                                {
  size_t prevSize = m_size;
  if(m_writeBuffer.get()) m_size += m_writeBuffer->flush(); 
  if(m_updateBuffer.get()) m_updateBuffer->flush();
  if(m_deleteBuffer.get()) m_size -= m_deleteBuffer->flush();
  m_schema->containerSequences().sinchronizeAll();
  if( prevSize != m_size ){
    m_containerUpdateTable.takeNote( id(), m_size );
  }
}
bool ora::DatabaseContainer::getNames ( std::vector< std::string > &  destination)

Definition at line 496 of file DatabaseContainer.cc.

                                                                      {
  return m_schema->dbSession().getNamesForContainer( m_schema->containerId(), destination );
}
int ora::DatabaseContainer::id ( void  )

Definition at line 346 of file DatabaseContainer.cc.

                            {
  return m_schema->containerId();
}
int ora::DatabaseContainer::insertItem ( const void *  data,
const Reflex::Type &  type 
)

Definition at line 438 of file DatabaseContainer.cc.

References ora::ClassUtils::resolvedType(), ora::MappingRules::sequenceNameForContainer(), and ora::throwException().

                                                                    {
  if(!m_writeBuffer.get()){
    m_writeBuffer.reset( new WriteBuffer( *m_schema ) );
  }
  Reflex::Type inputResType = ClassUtils::resolvedType( dataType );
  Reflex::Type contType = ClassUtils::resolvedType(m_schema->type());
  if( inputResType.Name()!= contType.Name() && !inputResType.HasBase( contType ) ){
    throwException( "Provided input object type=\""+inputResType.Name()+
                    "\" does not match with the container type=\""+contType.Name()+"\"",
                    "DatabaseContainer::insertItem" );
  }

  int newId = m_schema->containerSequences().getNextId( MappingRules::sequenceNameForContainer( m_schema->containerName()) );
  m_writeBuffer->registerForWrite( newId, data );
  return newId;
}
bool ora::DatabaseContainer::isLocked ( )

Definition at line 392 of file DatabaseContainer.cc.

                                   {
  return m_lock;
}
ora::Handle< ora::IteratorBuffer > ora::DatabaseContainer::iteratorBuffer ( )

Definition at line 370 of file DatabaseContainer.cc.

References ora::Handle< T >::reset().

                                                                 {
  if(!m_readBuffer.get()){
    m_readBuffer.reset( new ReadBuffer( *m_schema ) );
  }
  if( !m_iteratorBuffer ){
    m_iteratorBuffer.reset( new IteratorBuffer(*m_schema, *m_readBuffer ) );
    m_iteratorBuffer->reset();
  }
  return m_iteratorBuffer;
}
bool ora::DatabaseContainer::lock ( )

Definition at line 381 of file DatabaseContainer.cc.

References mergeVDriftHistosByStation::name, ora::ContainerHeaderData::numberOfObjects, and ora::throwException().

                               {
  if( !m_lock ){
    ContainerHeaderData headerData;
    m_lock = m_dbSchema.containerHeaderTable().lockContainer( m_schema->containerId(), headerData );
    if(!m_lock) throwException("Container \""+name()+"\" has been dropped.","DatabaseContainer::lock()");
    // once the lock has been taken over, update the size in case has been changed...
    m_size = headerData.numberOfObjects;
  }
  return m_lock;
}
const std::string & ora::DatabaseContainer::mappingVersion ( )

Definition at line 362 of file DatabaseContainer.cc.

                                                     {
  return m_schema->mappingVersion();
}
const std::string & ora::DatabaseContainer::name ( )

Definition at line 350 of file DatabaseContainer.cc.

                                           {
  return m_schema->containerName();
}
void ora::DatabaseContainer::setAccessPermission ( const std::string &  principal,
bool  forWrite 
)

Definition at line 413 of file DatabaseContainer.cc.

                                                                 {
  m_schema->setAccessPermission( principal, forWrite );
}
void ora::DatabaseContainer::setItemName ( const std::string &  name,
int  itemId 
)

Definition at line 491 of file DatabaseContainer.cc.

                                                      {
  m_schema->dbSession().setObjectName( name, m_schema->containerId(), itemId );
}
size_t ora::DatabaseContainer::size ( void  )

Definition at line 366 of file DatabaseContainer.cc.

                                 {
  return m_size;
}
const Reflex::Type & ora::DatabaseContainer::type ( )

Definition at line 358 of file DatabaseContainer.cc.

                                            {
  return m_schema->type();
}
void ora::DatabaseContainer::updateItem ( int  itemId,
const void *  data,
const Reflex::Type &  type 
)

Definition at line 456 of file DatabaseContainer.cc.

References ora::ClassUtils::resolvedType(), and ora::throwException().

                                                                     {
  if(!m_updateBuffer.get()){
    m_updateBuffer.reset( new UpdateBuffer( *m_schema ) );
  }
  Reflex::Type inputResType = ClassUtils::resolvedType( dataType );
  Reflex::Type contType = ClassUtils::resolvedType(m_schema->type());
  if( inputResType.Name()!= contType.Name() && !inputResType.HasBase( contType ) ){
    throwException( "Provided input object type=\""+inputResType.Name()+"\" does not match with the container type=\""+
                    contType.Name()+"\".",
                    "DatabaseContainer::updateItem" );
  }

  m_updateBuffer->registerForUpdate( itemId, data );
}

Member Data Documentation

Definition at line 113 of file DatabaseContainer.h.

Definition at line 105 of file DatabaseContainer.h.

Definition at line 110 of file DatabaseContainer.h.

Definition at line 111 of file DatabaseContainer.h.

Definition at line 114 of file DatabaseContainer.h.

Definition at line 109 of file DatabaseContainer.h.

Definition at line 106 of file DatabaseContainer.h.

Definition at line 112 of file DatabaseContainer.h.

Definition at line 108 of file DatabaseContainer.h.

Definition at line 107 of file DatabaseContainer.h.