15 #include "CoralBase/Attribute.h"
34 if( iMap == topLevelMapping.
end()){
36 type.Name(Reflex::SCOPED)+
"\"",
37 "WriteBuffer::WriteBuffer");
50 m_buffer.push_back( std::make_pair(oid, data ) );
55 for( std::vector<std::pair<int, const void*> >::const_iterator iW =
m_buffer.begin();
57 write( iW->first, iW->second );
67 dataBuff.begin()->data<
int>() = oid;
72 std::vector<std::pair<int, const void*> >
m_buffer;
89 std::vector<MappingElement> dependentMappings;
93 dependentMappings.clear();
102 if( iMap == topLevelMapping.
end()){
104 type.Name(Reflex::SCOPED)+
"\"",
105 "UpdateBuffer::UpdateBuffer");
118 m_buffer.push_back( std::make_pair( oid, data ));
124 for( std::vector<std::pair<int, const void*> >::const_iterator iU =
m_buffer.begin();
126 update( iU->first, iU->second );
139 dataBuff.begin()->data<
int>() = oid;
141 whereDataBuff.begin()->data<
int>() = oid;
147 std::vector<std::pair<int, const void*> >
m_buffer;
161 m_topLevelQuery( contSchema.mapping().topElement().tableName(), contSchema.storageSchema() ){
167 if( iMap == topLevelMapping.
end()){
169 m_type.Name(Reflex::SCOPED)+
"\"",
170 "ReadBuffer::ReadBuffer");
183 dataBuff.begin()->data<
int>() = oid;
186 void* destination = 0;
217 std::vector<MappingElement> dependentMappings;
221 dependentMappings.clear();
234 for( std::vector<int>::const_iterator iD =
m_buffer.begin();
255 m_query( schema.mapping().topElement().tableName(), schema.storageSchema() ),
257 m_readBuffer( buffer ){
271 bool prevValid = (m_itemId != -1);
272 bool currValid =
false;
274 if( m_query.nextCursorRow() ){
275 coral::AttributeList& row = m_query.data();
276 m_itemId = row.begin()->data<
int>();
280 if( !currValid && prevValid ) m_query.clear();
286 if( m_itemId != -1 ){
287 ret = m_readBuffer.read( m_itemId );
294 throwException(
"Provided output object type \""+asType.Name(Reflex::SCOPED)+
"\" does not match with the container type \""+
295 type().Name(Reflex::SCOPED)+
"\"",
"IteratorBuffer::getItemAsType");
305 return m_readBuffer.type();
309 const std::string& containerName,
311 unsigned int containerSize,
313 m_schema( new
ContainerSchema(contId, containerName, className, session) ),
319 m_size( containerSize ),
320 m_containerUpdateTable( session.containerUpdateTable() ){
324 const std::string& containerName,
327 m_schema( new
ContainerSchema(contId, containerName, containerType, session) ),
334 m_containerUpdateTable( session.containerUpdateTable() ){
338 m_iteratorBuffer.clear();
342 return m_schema->containerId();
346 return m_schema->containerName();
350 return m_schema->className();
354 return m_schema->type();
358 return m_schema->mappingVersion();
366 if(!m_readBuffer.get()){
367 m_readBuffer.reset(
new ReadBuffer( *m_schema ) );
369 if( !m_iteratorBuffer ){
370 m_iteratorBuffer.reset(
new IteratorBuffer(*m_schema, *m_readBuffer ) );
371 m_iteratorBuffer->reset();
373 return m_iteratorBuffer;
385 m_schema->extendIfRequired( dependentType );
390 if(!m_readBuffer.get()){
391 m_readBuffer.reset(
new ReadBuffer( *m_schema ) );
393 return m_readBuffer->read( itemId );
398 if(!m_readBuffer.get()){
399 m_readBuffer.reset(
new ReadBuffer( *m_schema ) );
402 throwException(
"Provided output object type \""+asType.Name(Reflex::SCOPED)+
"\" does not match with the container type \""+
403 type().Name(Reflex::SCOPED)+
"\"",
"DatabaseContainer::fetchItemAsType");
405 return m_readBuffer->read( itemId );
410 if(!m_writeBuffer.get()){
411 m_writeBuffer.reset(
new WriteBuffer( *m_schema ) );
415 if( inputResType.Name()!= contType.Name() && !inputResType.HasBase( contType ) ){
416 throwException(
"Provided input object type=\""+inputResType.Name()+
417 "\" does not match with the container type=\""+contType.Name()+
"\"",
418 "DatabaseContainer::insertItem" );
422 m_writeBuffer->registerForWrite( newId, data );
429 if(!m_updateBuffer.get()){
434 if( inputResType.Name()!= contType.Name() && !inputResType.HasBase( contType ) ){
435 throwException(
"Provided input object type=\""+inputResType.Name()+
"\" does not match with the container type=\""+
436 contType.Name()+
"\".",
437 "DatabaseContainer::updateItem" );
440 m_updateBuffer->registerForUpdate( itemId, data );
444 if(!m_deleteBuffer.get()){
447 m_deleteBuffer->registerForDelete( itemId );
451 size_t prevSize = m_size;
452 if(m_writeBuffer.get()) m_size += m_writeBuffer->flush();
453 if(m_updateBuffer.get()) m_updateBuffer->flush();
454 if(m_deleteBuffer.get()) m_size -= m_deleteBuffer->flush();
455 m_schema->containerSequences().sinchronizeAll();
456 if( prevSize != m_size ){
457 m_containerUpdateTable.takeNote(
id(), m_size );
463 m_schema->dbSession().setObjectName( name, m_schema->containerId(), itemId );
467 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)
std::auto_ptr< RelationalDeleter > m_depDeleter
const Reflex::Type & type()
std::auto_ptr< IRelationalWriter > m_writer
IRelationalReader * newReader(const Reflex::Type &dataType, MappingElement &dataMapping)
RelationalBuffer m_operationBuffer
void * constructObject(const Reflex::Type &typ)
void addId(const std::string &columnName)
virtual ~DatabaseContainer()
void write(int oid, const void *data)
void updateItem(int itemId, const void *data, const Reflex::Type &type)
DataElement m_topLevelElement
UpdateBuffer(ContainerSchema &contSchema)
int insertItem(const void *data, const Reflex::Type &type)
RelationalBuffer m_operationBuffer
bool getNames(std::vector< std::string > &destination)
void * getItemAsType(const Reflex::Type &type)
DataElement m_topLevelElement
const Reflex::Type & type()
ReadBuffer(ContainerSchema &contSchema)
InsertOperation & newInsert(const std::string &tableName)
std::auto_ptr< IRelationalUpdater > m_updater
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()
Reflex::Type resolvedType(const Reflex::Type &typ)
void addOrderId(const std::string &columnName)
std::vector< std::pair< int, const void * > > m_buffer
UpdateOperation * m_topLevelUpdate
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)
InsertOperation * m_topLevelInsert
void registerForWrite(int oid, const void *data)
void addWhereId(const std::string &columnName)
iterator end()
Returns an iterator in the end of the sequence.
std::auto_ptr< RelationalDeleter > m_depDeleter
void registerForDelete(int oid)
UpdateOperation & newUpdate(const std::string &tableName, bool addToResult=false)
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
RelationalBuffer m_operationBuffer
void update(int oid, const void *data)
std::auto_ptr< RelationalDeleter > m_mainDeleter
std::string className(const T &t)
SelectOperation m_topLevelQuery
bool isType(const Reflex::Type &type, const Reflex::Type &baseType)
DataElement m_topLevelElement