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 Reflex::Type &containerType, 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 294 of file DatabaseContainer.cc.

298  :
299  m_dbSchema( session.schema() ),
300  m_schema( new ContainerSchema(contId, containerName, className, session) ),
301  m_writeBuffer(),
302  m_updateBuffer(),
303  m_readBuffer(),
304  m_deleteBuffer(),
306  m_size( containerSize ),
307  m_containerUpdateTable( session.containerUpdateTable() ),
308  m_lock( false ){
309 }
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
Handle< IteratorBuffer > m_iteratorBuffer
ora::DatabaseContainer::DatabaseContainer ( int  contId,
const std::string &  containerName,
const Reflex::Type &  containerType,
DatabaseSession session 
)

Definition at line 311 of file DatabaseContainer.cc.

314  :
315  m_dbSchema( session.schema() ),
316  m_schema( new ContainerSchema(contId, containerName, containerType, session) ),
317  m_writeBuffer(),
318  m_updateBuffer(),
319  m_readBuffer(),
320  m_deleteBuffer(),
322  m_size(0),
323  m_containerUpdateTable( session.containerUpdateTable() ),
324  m_lock( false ) {
325 }
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
Handle< IteratorBuffer > m_iteratorBuffer
ora::DatabaseContainer::~DatabaseContainer ( )
virtual

Definition at line 327 of file DatabaseContainer.cc.

327  {
328  m_iteratorBuffer.clear();
329 }
Handle< IteratorBuffer > m_iteratorBuffer

Member Function Documentation

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

Definition at line 339 of file DatabaseContainer.cc.

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

339  {
340  return m_schema->className();
341 }
std::auto_ptr< ContainerSchema > m_schema
void ora::DatabaseContainer::create ( )

Definition at line 381 of file DatabaseContainer.cc.

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

381  {
382  m_schema->create();
383 }
std::auto_ptr< ContainerSchema > m_schema
void ora::DatabaseContainer::drop ( )

Definition at line 385 of file DatabaseContainer.cc.

References ora::throwException().

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

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

Definition at line 458 of file DatabaseContainer.cc.

458  {
459  if(!m_deleteBuffer.get()){
460  m_deleteBuffer.reset( new DeleteBuffer( *m_schema ) );
461  }
462  m_deleteBuffer->registerForDelete( itemId );
463 }
std::auto_ptr< DeleteBuffer > m_deleteBuffer
std::auto_ptr< ContainerSchema > m_schema
void ora::DatabaseContainer::extendSchema ( const Reflex::Type &  dependentType)

Definition at line 394 of file DatabaseContainer.cc.

394  {
395  m_schema->extendIfRequired( dependentType );
396 }
std::auto_ptr< ContainerSchema > m_schema
void * ora::DatabaseContainer::fetchItem ( int  itemId)

Definition at line 403 of file DatabaseContainer.cc.

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

403  {
404 
405  if(!m_readBuffer.get()){
406  m_readBuffer.reset( new ReadBuffer( *m_schema ) );
407  }
408  return m_readBuffer->read( itemId );
409 }
std::auto_ptr< ContainerSchema > m_schema
std::auto_ptr< ReadBuffer > m_readBuffer
void * ora::DatabaseContainer::fetchItemAsType ( int  itemId,
const Reflex::Type &  asType 
)

Definition at line 411 of file DatabaseContainer.cc.

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

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

412  {
413  if(!m_readBuffer.get()){
414  m_readBuffer.reset( new ReadBuffer( *m_schema ) );
415  }
416  if( !ClassUtils::isType( type(), asType ) ){
417  throwException("Provided output object type \""+asType.Name(Reflex::SCOPED)+"\" does not match with the container type \""+
418  type().Name(Reflex::SCOPED)+"\"","DatabaseContainer::fetchItemAsType");
419  }
420  return m_readBuffer->read( itemId );
421 }
const Reflex::Type & type()
std::auto_ptr< ContainerSchema > m_schema
std::auto_ptr< ReadBuffer > m_readBuffer
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
bool isType(const Reflex::Type &type, const Reflex::Type &baseType)
Definition: ClassUtils.cc:45
void ora::DatabaseContainer::flush ( )

Definition at line 465 of file DatabaseContainer.cc.

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

