13 #include "CoralBase/Attribute.h"
14 #include "RelationalAccess/IBulkOperation.h"
15 #include "Reflex/Object.h"
20 m_objectType( objectType ),
21 m_mappingElement( mapping ),
22 m_schema( contSchema ),
26 m_insertOperation( 0 ),
38 m_localElement.clear();
41 m_recordId.push_back(0);
47 if ( ! arrayType || !arrayResolvedType ) {
48 throwException(
"Missing dictionary information for the element type of the array \"" +
49 m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) +
"\"",
50 "CArrayWriter::build" );
57 const std::vector<std::string>& columns = m_mappingElement.columnNames();
58 if( !columns.size() ){
60 "CArrayWriter::build");
62 for(
size_t i=0;
i<columns.size();
i++ ){
63 m_insertOperation->addId( columns[
i ] );
73 if ( iMe == m_mappingElement.end() ) {
74 throwException(
"Item for \"" + arrayTypeName +
"\" not found in the mapping element",
75 "CArrayWriter::build" );
78 m_dataWriter.reset( streamerFactory.
newWriter( arrayResolvedType, iMe->second ));
79 m_dataWriter->build( m_localElement, *m_insertOperation, operationBuffer );
85 for(
size_t i=0;
i<identity.size();
i++) {
86 m_recordId.push_back( identity[
i] );
88 m_recordId.push_back( 0 );
96 "CArrayWriter::write");
98 const std::vector<std::string>& columns = m_mappingElement.columnNames();
99 if( columns.size() != m_recordId.size()+1){
100 throwException(
"Record id elements provided are not matching with the mapped id columns.",
101 "CArrayWriter::write");
104 void*
data = m_offset->address( inputData );
107 size_t containerSize = m_arrayHandler->size( data );
109 if ( containerSize == 0 )
return;
111 size_t startElementIndex = m_arrayHandler->startElementIndex( data );
113 std::auto_ptr<IArrayIteratorHandler> iteratorHandler( m_arrayHandler->iterate( data ) );
115 InsertCache& bulkOperation = m_insertOperation->setUp( containerSize-startElementIndex+1 );
117 for (
size_t iIndex = startElementIndex; iIndex < containerSize; ++iIndex ) {
119 m_recordId[m_recordId.size()-1] = iIndex;
120 coral::AttributeList& dataBuff = m_insertOperation->data();
122 dataBuff[ columns[0] ].data<
int>() = oid;
123 for(
size_t i = 1;
i < columns.size();
i++ ){
124 dataBuff[ columns[
i] ].data<
int>() = m_recordId[
i-1];
127 void* objectReference = iteratorHandler->object();
129 m_dataWriter->setRecordId( m_recordId );
130 m_dataWriter->write( oid, objectReference );
134 iteratorHandler->increment();
137 m_arrayHandler->finalize( const_cast<void*>( data ) );
144 m_deleter( mapping ),
145 m_writer( objectType, mapping, contSchema ){
154 m_deleter.build( operationBuffer );
155 m_writer.build( offset, relationalData, operationBuffer );
160 m_writer.setRecordId( identity );
165 m_deleter.erase( oid );
166 m_writer.write( oid, data );
172 m_objectType( objectType ),
173 m_mappingElement( mapping ),
174 m_schema( contSchema ),
189 m_localElement.clear();
193 m_recordId.push_back(0);
199 if ( ! arrayType || !arrayResolvedType ) {
200 throwException(
"Missing dictionary information for the element type of the array \"" +
201 m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) +
"\"",
202 "CArrayReader::build" );
209 m_query->addWhereId( m_mappingElement.pkColumn() );
210 std::vector<std::string> recIdCols = m_mappingElement.recordIdColumns();
211 for(
size_t i=0;
i<recIdCols.size();
i++ ){
212 m_query->addId( recIdCols[
i ] );
213 m_query->addOrderId( recIdCols[ i ] );
224 if ( iMe == m_mappingElement.end() ) {
225 throwException(
"Item for \"" + arrayTypeName +
"\" not found in the mapping element",
226 "CArrayReader::build" );
229 m_dataReader.reset( streamerFactory.
newReader( arrayResolvedType, iMe->second ) );
230 m_dataReader->build( m_localElement, *m_query );
237 "CArrayReader::select");
239 coral::AttributeList& whereData = m_query->whereData();
240 whereData[ m_mappingElement.pkColumn() ].data<
int>() = oid;
242 m_dataReader->select( oid );
247 for(
size_t i=0;
i<identity.size();
i++) {
248 m_recordId.push_back( identity[
i] );
251 m_recordId.push_back( 0 );
257 "CArrayReader::read");
259 void* address = m_offset->address( destinationData );
261 Reflex::Type iteratorDereferenceReturnType = m_arrayHandler->iteratorReturnType();
263 bool isElementFundamental = iteratorDereferenceReturnType.IsFundamental();
265 std::string positionColumn = m_mappingElement.posColumn();
267 size_t arraySize = m_objectType.ArrayLength();
269 m_arrayHandler->clear( address );
271 size_t cursorSize = m_query->selectionSize(m_recordId, m_recordId.size()-1);
273 while ( i< cursorSize ){
275 m_recordId[m_recordId.size()-1] = (int)i;
276 m_query->selectRow( m_recordId );
277 coral::AttributeList& row = m_query->data();
279 int arrayIndex = row[positionColumn].data<
int >();
282 void* objectData = 0;
284 if(arrayIndex >= (
int)arraySize){
286 "CArrayReader::read");
291 objectData =
static_cast<char*
>(address)+arrayIndex*iteratorDereferenceReturnType.SizeOf();
293 if(!isElementFundamental){
295 iteratorDereferenceReturnType.Construct(
Reflex::Type(0,0),std::vector< void* >(),objectData);
298 m_dataReader->setRecordId( m_recordId );
299 m_dataReader->read( objectData );
304 m_arrayHandler->finalize( address );
309 if(m_dataReader.get()) m_dataReader->clear();
315 m_objectType( objectType ),
316 m_mapping( mapping ),
317 m_schema( contSchema ){
324 return new CArrayWriter( m_objectType, m_mapping, m_schema );
328 return new CArrayUpdater( m_objectType, m_mapping, m_schema );
332 return new CArrayReader( m_objectType, m_mapping, m_schema );
IRelationalReader * newReader()
IRelationalReader * newReader(const Reflex::Type &dataType, MappingElement &dataMapping)
bool build(DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
CArrayUpdater(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
void update(int oid, const void *data)
Updates a data element.
CArrayStreamer(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
void setRecordId(const std::vector< int > &identity)
static IArrayHandler * newArrayHandler(const Reflex::Type &arrayType)
void read(void *address)
Reads a data element.
void processNextIteration()
CArrayWriter(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
unsigned int offset(bool)
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
IRelationalUpdater * newUpdater()
MultiRecordInsertOperation & newMultiRecordInsert(const std::string &tableName)
Reflex::Type resolvedType(const Reflex::Type &typ)
IRelationalWriter * newWriter(const Reflex::Type &dataType, MappingElement &dataMapping)
bool build(DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
void write(int oid, const void *data)
Writes a data element.
bool build(DataElement &offset, IRelationalData &relationalData)
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
char data[epos_bytes_allocation]
void setRecordId(const std::vector< int > &identity)
IRelationalWriter * newWriter()
CArrayReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
void setRecordId(const std::vector< int > &identity)