15 #include "CoralBase/Attribute.h"
16 #include "RelationalAccess/IBulkOperation.h"
22 m_objectType( objectType ),
23 m_mappingElement( mapping ),
24 m_schema( contSchema ),
29 m_insertOperation( 0 ),
42 throwException(
"Missing dictionary information for the type of the container \"" +
43 m_objectType.cppName() +
"\"",
44 "STLContainerWriter::build" );
46 m_localElement.clear();
49 m_recordId.push_back(0);
55 const std::vector<std::string>&
columns = m_mappingElement.columnNames();
56 if( !columns.size() ){
58 "STLContainerWriter::build");
60 for(
size_t i=0;
i<columns.size();
i++ ){
61 m_insertOperation->addId( columns[
i ] );
73 if ( ! keyType || !keyResolvedType ) {
74 throwException(
"Missing dictionary information for the key type of the container \"" +
75 m_objectType.cppName() +
"\"",
76 "STLContainerWriter::build" );
81 if ( iMe == m_mappingElement.end() ) {
82 throwException(
"Item for \"" + keyName +
"\" not found in the mapping element",
83 "STLContainerWriter::build" );
86 m_keyWriter.reset( streamerFactory.
newWriter( keyResolvedType, iMe->second ) );
87 m_keyWriter->build( m_localElement, *m_insertOperation, operationBuffer );
95 if ( ! valueType || !valueResolvedType ) {
96 throwException(
"Missing dictionary information for the content type of the container \"" +
97 m_objectType.cppName() +
"\"",
98 "STLContainerWriter::build" );
101 std::string valueName(m_associative ?
"mapped_type" :
"value_type");
104 if ( iMe == m_mappingElement.end() ) {
107 iMe = m_mappingElement.find( valueName2 );
108 if ( iMe == m_mappingElement.end() ) {
109 throwException(
"Item for \"" + valueName +
"\" not found in the mapping element",
110 "STLContainerWriter::build" );
114 m_dataWriter.reset( streamerFactory.
newWriter( valueResolvedType, iMe->second ) );
115 m_dataWriter->build( m_localElement, *m_insertOperation, operationBuffer );
122 for(
size_t i=0;
i<identity.size();
i++) {
123 m_recordId.push_back( identity[
i] );
125 m_recordId.push_back( 0 );
133 "STLContainerWriter::write");
136 const std::vector<std::string>&
columns = m_mappingElement.columnNames();
137 if( columns.size() != m_recordId.size()+1){
138 throwException(
"Object id elements provided are not matching with the mapped id columns.",
139 "STLContainerWriter::write");
142 const edm::TypeWithDict& iteratorReturnType = m_arrayHandler->iteratorReturnType();
150 if ( ! firstMember ) {
151 throwException(
"Could not find the data member \"first\" for the class \"" +
152 iteratorReturnType.
cppName() +
"\"",
153 "STLContainerWriter::write" );
156 if ( ! secondMember ) {
157 throwException(
"Could not retrieve the data member \"second\" for the class \"" +
158 iteratorReturnType.
cppName() +
"\"",
159 "STLContainerWriter::write" );
163 void*
data = m_offset->address( inputData );
166 size_t containerSize = m_arrayHandler->size( data );
168 if ( containerSize == 0 )
return;
170 size_t startElementIndex = m_arrayHandler->startElementIndex( data );
171 std::auto_ptr<IArrayIteratorHandler> iteratorHandler( m_arrayHandler->iterate( data ) );
173 InsertCache& bulkInsert = m_insertOperation->setUp( containerSize-startElementIndex+1 );
175 for (
size_t iIndex = startElementIndex; iIndex < containerSize; ++iIndex ) {
177 m_recordId[m_recordId.size()-1] = iIndex;
178 coral::AttributeList& dataBuff = m_insertOperation->data();
180 dataBuff[ columns[0] ].data<
int>() = oid;
181 for(
size_t i = 1;
i < columns.size();
i++ ){
182 dataBuff[ columns[
i] ].data<
int>() = m_recordId[
i-1];
185 void* objectReference = iteratorHandler->object();
186 void* componentData = objectReference;
189 void* keyData =
static_cast< char*
>( objectReference ) + firstMember.
offset();
190 m_keyWriter->setRecordId( m_recordId );
191 m_keyWriter->write( oid, keyData );
193 componentData =
static_cast< char*
>( objectReference ) + secondMember.
offset();
195 m_dataWriter->setRecordId( m_recordId );
197 m_dataWriter->write( oid, componentData );
198 bulkInsert.processNextIteration();
201 iteratorHandler->increment();
205 m_arrayHandler->finalize( const_cast<void*>( data ) );
212 m_deleter( mapping ),
213 m_writer( objectType, mapping, contSchema ){
222 m_deleter.build( operationBuffer );
223 m_writer.build( offset, relationalData, operationBuffer );
228 m_writer.setRecordId( identity );
233 m_deleter.erase( oid );
234 m_writer.write( oid, data );
240 m_objectType( objectType ),
241 m_mappingElement( mapping ),
242 m_schema( contSchema ),
257 m_localElement.clear();
260 m_recordId.push_back(0);
267 m_query->addWhereId( m_mappingElement.pkColumn() );
268 std::vector<std::string> recIdCols = m_mappingElement.recordIdColumns();
269 for(
size_t i=0;
i<recIdCols.size();
i++ ){
270 m_query->addId( recIdCols[
i ] );
271 m_query->addOrderId( recIdCols[ i ] );
279 if ( m_associative ){
284 if ( ! keyType ||!keyResolvedType ) {
285 throwException(
"Missing dictionary information for the key type of the container \"" +
286 m_objectType.cppName() +
"\"",
287 "STLContainerReader::build" );
293 if ( iMe == m_mappingElement.end() ) {
294 throwException(
"Item for \"" + keyName +
"\" not found in the mapping element",
295 "STLContainerReader::build" );
298 m_keyReader.reset( streamerFactory.
newReader( keyResolvedType, iMe->second ) );
299 m_keyReader->build( m_localElement, *m_query );
308 if ( ! valueType ||!valueResolvedType ) {
309 throwException(
"Missing dictionary information for the content type of the container \"" +
310 m_objectType.cppName() +
"\"",
311 "STLContainerReader::build" );
314 std::string valueName(m_associative ?
"mapped_type" :
"value_type");
317 if ( iMe == m_mappingElement.end() ) {
320 iMe = m_mappingElement.find( valueName2 );
321 if ( iMe == m_mappingElement.end() ) {
322 throwException(
"Item for \"" + valueName +
"\" not found in the mapping element",
323 "STLContainerReader::build" );
327 m_dataReader.reset( streamerFactory.
newReader( valueResolvedType, iMe->second ) );
328 m_dataReader->build( m_localElement, *m_query );
335 "STLContainerReader::read");
337 coral::AttributeList& whereData = m_query->whereData();
338 whereData[ m_mappingElement.pkColumn() ].data<
int>() = oid;
340 if(m_keyReader.get()) m_keyReader->select( oid );
341 m_dataReader->select( oid );
346 for(
size_t i=0;
i<identity.size();
i++) {
347 m_recordId.push_back( identity[
i] );
350 m_recordId.push_back( 0 );
357 "STLContainerReader::read");
360 void* address = m_offset->address( destinationData );
362 const edm::TypeWithDict& iteratorReturnType = m_arrayHandler->iteratorReturnType();
368 if ( m_associative ) {
371 if ( ! firstMember ) {
372 throwException(
"Could not retrieve the data member \"first\" of the class \"" +
373 iteratorReturnType.
cppName() +
"\"",
374 "STLContainerReader::read" );
377 if ( ! secondMember ) {
378 throwException(
"Could not retrieve the data member \"second\" of the class \"" +
379 iteratorReturnType.
cppName() +
"\"",
380 "STLContainerReader::read" );
384 bool isElementFundamental = iteratorReturnType.
isFundamental();
386 m_arrayHandler->clear( address );
388 size_t cursorSize = m_query->selectionSize(m_recordId, m_recordId.size()-1);
391 void* objectData = 0;
392 if(isElementFundamental){
393 objectData = &primitiveStub;
398 while ( i< cursorSize ){
400 m_recordId[m_recordId.size()-1] = (int)i;
401 m_query->selectRow( m_recordId );
403 void* componentData = objectData;
407 keyData =
static_cast< char*
>( objectData ) + firstMember.
offset();
408 m_keyReader->setRecordId( m_recordId );
409 m_keyReader->read( keyData );
411 componentData =
static_cast< char*
>( objectData ) + secondMember.
offset();
413 m_dataReader->setRecordId( m_recordId );
414 m_dataReader->read( componentData );
416 size_t prevSize = m_arrayHandler->size( address );
417 m_arrayHandler->appendNewElement( address, objectData );
418 bool inserted = m_arrayHandler->size( address )>prevSize;
420 throwException(
"Could not insert a new element in the array type \"" +
421 m_objectType.cppName() +
"\"",
422 "STLContainerReader::read" );
427 iteratorReturnType.
destruct( objectData );
430 m_arrayHandler->finalize( address );
435 if(m_query.get()) m_query->clear();
436 if(m_keyReader.get()) m_keyReader->clear();
437 if(m_dataReader.get()) m_dataReader->clear();
443 m_objectType( objectType ),
444 m_mapping( mapping ),
445 m_schema( contSchema ){
edm::TypeWithDict resolvedType(const edm::TypeWithDict &typ)
bool build(DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
virtual ~STLContainerWriter()
virtual ~STLContainerUpdater()
void setRecordId(const std::vector< int > &identity)
IRelationalReader * newReader()
std::string unscopedName() const
TypeWithDict templateArgumentAt(size_t index) const
MemberWithDict dataMemberByName(std::string const &) const
STLContainerWriter(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
virtual ~STLContainerReader()
STLContainerReader(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
std::string cppName() const
void write(int oid, const void *data)
Writes a data element.
bool build(DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
void read(void *address)
Reads a data element.
IRelationalWriter * newWriter(const edm::TypeWithDict &dataType, MappingElement &dataMapping)
static IArrayHandler * newArrayHandler(const edm::TypeWithDict &arrayType)
bool isFundamental() const
void setRecordId(const std::vector< int > &identity)
void setRecordId(const std::vector< int > &identity)
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
MultiRecordInsertOperation & newMultiRecordInsert(const std::string &tableName)
IRelationalReader * newReader(const edm::TypeWithDict &dataType, MappingElement &dataMapping)
STLContainerStreamer(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
bool isTypeAssociativeContainer(const edm::TypeWithDict &typ)
void destruct(void *address, bool dealloc=true) const
void update(int oid, const void *data)
Updates a data element.
IRelationalWriter * newWriter()
STLContainerUpdater(const edm::TypeWithDict &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
edm::TypeWithDict containerKeyType(const edm::TypeWithDict &typ)
edm::TypeWithDict containerDataType(const edm::TypeWithDict &typ)
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
bool build(DataElement &offset, IRelationalData &relationalData)
IRelationalUpdater * newUpdater()
edm::TypeWithDict containerValueType(const edm::TypeWithDict &typ)
ObjectWithDict construct() const