Public Member Functions | |
bool | build () |
void | executeAndLoad (void *address) |
QVQueryMaker (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema) | |
void | select (const std::vector< int > &fullId, const Selection &selection) |
size_t | selectionCount (const std::vector< int > &fullId, const Selection &selection) |
void | setQueryCondition (IRelationalData &queryData, const Selection &selection, MappingElement &mappingElement) |
~QVQueryMaker () | |
Private Attributes | |
std::auto_ptr< IArrayHandler > | m_arrayHandler |
std::auto_ptr< IRelationalReader > | m_dataReader |
DataElement | m_localElement |
MappingElement & | m_mappingElement |
Reflex::Type | m_objectType |
int | m_oid |
std::auto_ptr< SelectOperation > | m_query |
std::vector< int > | m_recordId |
ContainerSchema & | m_schema |
Definition at line 51 of file QueryableVectorStreamer.cc.
ora::QVQueryMaker::QVQueryMaker | ( | const Reflex::Type & | objectType, |
MappingElement & | mapping, | ||
ContainerSchema & | contSchema | ||
) | [inline] |
Definition at line 53 of file QueryableVectorStreamer.cc.
{ }
ora::QVQueryMaker::~QVQueryMaker | ( | ) | [inline] |
Definition at line 64 of file QueryableVectorStreamer.cc.
{
bool ora::QVQueryMaker::build | ( | ) | [inline] |
Definition at line 67 of file QueryableVectorStreamer.cc.
Referenced by ora::QueryableVectorLoader::loadSelection().
{ m_query->addId( recIdCols[ i ] ); m_query->addOrderId( recIdCols[ i ] ); } Reflex::Type storeBaseType = ClassUtils::containerSubType(m_objectType,"range_store_base_type"); if( !storeBaseType ){ throwException( "Missing dictionary information for the range store base type of the container \"" + m_objectType.Name(Reflex::SCOPED) + "\"", "QVQueryMaker::build" ); } m_arrayHandler.reset( ArrayHandlerFactory::newArrayHandler( storeBaseType ) ); Reflex::Type valueType = ClassUtils::containerValueType(m_objectType); Reflex::Type valueResolvedType = ClassUtils::resolvedType(valueType); // Check the component type if ( ! valueType ||!valueResolvedType ) { throwException( "Missing dictionary information for the content type of the container \"" + m_objectType.Name(Reflex::SCOPED) + "\"", "QVQueryMaker::build" ); } std::string valueName = valueType.Name(); // Retrieve the relevant mapping element MappingElement::iterator iMe = m_mappingElement.find( valueName ); if ( iMe == m_mappingElement.end() ) { throwException( "Item for \"" + valueName + "\" not found in the mapping element", "QVQueryMaker::build" ); } m_dataReader.reset( streamerFactory.newReader( valueResolvedType, iMe->second ) ); m_dataReader->build( m_localElement, *m_query ); return true; }
void ora::QVQueryMaker::executeAndLoad | ( | void * | address | ) | [inline] |
Definition at line 220 of file QueryableVectorStreamer.cc.
References ora::throwException().
Referenced by ora::QueryableVectorLoader::loadSelection().
{ throwException("The reader has not been built.", "QVReader::read"); } Reflex::Type iteratorDereferenceReturnType = m_arrayHandler->iteratorReturnType(); Reflex::Member firstMember = iteratorDereferenceReturnType.MemberByName( "first" ); if ( ! firstMember ) { throwException( "Could not retrieve the data member \"first\" of the class \"" + iteratorDereferenceReturnType.Name(Reflex::SCOPED) + "\"", "QVQueryMakerAndLoad::read" ); } Reflex::Member secondMember = iteratorDereferenceReturnType.MemberByName( "second" ); if ( ! secondMember ) { throwException( "Could not retrieve the data member \"second\" of the class \"" + iteratorDereferenceReturnType.Name(Reflex::SCOPED) + "\"", "QVQueryMakerAndLoad::read" ); } m_arrayHandler->clear( address ); unsigned int i=0; while ( m_query->nextCursorRow() ){ // Create a new element for the array void* objectData = iteratorDereferenceReturnType.Construct().Address(); void* positionData = static_cast< char* >( objectData ) + firstMember.Offset(); void* containerData = static_cast< char* >( objectData ) + secondMember.Offset(); m_recordId[m_recordId.size()-1] = (int)i; coral::AttributeList& row = m_query->data(); *(size_t*)positionData = (size_t)(row[m_mappingElement.posColumn()].data<int>()); m_dataReader->setRecordId( m_recordId ); m_dataReader->select( m_oid ); m_dataReader->read( containerData ); size_t prevSize = m_arrayHandler->size( address ); m_arrayHandler->appendNewElement( address, objectData ); bool inserted = m_arrayHandler->size( address )>prevSize; iteratorDereferenceReturnType.Destruct( objectData ); if ( !inserted ) { throwException( "Could not insert a new element in the array type \"" + m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) + "\"", "QVQueryMakerAndLoad::executeAndLoad" ); } ++i; } m_arrayHandler->finalize( address ); m_query->clear(); }
void ora::QVQueryMaker::select | ( | const std::vector< int > & | fullId, |
const Selection & | selection | ||
) | [inline] |
Definition at line 170 of file QueryableVectorStreamer.cc.
References ora::throwException().
Referenced by ora::QueryableVectorLoader::loadSelection().
{ throwException("The reader has not been built.", "QVReader::select"); } m_oid = fullId[0]; m_recordId.clear(); for(size_t i=1;i<fullId.size();i++) { m_recordId.push_back( fullId[i] ); } // allocate the element for the index... m_recordId.push_back( 0 ); coral::AttributeList& whereData = m_query->whereData(); whereData[ m_mappingElement.pkColumn() ].data<int>() = fullId[0]; setQueryCondition( *m_query, selection, m_mappingElement ); m_query->execute(); }
size_t ora::QVQueryMaker::selectionCount | ( | const std::vector< int > & | fullId, |
const Selection & | selection | ||
) | [inline] |
Definition at line 192 of file QueryableVectorStreamer.cc.
Referenced by ora::QueryableVectorLoader::getSelectionCount().
{ countQuery.addWhereId( recIdColumns[i] ); } coral::AttributeList& whereData = countQuery.whereData(); // Fill-in the identities. whereData[ m_mappingElement.pkColumn() ].data<int>() = fullId[0]; for ( size_t i=0;i<fullId.size();i++ ){ whereData[ recIdColumns[i] ].data<int>() = fullId[i+1]; } setQueryCondition( countQuery, selection, m_mappingElement ); countQuery.execute(); size_t result = 0; if( countQuery.nextCursorRow() ){ coral::AttributeList& row = countQuery.data(); result = row[countColumn].data<int>(); } return result; }
void ora::QVQueryMaker::setQueryCondition | ( | IRelationalData & | queryData, |
const Selection & | selection, | ||
MappingElement & | mappingElement | ||
) | [inline] |
Definition at line 114 of file QueryableVectorStreamer.cc.
References ora::MappingElement::columnNames(), ora::MappingElement::elementType(), ora::MappingElement::elementTypeAsString(), ora::MappingElement::end(), ora::MappingElement::find(), i, ora::Selection::indexVariable(), ora::MappingElement::Object, ora::MappingElement::Primitive, ora::throwException(), and ora::Selection::variableNameFromUniqueString().
{ cond << " AND "; std::string varName = Selection::variableNameFromUniqueString(iItem->first); std::stringstream selColumn; std::string colName(""); if(varName == Selection::indexVariable()){ colName = mappingElement.columnNames()[mappingElement.columnNames().size()-1]; // the position column is the last selColumn << colName<<"_"<<i; whereData.extend<int>(selColumn.str()); whereData[selColumn.str()].data<int>() = selection.data()[iItem->first].data<int>(); } else { MappingElement::iterator iElem = mappingElement.find("value_type"); if ( iElem == mappingElement.end() ) { throwException( "Item for element \"value_type\" not found in the mapping element", "QVQueryMaker::setQueryCondition" ); } MappingElement& valueTypeElement = iElem->second; if( valueTypeElement.elementType()==MappingElement::Primitive ){ if(varName!="value_type"){ throwException( "Item for element \"" + varName + "\" not found in the mapping element", "QVQueryMaker::setQueryCondition" ); } colName = valueTypeElement.columnNames()[0]; } else if( valueTypeElement.elementType()==MappingElement::Object ){ MappingElement::iterator iInnerElem = valueTypeElement.find(varName); if ( iInnerElem == valueTypeElement.end() ) { throwException( "Item for element \"" + varName + "\" not found in the mapping element", "QVQueryMaker::setQueryCondition" ); } colName = iInnerElem->second.columnNames()[0]; } else { throwException( "Queries cannot be executed on types mapped on "+ MappingElement::elementTypeAsString(valueTypeElement.elementType()), "QVQueryMaker::setQueryCondition" ); } selColumn << colName<<"_"<<i; whereData.extend(selColumn.str(),selection.data()[iItem->first].specification().type()); whereData[selColumn.str()].setValueFromAddress(selection.data()[iItem->first].addressOfData()); } cond << colName << " " << iItem->second << " :"<<selColumn.str(); i++; selColumn.str(""); } // add the resulting condition clause queryData.whereClause()+=cond.str(); }
std::auto_ptr<IArrayHandler> ora::QVQueryMaker::m_arrayHandler [private] |
Definition at line 283 of file QueryableVectorStreamer.cc.
std::auto_ptr<IRelationalReader> ora::QVQueryMaker::m_dataReader [private] |
Definition at line 284 of file QueryableVectorStreamer.cc.
DataElement ora::QVQueryMaker::m_localElement [private] |
Definition at line 281 of file QueryableVectorStreamer.cc.
Definition at line 278 of file QueryableVectorStreamer.cc.
Reflex::Type ora::QVQueryMaker::m_objectType [private] |
Definition at line 277 of file QueryableVectorStreamer.cc.
int ora::QVQueryMaker::m_oid [private] |
Definition at line 285 of file QueryableVectorStreamer.cc.
std::auto_ptr<SelectOperation> ora::QVQueryMaker::m_query [private] |
Definition at line 282 of file QueryableVectorStreamer.cc.
std::vector<int> ora::QVQueryMaker::m_recordId [private] |
Definition at line 280 of file QueryableVectorStreamer.cc.
ContainerSchema& ora::QVQueryMaker::m_schema [private] |
Definition at line 279 of file QueryableVectorStreamer.cc.