Go to the documentation of this file.00001 #include "RelationalBuffer.h"
00002 #include "RelationalOperation.h"
00003 #include "MultiRecordInsertOperation.h"
00004
00005 ora::RelationalBuffer::RelationalBuffer( coral::ISchema& schema ):
00006 m_schema( schema ),
00007 m_operations(),
00008 m_volatileBuffers(),
00009 m_blobBuffer(){
00010 }
00011
00012 ora::RelationalBuffer::~RelationalBuffer(){
00013 clear();
00014 }
00015
00016 ora::InsertOperation& ora::RelationalBuffer::newInsert( const std::string& tableName ){
00017 InsertOperation* newOperation = new InsertOperation( tableName, m_schema );
00018 m_operations.push_back( std::make_pair(newOperation,false) );
00019 return *newOperation;
00020 }
00021
00022 ora::BulkInsertOperation& ora::RelationalBuffer::newBulkInsert( const std::string& tableName ){
00023 BulkInsertOperation* newOperation = new BulkInsertOperation( tableName, m_schema );
00024 m_operations.push_back( std::make_pair(newOperation,false) );
00025 return *newOperation;
00026 }
00027
00028 ora::MultiRecordInsertOperation& ora::RelationalBuffer::newMultiRecordInsert( const std::string& tableName ){
00029 MultiRecordInsertOperation* newOperation = new MultiRecordInsertOperation( tableName, m_schema );
00030 m_operations.push_back( std::make_pair(newOperation,false) );
00031 return *newOperation;
00032 }
00033
00034 ora::UpdateOperation& ora::RelationalBuffer::newUpdate( const std::string& tableName,
00035 bool addToResult ){
00036 UpdateOperation* newOperation = new UpdateOperation( tableName, m_schema );
00037 m_operations.push_back( std::make_pair(newOperation,addToResult) );
00038 return *newOperation;
00039 }
00040
00041 ora::DeleteOperation& ora::RelationalBuffer::newDelete( const std::string& tableName,
00042 bool addToResult ){
00043 DeleteOperation* newOperation = new DeleteOperation( tableName, m_schema );
00044 m_operations.push_back( std::make_pair(newOperation,addToResult) );
00045 return *newOperation;
00046 }
00047
00048
00049 ora::RelationalBuffer& ora::RelationalBuffer::addVolatileBuffer(){
00050 RelationalBuffer* newBuffer = new RelationalBuffer( m_schema );
00051 m_volatileBuffers.push_back( newBuffer );
00052 return *newBuffer;
00053 }
00054
00055 void ora::RelationalBuffer::storeBlob( boost::shared_ptr<coral::Blob> blob ){
00056 m_blobBuffer.push_back( blob );
00057 }
00058
00059 void ora::RelationalBuffer::clear(){
00060 for( std::vector< std::pair<IRelationalOperation*,bool> >::const_iterator iOp = m_operations.begin();
00061 iOp != m_operations.end(); ++iOp ){
00062 delete iOp->first;
00063 }
00064 m_operations.clear();
00065 for( std::vector<RelationalBuffer*>::const_iterator iV = m_volatileBuffers.begin() ;
00066 iV != m_volatileBuffers.end(); ++iV ){
00067 delete *iV;
00068 }
00069 m_volatileBuffers.clear();
00070 m_blobBuffer.clear();
00071 }
00072
00073 bool ora::RelationalBuffer::flush(){
00074 bool ret = true;
00075 bool go = true;
00076 std::vector< std::pair<IRelationalOperation*,bool> >::const_iterator iOp = m_operations.begin();
00077 if( iOp != m_operations.end() ){
00078 bool ok = (iOp->first)->execute();
00079 go = ok || !(iOp->first)->isRequired();
00080 ret = ret && (ok || !iOp->second);
00081 iOp++;
00082 }
00083 for( ; iOp != m_operations.end(); ++iOp ){
00084 if( go ){
00085 bool ok = (iOp->first)->execute();
00086 go = ok || !(iOp->first)->isRequired();
00087 ret = ret && (ok || !iOp->second);
00088 } else {
00089 (iOp->first)->reset();
00090 }
00091 }
00092 for( std::vector<RelationalBuffer*>::iterator iV = m_volatileBuffers.begin() ;
00093 iV != m_volatileBuffers.end(); ++iV ){
00094 (*iV)->flush();
00095 delete *iV;
00096 }
00097 m_volatileBuffers.clear();
00098 m_blobBuffer.clear();
00099 return ret;
00100 }
00101
00102