465  {
466  size_t prevSize = m_size;
467  if(m_writeBuffer.get()) m_size += m_writeBuffer->flush();
468  if(m_updateBuffer.get()) m_updateBuffer->flush();
469  if(m_deleteBuffer.get()) m_size -= m_deleteBuffer->flush();
470  m_schema->containerSequences().sinchronizeAll();
471  if( prevSize != m_size ){
473  }
474 }
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 481 of file DatabaseContainer.cc.

481  {
482  return m_schema->dbSession().getNamesForContainer( m_schema->containerId(), destination );
483 }
std::auto_ptr< ContainerSchema > m_schema
int ora::DatabaseContainer::id ( void  )
int ora::DatabaseContainer::insertItem ( const void *  data,
const Reflex::Type &  type 
)

Definition at line 423 of file DatabaseContainer.cc.

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

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

424  {
425  if(!m_writeBuffer.get()){
426  m_writeBuffer.reset( new WriteBuffer( *m_schema ) );
427  }
429  Reflex::Type contType = ClassUtils::resolvedType(m_schema->type());
430  if( inputResType.Name()!= contType.Name() && !inputResType.HasBase( contType ) ){
431  throwException( "Provided input object type=\""+inputResType.Name()+
432  "\" does not match with the container type=\""+contType.Name()+"\"",
433  "DatabaseContainer::insertItem" );
434  }
435 
436  int newId = m_schema->containerSequences().getNextId( MappingRules::sequenceNameForContainer( m_schema->containerName()) );
437  m_writeBuffer->registerForWrite( newId, data );
438  return newId;
439 }
std::auto_ptr< WriteBuffer > m_writeBuffer
std::auto_ptr< ContainerSchema > m_schema
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:404
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static std::string sequenceNameForContainer(const std::string &containerName)
Definition: MappingRules.cc:14
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
bool ora::DatabaseContainer::isLocked ( )

Definition at line 377 of file DatabaseContainer.cc.

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

Definition at line 355 of file DatabaseContainer.cc.

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

355  {
356  if(!m_readBuffer.get()){
357  m_readBuffer.reset( new ReadBuffer( *m_schema ) );
358  }
359  if( !m_iteratorBuffer ){
360  m_iteratorBuffer.reset( new IteratorBuffer(*m_schema, *m_readBuffer ) );
361  m_iteratorBuffer->reset();
362  }
363  return m_iteratorBuffer;
364 }
std::auto_ptr< ContainerSchema > m_schema
std::auto_ptr< ReadBuffer > m_readBuffer
Handle< IteratorBuffer > m_iteratorBuffer
bool ora::DatabaseContainer::lock ( )

Definition at line 366 of file DatabaseContainer.cc.

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

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

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

Definition at line 347 of file DatabaseContainer.cc.

347  {
348  return m_schema->mappingVersion();
349 }
std::auto_ptr< ContainerSchema > m_schema
const std::string & ora::DatabaseContainer::name ( )

Definition at line 335 of file DatabaseContainer.cc.

Referenced by Vispa.Views.PropertyView.Property::valueChanged().

335  {
336  return m_schema->containerName();
337 }
std::auto_ptr< ContainerSchema > m_schema
void ora::DatabaseContainer::setAccessPermission ( const std::string &  principal,
bool  forWrite 
)

Definition at line 398 of file DatabaseContainer.cc.

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

Definition at line 476 of file DatabaseContainer.cc.

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

Definition at line 351 of file DatabaseContainer.cc.

351  {
352  return m_size;
353 }
const Reflex::Type & ora::DatabaseContainer::type ( )
void ora::DatabaseContainer::updateItem ( int  itemId,
const void *  data,
const Reflex::Type &  type 
)

Definition at line 441 of file DatabaseContainer.cc.

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

443  {
444  if(!m_updateBuffer.get()){
445  m_updateBuffer.reset( new UpdateBuffer( *m_schema ) );
446  }
448  Reflex::Type contType = ClassUtils::resolvedType(m_schema->type());
449  if( inputResType.Name()!= contType.Name() && !inputResType.HasBase( contType ) ){
450  throwException( "Provided input object type=\""+inputResType.Name()+"\" does not match with the container type=\""+
451  contType.Name()+"\".",
452  "DatabaseContainer::updateItem" );
453  }
454 
455  m_updateBuffer->registerForUpdate( itemId, data );
456 }
std::auto_ptr< ContainerSchema > m_schema
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:404
std::auto_ptr< UpdateBuffer > m_updateBuffer
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void throwException(const std::string &message, const std::string &methodName)
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.