test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
ora::DatabaseContainer Class Reference

#include <DatabaseContainer.h>

Public Member Functions

const std::string & className ()
 
void create ()
 
 DatabaseContainer (int contId, const std::string &containerName, const std::string &className, unsigned int containerSize, DatabaseSession &session)
 
 DatabaseContainer (int contId, const std::string &containerName, const edm::TypeWithDict &containerType, DatabaseSession &session)
 
void drop ()
 
void erase (int itemId)
 
void extendSchema (const edm::TypeWithDict &dependentType)
 
void * fetchItem (int itemId)
 
void * fetchItemAsType (int itemId, const edm::TypeWithDict &asType)
 
void flush ()
 
bool getNames (std::vector< std::string > &destination)
 
int id ()
 
int insertItem (const void *data, const edm::TypeWithDict &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 edm::TypeWithDicttype ()
 
void updateItem (int itemId, const void *data, const edm::TypeWithDict &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 299 of file DatabaseContainer.cc.

303  :
304  m_dbSchema( session.schema() ),
305  m_schema( new ContainerSchema(contId, containerName, className, session) ),
306  m_writeBuffer(),
307  m_updateBuffer(),
308  m_readBuffer(),
309  m_deleteBuffer(),
311  m_size( containerSize ),
312  m_containerUpdateTable( session.containerUpdateTable() ),
313  m_lock( false ){
314 }
std::auto_ptr< WriteBuffer > m_writeBuffer
IDatabaseSchema & m_dbSchema
std::auto_ptr< DeleteBuffer > m_deleteBuffer
std::auto_ptr< ContainerSchema > m_schema
const std::string & className()
ContainerUpdateTable & m_containerUpdateTable
std::auto_ptr< ReadBuffer > m_readBuffer
std::auto_ptr< UpdateBuffer > m_updateBuffer
session
Definition: models.py:201
Handle< IteratorBuffer > m_iteratorBuffer
ora::DatabaseContainer::DatabaseContainer ( int  contId,
const std::string &  containerName,
const edm::TypeWithDict containerType,
DatabaseSession session 
)

Definition at line 316 of file DatabaseContainer.cc.

319  :
320  m_dbSchema( session.schema() ),
321  m_schema( new ContainerSchema(contId, containerName, containerType, session) ),
322  m_writeBuffer(),
323  m_updateBuffer(),
324  m_readBuffer(),
325  m_deleteBuffer(),
327  m_size(0),
328  m_containerUpdateTable( session.containerUpdateTable() ),
329  m_lock( false ) {
330 }
std::auto_ptr< WriteBuffer > m_writeBuffer
IDatabaseSchema & m_dbSchema
std::auto_ptr< DeleteBuffer > m_deleteBuffer
std::auto_ptr< ContainerSchema > m_schema
ContainerUpdateTable & m_containerUpdateTable
std::auto_ptr< ReadBuffer > m_readBuffer
std::auto_ptr< UpdateBuffer > m_updateBuffer
session
Definition: models.py:201
Handle< IteratorBuffer > m_iteratorBuffer
ora::DatabaseContainer::~DatabaseContainer ( )
virtual

Definition at line 332 of file DatabaseContainer.cc.

332  {
333  m_iteratorBuffer.clear();
334 }
Handle< IteratorBuffer > m_iteratorBuffer

Member Function Documentation

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

Definition at line 344 of file DatabaseContainer.cc.

Referenced by ora::DatabaseUtilitySession::importContainerSchema().

344  {
345  return m_schema->className();
346 }
std::auto_ptr< ContainerSchema > m_schema
void ora::DatabaseContainer::create ( )

Definition at line 386 of file DatabaseContainer.cc.

Referenced by ora::DatabaseSession::createContainer().

386  {
387  m_schema->create();
388 }
std::auto_ptr< ContainerSchema > m_schema
void ora::DatabaseContainer::drop ( )

Definition at line 390 of file DatabaseContainer.cc.

References ora::throwException().

Referenced by ora::DatabaseSession::dropContainer().

390  {
391  if(!m_schema->dbSession().testDropPermission()){
392  throwException("Drop permission has been denied for the current user.",
393  "DatabaseContainer::drop");
394  }
395  m_schema->drop();
396  m_containerUpdateTable.remove( m_schema->containerId() );
397 }
std::auto_ptr< ContainerSchema > m_schema
ContainerUpdateTable & m_containerUpdateTable
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
void ora::DatabaseContainer::erase ( int  itemId)

Definition at line 463 of file DatabaseContainer.cc.

463  {
464  if(!m_deleteBuffer.get()){
465  m_deleteBuffer.reset( new DeleteBuffer( *m_schema ) );
466  }
467  m_deleteBuffer->registerForDelete( itemId );
468 }
std::auto_ptr< DeleteBuffer > m_deleteBuffer
std::auto_ptr< ContainerSchema > m_schema
void ora::DatabaseContainer::extendSchema ( const edm::TypeWithDict dependentType)

Definition at line 399 of file DatabaseContainer.cc.

399  {
400  m_schema->extendIfRequired( dependentType );
401 }
std::auto_ptr< ContainerSchema > m_schema
void * ora::DatabaseContainer::fetchItem ( int  itemId)

Definition at line 408 of file DatabaseContainer.cc.

Referenced by ora::DatabaseSession::fetchObjectByName().

408  {
409 
410  if(!m_readBuffer.get()){
411  m_readBuffer.reset( new ReadBuffer( *m_schema ) );
412  }
413  return m_readBuffer->read( itemId );
414 }
std::auto_ptr< ContainerSchema > m_schema
std::auto_ptr< ReadBuffer > m_readBuffer
void * ora::DatabaseContainer::fetchItemAsType ( int  itemId,
const edm::TypeWithDict asType 
)

Definition at line 416 of file DatabaseContainer.cc.

References edm::TypeWithDict::cppName(), ora::ClassUtils::isType(), and ora::throwException().

Referenced by ora::DatabaseSession::fetchTypedObjectByName().

417  {
418  if(!m_readBuffer.get()){
419  m_readBuffer.reset( new ReadBuffer( *m_schema ) );
420  }
421  if( !ClassUtils::isType( type(), asType ) ){
422  throwException("Provided output object type \""+asType.cppName()+"\" does not match with the container type \""+type().cppName(),
423  "ora::DatabaseContainer::fetchItemAsType" );
424  }
425  return m_readBuffer->read( itemId );
426 }
const edm::TypeWithDict & type()
bool isType(const edm::TypeWithDict &type, const edm::TypeWithDict &baseType)
Definition: ClassUtils.cc:50
std::auto_ptr< ContainerSchema > m_schema
std::string cppName() const
std::auto_ptr< ReadBuffer > m_readBuffer
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
void ora::DatabaseContainer::flush ( )

Definition at line 470 of file DatabaseContainer.cc.

Referenced by ora::DatabaseUtilitySession::importContainer().

470  {
471  size_t prevSize = m_size;
472  if(m_writeBuffer.get()) m_size += m_writeBuffer->flush();
473  if(m_updateBuffer.get()) m_updateBuffer->flush();
474  if(m_deleteBuffer.get()) m_size -= m_deleteBuffer->flush();
475  m_schema->containerSequences().sinchronizeAll();
476  if( prevSize != m_size ){
478  }
479 }
std::auto_ptr< WriteBuffer > m_writeBuffer
void takeNote(int contId, unsigned int size)
std::auto_ptr< DeleteBuffer > m_deleteBuffer
std::auto_ptr< ContainerSchema > m_schema
ContainerUpdateTable & m_containerUpdateTable
std::auto_ptr< UpdateBuffer > m_updateBuffer
bool ora::DatabaseContainer::getNames ( std::vector< std::string > &  destination)

Definition at line 486 of file DatabaseContainer.cc.

References cmsStageWithFailover::destination.

486  {
487  return m_schema->dbSession().getNamesForContainer( m_schema->containerId(), destination );
488 }
std::auto_ptr< ContainerSchema > m_schema
int ora::DatabaseContainer::id ( )
int ora::DatabaseContainer::insertItem ( const void *  data,
const edm::TypeWithDict type 
)

Definition at line 428 of file DatabaseContainer.cc.

References edm::TypeWithDict::hasBase(), edm::TypeWithDict::name(), ora::ClassUtils::resolvedType(), ora::MappingRules::sequenceNameForContainer(), and ora::throwException().

Referenced by ora::DatabaseUtilitySession::importContainer().

429  {
430  if(!m_writeBuffer.get()){
431  m_writeBuffer.reset( new WriteBuffer( *m_schema ) );
432  }
435  if( inputResType.name()!= contType.name() && !inputResType.hasBase( contType ) ){
436  throwException( "Provided input object type=\""+inputResType.name()+
437  "\" does not match with the container type=\""+contType.name()+"\"",
438  "DatabaseContainer::insertItem" );
439  }
440 
441  int newId = m_schema->containerSequences().getNextId( MappingRules::sequenceNameForContainer( m_schema->containerName()) );
442  m_writeBuffer->registerForWrite( newId, data );
443  return newId;
444 }
edm::TypeWithDict resolvedType(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:486
std::auto_ptr< WriteBuffer > m_writeBuffer
bool hasBase(std::string const &) const
std::auto_ptr< ContainerSchema > m_schema
std::string name() const
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
static std::string sequenceNameForContainer(const std::string &containerName)
Definition: MappingRules.cc:15
bool ora::DatabaseContainer::isLocked ( )

Definition at line 382 of file DatabaseContainer.cc.

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

Definition at line 360 of file DatabaseContainer.cc.

Referenced by ora::DatabaseUtilitySession::importContainer().

360  {
361  if(!m_readBuffer.get()){
362  m_readBuffer.reset( new ReadBuffer( *m_schema ) );
363  }
364  if( !m_iteratorBuffer ){
365  m_iteratorBuffer.reset( new IteratorBuffer(*m_schema, *m_readBuffer ) );
366  m_iteratorBuffer->reset();
367  }
368  return m_iteratorBuffer;
369 }
std::auto_ptr< ContainerSchema > m_schema
std::auto_ptr< ReadBuffer > m_readBuffer
Handle< IteratorBuffer > m_iteratorBuffer
bool ora::DatabaseContainer::lock ( )

Definition at line 371 of file DatabaseContainer.cc.

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

Referenced by ora::Database::lockContainer().

371  {
372  if( !m_lock ){
373  ContainerHeaderData headerData;
374  m_lock = m_dbSchema.containerHeaderTable().lockContainer( m_schema->containerId(), headerData );
375  if(!m_lock) throwException("Container \""+name()+"\" has been dropped.","DatabaseContainer::lock()");
376  // once the lock has been taken over, update the size in case has been changed...
377  m_size = headerData.numberOfObjects;
378  }
379  return m_lock;
380 }
const std::string & name()
IDatabaseSchema & m_dbSchema
std::auto_ptr< ContainerSchema > m_schema
virtual bool lockContainer(int id, ContainerHeaderData &destination)=0
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
virtual IContainerHeaderTable & containerHeaderTable()=0
const std::string & ora::DatabaseContainer::mappingVersion ( )

Definition at line 352 of file DatabaseContainer.cc.

352  {
353  return m_schema->mappingVersion();
354 }
std::auto_ptr< ContainerSchema > m_schema
const std::string & ora::DatabaseContainer::name ( )
void ora::DatabaseContainer::setAccessPermission ( const std::string &  principal,
bool  forWrite 
)

Definition at line 403 of file DatabaseContainer.cc.

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

Definition at line 481 of file DatabaseContainer.cc.

482  {
483  m_schema->dbSession().setObjectName( name, m_schema->containerId(), itemId );
484 }
const std::string & name()
std::auto_ptr< ContainerSchema > m_schema
size_t ora::DatabaseContainer::size ( void  )

Definition at line 356 of file DatabaseContainer.cc.

356  {
357  return m_size;
358 }
const edm::TypeWithDict & ora::DatabaseContainer::type ( )
void ora::DatabaseContainer::updateItem ( int  itemId,
const void *  data,
const edm::TypeWithDict type 
)

Definition at line 446 of file DatabaseContainer.cc.

References edm::TypeWithDict::hasBase(), edm::TypeWithDict::name(), ora::ClassUtils::resolvedType(), and ora::throwException().

448  {
449  if(!m_updateBuffer.get()){
450  m_updateBuffer.reset( new UpdateBuffer( *m_schema ) );
451  }
454  if( inputResType.name()!= contType.name() && !inputResType.hasBase( contType ) ){
455  throwException( "Provided input object type=\""+inputResType.name()+"\" does not match with the container type=\""+
456  contType.name()+"\".",
457  "DatabaseContainer::updateItem" );
458  }
459 
460  m_updateBuffer->registerForUpdate( itemId, data );
461 }
edm::TypeWithDict resolvedType(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:486
bool hasBase(std::string const &) const
std::auto_ptr< ContainerSchema > m_schema
std::string name() const
std::auto_ptr< UpdateBuffer > m_updateBuffer
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10

Member Data Documentation

ContainerUpdateTable& ora::DatabaseContainer::m_containerUpdateTable
private

Definition at line 113 of file DatabaseContainer.h.

IDatabaseSchema& ora::DatabaseContainer::m_dbSchema
private

Definition at line 105 of file DatabaseContainer.h.

std::auto_ptr<DeleteBuffer> ora::DatabaseContainer::m_deleteBuffer
private

Definition at line 110 of file DatabaseContainer.h.

Handle<IteratorBuffer> ora::DatabaseContainer::m_iteratorBuffer
private

Definition at line 111 of file DatabaseContainer.h.

bool ora::DatabaseContainer::m_lock
private

Definition at line 114 of file DatabaseContainer.h.

std::auto_ptr<ReadBuffer> ora::DatabaseContainer::m_readBuffer
private

Definition at line 109 of file DatabaseContainer.h.

std::auto_ptr<ContainerSchema> ora::DatabaseContainer::m_schema
private

Definition at line 106 of file DatabaseContainer.h.

size_t ora::DatabaseContainer::m_size
private

Definition at line 112 of file DatabaseContainer.h.

std::auto_ptr<UpdateBuffer> ora::DatabaseContainer::m_updateBuffer
private

Definition at line 108 of file DatabaseContainer.h.

std::auto_ptr<WriteBuffer> ora::DatabaseContainer::m_writeBuffer
private

Definition at line 107 of file DatabaseContainer.h.