16 #include "CoralBase/Attribute.h"
31 m_buffer.push_back( std::make_pair(oid, data ) );
44 if( iMap == topLevelMapping.
end()){
46 type.Name(Reflex::SCOPED)+
"\"",
47 "WriteBuffer::flush");
52 std::auto_ptr<IRelationalWriter> writer( streamerFactory.
newWriter( type, mapping ) );
53 writer->build( topLevelElement, *topLevelInsert, operationBuffer );
55 for( std::vector<std::pair<int, const void*> >::const_iterator iW =
m_buffer.begin();
58 const void*
data = iW->second;
59 coral::AttributeList& dataBuff = topLevelInsert->data();
60 dataBuff.begin()->data<
int>() = oid;
61 writer->write( oid, data );
62 if( operationBuffer.flush() ) nobj++;
71 std::vector<std::pair<int, const void*> >
m_buffer;
88 m_buffer.push_back( std::make_pair( oid, data ));
96 std::vector<MappingElement> dependentMappings;
99 depDeleter.
build( operationBuffer );
100 dependentMappings.clear();
109 if( iMap == topLevelMapping.
end()){
111 type.Name(Reflex::SCOPED)+
"\"",
112 "UpdateBuffer::flush");
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();
122 const void*
data = iU->second;
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++;
138 std::vector<std::pair<int, const void*> >
m_buffer;
148 m_topLevelQuery( contSchema.mapping().topElement().tableName(), contSchema.storageSchema() ){
154 if( iMap == topLevelMapping.
end()){
156 m_type.Name(Reflex::SCOPED)+
"\"",
157 "ReadBuffer::ReadBuffer");
170 dataBuff.begin()->data<
int>() = oid;
173 void* destination = 0;
214 mainDeleter.
build( operationBuffer );
215 std::vector<MappingElement> dependentMappings;
218 depDeleter.
build( operationBuffer );
219 dependentMappings.clear();
221 for( std::vector<int>::const_iterator iD =
m_buffer.begin();
223 depDeleter.
erase( *iD );
224 mainDeleter.erase( *iD );
225 if( operationBuffer.flush() ) nobj++;
241 m_query( schema.mapping().topElement().tableName(), schema.storageSchema() ),
243 m_readBuffer( buffer ){
257 bool prevValid = (m_itemId != -1);
258 bool currValid =
false;
260 if( m_query.nextCursorRow() ){
261 coral::AttributeList& row = m_query.data();
262 m_itemId = row.begin()->data<
int>();
266 if( !currValid && prevValid ) m_query.clear();
272 if( m_itemId != -1 ){
273 ret = m_readBuffer.read( m_itemId );
280 throwException(
"Provided output object type \""+asType.Name(Reflex::SCOPED)+
"\" does not match with the container type \""+
281 type().Name(Reflex::SCOPED)+
"\"",
"IteratorBuffer::getItemAsType");
291 return m_readBuffer.type();
297 unsigned int containerSize,
299 m_dbSchema( session.
schema() ),
300 m_schema( new
ContainerSchema(contId, containerName, className, session) ),
306 m_size( containerSize ),
307 m_containerUpdateTable( session.containerUpdateTable() ),
315 m_dbSchema( session.
schema() ),
316 m_schema( new
ContainerSchema(contId, containerName, containerType, session) ),
323 m_containerUpdateTable( session.containerUpdateTable() ),
328 m_iteratorBuffer.clear();
332 return m_schema->containerId();
336 return m_schema->containerName();
340 return m_schema->className();
344 return m_schema->type();
348 return m_schema->mappingVersion();
356 if(!m_readBuffer.get()){
357 m_readBuffer.reset(
new ReadBuffer( *m_schema ) );
359 if( !m_iteratorBuffer ){
360 m_iteratorBuffer.reset(
new IteratorBuffer(*m_schema, *m_readBuffer ) );
361 m_iteratorBuffer->reset();
363 return m_iteratorBuffer;
369 m_lock = m_dbSchema.containerHeaderTable().lockContainer( m_schema->containerId(), headerData );
370 if(!m_lock)
throwException(
"Container \""+
name()+
"\" has been dropped.",
"DatabaseContainer::lock()");
386 if(!m_schema->dbSession().testDropPermission()){
387 throwException(
"Drop permission has been denied for the current user.",
388 "DatabaseContainer::drop");
391 m_containerUpdateTable.remove( m_schema->containerId() );
395 m_schema->extendIfRequired( dependentType );
400 m_schema->setAccessPermission( principal, forWrite );
405 if(!m_readBuffer.get()){
406 m_readBuffer.reset(
new ReadBuffer( *m_schema ) );
408 return m_readBuffer->read( itemId );
413 if(!m_readBuffer.get()){
414 m_readBuffer.reset(
new ReadBuffer( *m_schema ) );
417 throwException(
"Provided output object type \""+asType.Name(Reflex::SCOPED)+
"\" does not match with the container type \""+
418 type().Name(Reflex::SCOPED)+
"\"",
"DatabaseContainer::fetchItemAsType");
420 return m_readBuffer->read( itemId );
425 if(!m_writeBuffer.get()){
426 m_writeBuffer.reset(
new WriteBuffer( *m_schema ) );
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" );
437 m_writeBuffer->registerForWrite( newId, data );
444 if(!m_updateBuffer.get()){
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" );
455 m_updateBuffer->registerForUpdate( itemId, data );
459 if(!m_deleteBuffer.get()){
462 m_deleteBuffer->registerForDelete( itemId );
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 ){
472 m_containerUpdateTable.takeNote(
id(), m_size );
478 m_schema->dbSession().setObjectName( name, m_schema->containerId(), itemId );
482 return m_schema->dbSession().getNamesForContainer( m_schema->containerId(), destination );
void registerForUpdate(int oid, const void *data)
const std::string & name()
DatabaseContainer(int contId, const std::string &containerName, const std::string &className, unsigned int containerSize, DatabaseSession &session)
WriteBuffer(ContainerSchema &contSchema)
const Reflex::Type & type()
IRelationalReader * newReader(const Reflex::Type &dataType, MappingElement &dataMapping)
void * constructObject(const Reflex::Type &typ)
virtual ~DatabaseContainer()
void updateItem(int itemId, const void *data, const Reflex::Type &type)
ContainerSchema & m_contSchema
UpdateBuffer(ContainerSchema &contSchema)
int insertItem(const void *data, const Reflex::Type &type)
bool getNames(std::vector< std::string > &destination)
void * getItemAsType(const Reflex::Type &type)
DataElement m_topLevelElement
ContainerSchema & m_contSchema
const Reflex::Type & type()
ReadBuffer(ContainerSchema &contSchema)
int addWhereId(const std::string &columnName)
const Reflex::Type & type()
bool mappingForDependentClasses(std::vector< MappingElement > &destination)
const std::string & className()
const MappingElement & topElement() const
void extendSchema(const Reflex::Type &dependentType)
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 std::string & mappingVersion()
int addId(const std::string &columnName)
void build(RelationalBuffer &buffer)
Reflex::Type resolvedType(const Reflex::Type &typ)
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
IRelationalWriter * newWriter(const Reflex::Type &dataType, MappingElement &dataMapping)
void * fetchItem(int itemId)
coral::AttributeList & whereData()
IRelationalUpdater * newUpdater(const Reflex::Type &dataType, MappingElement &dataMapping)
void registerForWrite(int oid, const void *data)
coral::ISchema & storageSchema()
iterator end()
Returns an iterator in the end of the sequence.
char data[epos_bytes_allocation]
void registerForDelete(int oid)
void setItemName(const std::string &name, int itemId)
MappingTree & mapping(bool writeEnabled=false)
Handle< IteratorBuffer > iteratorBuffer()
const Reflex::Type & m_type
void * fetchItemAsType(int itemId, const Reflex::Type &asType)
const Reflex::Type & type()
static std::string sequenceNameForContainer(const std::string &containerName)
DeleteBuffer(ContainerSchema &contSchema)
const std::string & tableName() const
void throwException(const std::string &message, const std::string &methodName)
std::auto_ptr< IRelationalReader > m_reader
ContainerSchema & m_contSchema
std::string className(const T &t)
SelectOperation m_topLevelQuery
bool isType(const Reflex::Type &type, const Reflex::Type &baseType)