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::UpdateBuffer Class Reference

Public Member Functions

size_t flush ()
 
void registerForUpdate (int oid, const void *data)
 
 UpdateBuffer (ContainerSchema &contSchema)
 
 ~UpdateBuffer ()
 

Private Attributes

std::vector< std::pair< int,
const void * > > 
m_buffer
 
ContainerSchemam_contSchema
 

Detailed Description

Definition at line 76 of file DatabaseContainer.cc.

Constructor & Destructor Documentation

ora::UpdateBuffer::UpdateBuffer ( ContainerSchema contSchema)
inlineexplicit

Definition at line 78 of file DatabaseContainer.cc.

78  :
79  m_buffer(),
80  m_contSchema( contSchema ){
81  }
std::vector< std::pair< int, const void * > > m_buffer
ContainerSchema & m_contSchema
ora::UpdateBuffer::~UpdateBuffer ( )
inline

Definition at line 83 of file DatabaseContainer.cc.

83  {
84  }

Member Function Documentation

size_t ora::UpdateBuffer::flush ( )
inline

Definition at line 92 of file DatabaseContainer.cc.

References ora::InputRelationalData::addId(), ora::InputRelationalData::addWhereId(), ora::RelationalDeleter::build(), ora::MappingElement::columnNames(), ora::InputRelationalData::data(), data, ora::MappingElement::end(), ora::RelationalDeleter::erase(), ora::MappingElement::find(), m_buffer, m_contSchema, ora::ContainerSchema::mapping(), ora::ContainerSchema::mappingForDependentClasses(), ora::RelationalStreamerFactory::newUpdater(), ora::ContainerSchema::storageSchema(), ora::MappingElement::tableName(), ora::throwException(), ora::MappingTree::topElement(), funct::true, ora::ContainerSchema::type(), and ora::InputRelationalData::whereData().

92  {
93  size_t nobj = 0;
94  if( m_buffer.size() ){
95  RelationalBuffer operationBuffer( m_contSchema.storageSchema() );
96  std::vector<MappingElement> dependentMappings;
97  m_contSchema.mappingForDependentClasses( dependentMappings );
98  RelationalDeleter depDeleter( dependentMappings );
99  depDeleter.build( operationBuffer );
100  dependentMappings.clear();
101 
102  MappingElement& topLevelMapping = m_contSchema.mapping( true ).topElement();
103  UpdateOperation* topLevelUpdate = &operationBuffer.newUpdate( topLevelMapping.tableName(), true );
104  topLevelUpdate->addId( topLevelMapping.columnNames()[ 0 ] );
105  topLevelUpdate->addWhereId( topLevelMapping.columnNames()[ 0 ] );
106  const Reflex::Type& type = m_contSchema.type();
107  MappingElement::iterator iMap = topLevelMapping.find( type.Name(Reflex::SCOPED) );
108  // the first inner mapping is the relevant...
109  if( iMap == topLevelMapping.end()){
110  throwException("Could not find a mapping element for class \""+
111  type.Name(Reflex::SCOPED)+"\"",
112  "UpdateBuffer::flush");
113  }
114  MappingElement& mapping = iMap->second;
115  RelationalStreamerFactory streamerFactory( m_contSchema );
116  DataElement topLevelElement;
117  std::auto_ptr<IRelationalUpdater> updater( streamerFactory.newUpdater( type, mapping ));
118  updater->build( topLevelElement, *topLevelUpdate, operationBuffer );
119  for( std::vector<std::pair<int, const void*> >::const_iterator iU = m_buffer.begin();
120  iU != m_buffer.end(); ++iU ){
121  int oid = iU->first;
122  const void* data = iU->second;
123  // erase the dependencies (they cannot be updated...)
124  depDeleter.erase( oid );
125  coral::AttributeList& dataBuff = topLevelUpdate->data();
126  dataBuff.begin()->data<int>() = oid;
127  coral::AttributeList& whereDataBuff = topLevelUpdate->whereData();
128  whereDataBuff.begin()->data<int>() = oid;
129  updater->update( oid, data );
130  if( operationBuffer.flush()) nobj++;
131  }
132  m_buffer.clear();
133  }
134  return nobj;
135  }
type
Definition: HCALResponse.h:22
const Reflex::Type & type()
bool mappingForDependentClasses(std::vector< MappingElement > &destination)
const MappingElement & topElement() const
Definition: MappingTree.h:143
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
std::vector< std::pair< int, const void * > > m_buffer
coral::ISchema & storageSchema()
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
MappingTree & mapping(bool writeEnabled=false)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
ContainerSchema & m_contSchema
void ora::UpdateBuffer::registerForUpdate ( int  oid,
const void *  data 
)
inline

Definition at line 87 of file DatabaseContainer.cc.

References m_buffer.

87  {
88  m_buffer.push_back( std::make_pair( oid, data ));
89  }
std::vector< std::pair< int, const void * > > m_buffer
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82

Member Data Documentation

std::vector<std::pair<int, const void*> > ora::UpdateBuffer::m_buffer
private

Definition at line 138 of file DatabaseContainer.cc.

Referenced by flush(), and registerForUpdate().

ContainerSchema& ora::UpdateBuffer::m_contSchema
private

Definition at line 139 of file DatabaseContainer.cc.

Referenced by flush().