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 ] );
70 std::string arrayTypeName = arrayType.Name();
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 );
108 size_t persistentSize = m_arrayHandler->persistentSize( data );
110 if ( containerSize == 0 || containerSize < persistentSize )
return;
112 size_t startElementIndex = m_arrayHandler->startElementIndex( data );
114 std::auto_ptr<IArrayIteratorHandler> iteratorHandler( m_arrayHandler->iterate( data ) );
116 InsertCache& bulkOperation = m_insertOperation->setUp( containerSize-startElementIndex+1 );
118 for (
size_t iIndex = startElementIndex; iIndex < containerSize; ++iIndex ) {
120 m_recordId[m_recordId.size()-1] = iIndex;
121 coral::AttributeList& dataBuff = m_insertOperation->data();
123 dataBuff[ columns[0] ].data<
int>() = oid;
124 for(
size_t i = 1;
i < columns.size();
i++ ){
125 dataBuff[ columns[
i] ].data<
int>() = m_recordId[
i-1];
128 void* objectReference = iteratorHandler->object();
130 m_dataWriter->setRecordId( m_recordId );
131 m_dataWriter->write( oid, objectReference );
135 iteratorHandler->increment();
138 m_arrayHandler->finalize( const_cast<void*>( data ) );
145 m_deleter( mapping ),
146 m_writer( objectType, mapping, contSchema ){
155 m_deleter.build( operationBuffer );
156 m_writer.build( offset, relationalData, operationBuffer );
161 m_writer.setRecordId( identity );
166 m_deleter.erase( oid );
167 m_writer.write( oid, data );
173 m_objectType( objectType ),
174 m_mappingElement( mapping ),
175 m_schema( contSchema ),
190 m_localElement.clear();
194 m_recordId.push_back(0);
200 if ( ! arrayType || !arrayResolvedType ) {
201 throwException(
"Missing dictionary information for the element type of the array \"" +
202 m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) +
"\"",
203 "CArrayReader::build" );
210 m_query->addWhereId( m_mappingElement.pkColumn() );
211 std::vector<std::string> recIdCols = m_mappingElement.recordIdColumns();
212 for(
size_t i=0;
i<recIdCols.size();
i++ ){
213 m_query->addId( recIdCols[
i ] );
214 m_query->addOrderId( recIdCols[ i ] );
221 std::string arrayTypeName = arrayType.Name();
225 if ( iMe == m_mappingElement.end() ) {
226 throwException(
"Item for \"" + arrayTypeName +
"\" not found in the mapping element",
227 "CArrayReader::build" );
230 m_dataReader.reset( streamerFactory.
newReader( arrayResolvedType, iMe->second ) );
231 m_dataReader->build( m_localElement, *m_query );
238 "CArrayReader::select");
240 coral::AttributeList& whereData = m_query->whereData();
241 whereData[ m_mappingElement.pkColumn() ].data<
int>() = oid;
243 m_dataReader->select( oid );
248 for(
size_t i=0;
i<identity.size();
i++) {
249 m_recordId.push_back( identity[
i] );
252 m_recordId.push_back( 0 );
258 "CArrayReader::read");
260 void*
address = m_offset->address( destinationData );
262 Reflex::Type iteratorDereferenceReturnType = m_arrayHandler->iteratorReturnType();
264 bool isElementFundamental = iteratorDereferenceReturnType.IsFundamental();
266 std::string positionColumn = m_mappingElement.posColumn();
268 size_t arraySize = m_objectType.ArrayLength();
270 m_arrayHandler->clear( address );
272 size_t cursorSize = m_query->selectionSize(m_recordId, m_recordId.size()-1);
274 while ( i< cursorSize ){
276 m_recordId[m_recordId.size()-1] = (int)i;
277 m_query->selectRow( m_recordId );
278 coral::AttributeList& row = m_query->data();
280 int arrayIndex = row[positionColumn].data<
int >();
283 void* objectData = 0;
285 if(arrayIndex >= (
int)arraySize){
287 "CArrayReader::read");
292 objectData =
static_cast<char*
>(
address)+arrayIndex*iteratorDereferenceReturnType.SizeOf();
294 if(!isElementFundamental){
296 iteratorDereferenceReturnType.Construct(
Reflex::Type(0,0),std::vector< void* >(),objectData);
299 m_dataReader->setRecordId( m_recordId );
300 m_dataReader->read( objectData );
305 m_arrayHandler->finalize( address );
310 if(m_dataReader.get()) m_dataReader->clear();
316 m_objectType( objectType ),
317 m_mapping( mapping ),
318 m_schema( contSchema ){
325 return new CArrayWriter( m_objectType, m_mapping, m_schema );
329 return new CArrayUpdater( m_objectType, m_mapping, m_schema );
333 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 setRecordId(const std::vector< int > &identity)
void throwException(const std::string &message, const std::string &methodName)
IRelationalWriter * newWriter()
CArrayReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
void setRecordId(const std::vector< int > &identity)