16 #include "CoralBase/Attribute.h"
18 #include <boost/lexical_cast.hpp>
33 m_buffer.push_back( std::make_pair(oid, data ) );
46 if( iMap == topLevelMapping.
end()){
49 "WriteBuffer::flush");
54 std::auto_ptr<IRelationalWriter> writer( streamerFactory.
newWriter( type, mapping ) );
55 writer->build( topLevelElement, *topLevelInsert, operationBuffer );
57 for( std::vector<std::pair<int, const void*> >::const_iterator iW =
m_buffer.begin();
60 const void*
data = iW->second;
61 coral::AttributeList& dataBuff = topLevelInsert->data();
62 dataBuff.begin()->data<
int>() = oid;
63 writer->write( oid, data );
64 if( operationBuffer.flush() ) nobj++;
73 std::vector<std::pair<int, const void*> >
m_buffer;
90 m_buffer.push_back( std::make_pair( oid, data ));
98 std::vector<MappingElement> dependentMappings;
101 depDeleter.
build( operationBuffer );
102 dependentMappings.clear();
111 if( iMap == topLevelMapping.
end()){
114 "UpdateBuffer::flush");
119 std::auto_ptr<IRelationalUpdater> updater( streamerFactory.
newUpdater( type, mapping ));
120 updater->build( topLevelElement, *topLevelUpdate, operationBuffer );
121 for( std::vector<std::pair<int, const void*> >::const_iterator iU =
m_buffer.begin();
124 const void*
data = iU->second;
126 depDeleter.
erase( oid );
127 coral::AttributeList& dataBuff = topLevelUpdate->
data();
128 dataBuff.begin()->data<
int>() = oid;
129 coral::AttributeList& whereDataBuff = topLevelUpdate->
whereData();
130 whereDataBuff.begin()->data<
int>() = oid;
131 updater->update( oid, data );
132 if( operationBuffer.flush()) nobj++;
140 std::vector<std::pair<int, const void*> >
m_buffer;
156 if( iMap == topLevelMapping.
end()){
159 "ReadBuffer::ReadBuffer");
172 dataBuff.begin()->data<
int>() = oid;
175 void* destination = 0;
180 throwException(
"Object with item id "+boost::lexical_cast<std::string>(oid)+
" has not been found in the database.",
219 mainDeleter.
build( operationBuffer );
220 std::vector<MappingElement> dependentMappings;
223 depDeleter.
build( operationBuffer );
224 dependentMappings.clear();
226 for( std::vector<int>::const_iterator iD =
m_buffer.begin();
228 depDeleter.
erase( *iD );
229 mainDeleter.erase( *iD );
230 if( operationBuffer.flush() ) nobj++;
246 m_query( schema.mapping().topElement().
tableName(), schema.storageSchema() ),
248 m_readBuffer( buffer ){
262 bool prevValid = (m_itemId != -1);
263 bool currValid =
false;
265 if( m_query.nextCursorRow() ){
266 coral::AttributeList& row = m_query.data();
267 m_itemId = row.begin()->data<
int>();
271 if( !currValid && prevValid ) m_query.clear();
277 if( m_itemId != -1 ){
278 ret = m_readBuffer.read( m_itemId );
285 throwException(
"Provided output object type \""+asType.
cppName()+
"\" does not match with the container type \""+
type().cppName(),
286 "ora::IteratorBuffer::getItemsAsType" );
296 return m_readBuffer.type();
302 unsigned int containerSize,
304 m_dbSchema( session.
schema() ),
305 m_schema( new
ContainerSchema(contId, containerName, className, session) ),
311 m_size( containerSize ),
312 m_containerUpdateTable( session.containerUpdateTable() ),
320 m_dbSchema( session.
schema() ),
321 m_schema( new
ContainerSchema(contId, containerName, containerType, session) ),
328 m_containerUpdateTable( session.containerUpdateTable() ),
333 m_iteratorBuffer.clear();
337 return m_schema->containerId();
341 return m_schema->containerName();
345 return m_schema->className();
349 return m_schema->type();
353 return m_schema->mappingVersion();
361 if(!m_readBuffer.get()){
362 m_readBuffer.reset(
new ReadBuffer( *m_schema ) );
364 if( !m_iteratorBuffer ){
365 m_iteratorBuffer.reset(
new IteratorBuffer(*m_schema, *m_readBuffer ) );
366 m_iteratorBuffer->reset();
368 return m_iteratorBuffer;
374 m_lock = m_dbSchema.containerHeaderTable().lockContainer( m_schema->containerId(), headerData );
375 if(!m_lock)
throwException(
"Container \""+
name()+
"\" has been dropped.",
"DatabaseContainer::lock()");
391 if(!m_schema->dbSession().testDropPermission()){
392 throwException(
"Drop permission has been denied for the current user.",
393 "DatabaseContainer::drop");
396 m_containerUpdateTable.remove( m_schema->containerId() );
400 m_schema->extendIfRequired( dependentType );
405 m_schema->setAccessPermission( principal, forWrite );
410 if(!m_readBuffer.get()){
411 m_readBuffer.reset(
new ReadBuffer( *m_schema ) );
413 return m_readBuffer->read( itemId );
418 if(!m_readBuffer.get()){
419 m_readBuffer.reset(
new ReadBuffer( *m_schema ) );
422 throwException(
"Provided output object type \""+asType.
cppName()+
"\" does not match with the container type \""+
type().cppName(),
423 "ora::DatabaseContainer::fetchItemAsType" );
425 return m_readBuffer->read( itemId );
430 if(!m_writeBuffer.get()){
431 m_writeBuffer.reset(
new WriteBuffer( *m_schema ) );
435 if( inputResType.
name()!= contType.
name() && !inputResType.
hasBase( contType ) ){
437 "\" does not match with the container type=\""+contType.
name()+
"\"",
438 "DatabaseContainer::insertItem" );
442 m_writeBuffer->registerForWrite( newId, data );
449 if(!m_updateBuffer.get()){
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" );
460 m_updateBuffer->registerForUpdate( itemId, data );
464 if(!m_deleteBuffer.get()){
467 m_deleteBuffer->registerForDelete( itemId );
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 ){
477 m_containerUpdateTable.takeNote(
id(), m_size );
483 m_schema->dbSession().setObjectName( name, m_schema->containerId(), itemId );
487 return m_schema->dbSession().getNamesForContainer( m_schema->containerId(), destination );
void registerForUpdate(int oid, const void *data)
edm::TypeWithDict resolvedType(const edm::TypeWithDict &typ)
const std::string & name()
DatabaseContainer(int contId, const std::string &containerName, const std::string &className, unsigned int containerSize, DatabaseSession &session)
WriteBuffer(ContainerSchema &contSchema)
virtual ~DatabaseContainer()
ContainerSchema & m_contSchema
UpdateBuffer(ContainerSchema &contSchema)
bool getNames(std::vector< std::string > &destination)
const edm::TypeWithDict & type()
DataElement m_topLevelElement
const edm::TypeWithDict & type()
const edm::TypeWithDict & type()
ContainerSchema & m_contSchema
bool hasBase(std::string const &) const
ReadBuffer(ContainerSchema &contSchema)
int addWhereId(const std::string &columnName)
bool isType(const edm::TypeWithDict &type, const edm::TypeWithDict &baseType)
std::string cppName() const
int insertItem(const void *data, const edm::TypeWithDict &type)
bool mappingForDependentClasses(std::vector< MappingElement > &destination)
const std::string & className()
const MappingElement & topElement() const
IRelationalWriter * newWriter(const edm::TypeWithDict &dataType, MappingElement &dataMapping)
std::vector< std::pair< int, const void * > > m_buffer
IteratorBuffer(ContainerSchema &schema, ReadBuffer &buffer)
iterator find(const std::string &key)
Retrieves a sub-element.
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
const std::vector< std::string > & columnNames() const
const edm::TypeWithDict & type()
const std::string & mappingVersion()
int addId(const std::string &columnName)
void build(RelationalBuffer &buffer)
void extendSchema(const edm::TypeWithDict &dependentType)
void addOrderId(const std::string &columnName)
std::vector< std::pair< int, const void * > > m_buffer
void setAccessPermission(const std::string &principal, bool forWrite)
std::vector< int > m_buffer
IRelationalReader * newReader(const edm::TypeWithDict &dataType, MappingElement &dataMapping)
void * fetchItem(int itemId)
coral::AttributeList & whereData()
void registerForWrite(int oid, const void *data)
coral::ISchema & storageSchema()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
IRelationalUpdater * newUpdater(const edm::TypeWithDict &dataType, MappingElement &dataMapping)
iterator end()
Returns an iterator in the end of the sequence.
void * constructObject(const edm::TypeWithDict &typ)
char data[epos_bytes_allocation]
void registerForDelete(int oid)
void updateItem(int itemId, const void *data, const edm::TypeWithDict &type)
void setItemName(const std::string &name, int itemId)
MappingTree & mapping(bool writeEnabled=false)
void * getItemAsType(const edm::TypeWithDict &type)
Handle< IteratorBuffer > iteratorBuffer()
static std::string sequenceNameForContainer(const std::string &containerName)
void * fetchItemAsType(int itemId, const edm::TypeWithDict &asType)
DeleteBuffer(ContainerSchema &contSchema)
const std::string & tableName() const
volatile std::atomic< bool > shutdown_flag false
std::auto_ptr< IRelationalReader > m_reader
ContainerSchema & m_contSchema
const edm::TypeWithDict & m_type
std::string className(const T &t)
SelectOperation m_topLevelQuery