15 #include "RelationalAccess/IBulkOperation.h"
16 #include "Reflex/Member.h"
17 #include "Reflex/Base.h"
18 #include "CoralBase/Attribute.h"
33 void read(
const std::vector<int>& fullId,
void* destinationAddress){
35 std::vector<int> recordId;
36 for(
size_t i=1;
i<fullId.size();
i++) {
37 recordId.push_back( fullId[
i] );
78 for(
size_t i=0;
i<recIdCols.size();
i++ ){
80 m_query->addOrderId( recIdCols[ i ] );
85 throwException(
"Missing dictionary information for the range store base type of the container \"" +
87 "QVQueryMaker::build" );
95 if ( ! valueType ||!valueResolvedType ) {
96 throwException(
"Missing dictionary information for the content type of the container \"" +
98 "QVQueryMaker::build" );
100 std::string valueName = valueType.Name();
104 throwException(
"Item for \"" + valueName +
"\" not found in the mapping element",
105 "QVQueryMaker::build" );
114 coral::AttributeList& whereData = queryData.
whereData();
116 const std::vector<std::pair<std::string,std::string> >& theItems = selection.
items();
117 std::stringstream cond;
119 for(std::vector<std::pair<std::string,std::string> >::const_iterator iItem = theItems.begin();
120 iItem != theItems.end();
124 std::stringstream selColumn;
125 std::string colName(
"");
128 selColumn << colName<<
"_"<<
i;
129 whereData.extend<
int>(selColumn.str());
130 whereData[selColumn.str()].data<
int>() = selection.
data()[iItem->first].data<
int>();
133 if ( iElem == mappingElement.
end() ) {
134 throwException(
"Item for element \"value_type\" not found in the mapping element",
135 "QVQueryMaker::setQueryCondition" );
139 if(varName!=
"value_type"){
140 throwException(
"Item for element \"" + varName +
"\" not found in the mapping element",
141 "QVQueryMaker::setQueryCondition" );
146 if ( iInnerElem == valueTypeElement.
end() ) {
147 throwException(
"Item for element \"" + varName +
"\" not found in the mapping element",
148 "QVQueryMaker::setQueryCondition" );
150 colName = iInnerElem->second.columnNames()[0];
154 "QVQueryMaker::setQueryCondition" );
156 selColumn << colName<<
"_"<<
i;
157 whereData.extend(selColumn.str(),selection.
data()[iItem->first].specification().type());
158 whereData[selColumn.str()].setValueFromAddress(selection.
data()[iItem->first].addressOfData());
160 cond << colName <<
" " << iItem->second <<
" :"<<selColumn.str();
177 for(
size_t i=1;
i<fullId.size();
i++) {
183 coral::AttributeList& whereData =
m_query->whereData();
193 std::string countColumn(
"COUNT(*)");
194 countQuery.addData( countColumn ,
typeid(
int) );
197 for(
size_t i=0;
i<recIdColumns.size();
i++){
198 countQuery.addWhereId( recIdColumns[
i] );
201 coral::AttributeList& whereData = countQuery.whereData();
204 for (
size_t i=0;
i<fullId.size();
i++ ){
205 whereData[ recIdColumns[
i] ].data<
int>() = fullId[
i+1];
209 countQuery.execute();
212 if( countQuery.nextCursorRow() ){
213 coral::AttributeList& row = countQuery.data();
214 result = row[countColumn].data<
int>();
226 Reflex::Member firstMember = iteratorDereferenceReturnType.MemberByName(
"first" );
227 if ( ! firstMember ) {
228 throwException(
"Could not retrieve the data member \"first\" of the class \"" +
229 iteratorDereferenceReturnType.Name(Reflex::SCOPED) +
"\"",
230 "QVQueryMakerAndLoad::read" );
232 Reflex::Member secondMember = iteratorDereferenceReturnType.MemberByName(
"second" );
233 if ( ! secondMember ) {
234 throwException(
"Could not retrieve the data member \"second\" of the class \"" +
235 iteratorDereferenceReturnType.Name(Reflex::SCOPED) +
"\"",
236 "QVQueryMakerAndLoad::read" );
242 while (
m_query->nextCursorRow() ){
245 void* objectData = iteratorDereferenceReturnType.Construct().Address();
246 void* positionData =
static_cast< char*
>( objectData ) + firstMember.Offset();
247 void* containerData =
static_cast< char*
>( objectData ) + secondMember.Offset();
250 coral::AttributeList& row =
m_query->data();
262 iteratorDereferenceReturnType.Destruct( objectData );
264 throwException(
"Could not insert a new element in the array type \"" +
266 "QVQueryMakerAndLoad::executeAndLoad" );
293 const std::vector<int>& fullId ):
295 m_reader( objectType, mapping, contSchema ),
355 m_objectType( objectType ),
358 m_writer(ClassUtils::
containerSubType(objectType,
"store_base_type"), mapping, contSchema ){
368 m_localElement.clear();
369 return m_writer.build( m_localElement, data, operationBuffer );
373 m_writer.setRecordId( identity );
380 "QueryableVectorWriter::write");
382 void* vectorAddress = m_offset->address( inputData );
383 Reflex::Object vectorObj( m_objectType,const_cast<void*>(vectorAddress));
384 vectorObj.Invoke(
"load",0);
385 void* storageAddress = 0;
386 vectorObj.Invoke(
"storageAddress",storageAddress);
387 m_writer.write( oid, storageAddress );
393 m_objectType( objectType ),
396 m_updater( ClassUtils::
containerSubType(objectType,
"store_base_type"), mapping, contSchema ){
406 m_localElement.clear();
407 return m_updater.build( m_localElement, relationalData, operationBuffer );
411 m_updater.setRecordId( identity );
418 "QueryableVectorUpdater::update");
420 void* vectorAddress = m_offset->address( data );
421 Reflex::Object vectorObj( m_objectType,const_cast<void*>(vectorAddress));
422 vectorObj.Invoke(
"load",0);
423 void* storageAddress = 0;
424 vectorObj.Invoke(
"storageAddress",storageAddress);
425 m_updater.update( oid, storageAddress );
431 m_objectType(objectType),
432 m_mapping( mapping ),
433 m_schema( contSchema ),
440 for(std::vector<boost::shared_ptr<IVectorLoader> >::const_iterator iL = m_loaders.begin();
441 iL != m_loaders.end(); ++iL ){
448 m_dataElement = &dataElement;
450 m_tmpIds.push_back(0);
459 m_tmpIds.resize( 1+identity.size() );
460 for(
size_t i=0;
i<identity.size();
i++){
461 m_tmpIds[1+
i] = identity[
i];
468 "QueryableVectorReader::read");
472 Reflex::Member loaderMember = m_objectType.DataMemberByName(
"m_loader");
475 "QueryableVectorReader::read");
478 void* loaderAddress = loaderMemberElement.
address( destinationData );
481 boost::shared_ptr<IVectorLoader> loader(
new QueryableVectorLoader( m_objectType, m_mapping, m_schema, m_tmpIds ) );
482 m_loaders.push_back(loader);
484 *(
static_cast<boost::shared_ptr<IVectorLoader>*
>( loaderAddress )) = loader;
494 m_objectType( objectType ),
495 m_mapping( mapping ),
496 m_schema( contSchema ){
QueryableVectorStreamer(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
bool build(DataElement &offset, IRelationalData &relationalData)
void setQueryCondition(IRelationalData &queryData, const Selection &selection, MappingElement &mappingElement)
IRelationalWriter * newWriter()
virtual coral::AttributeList & whereData()=0
DataElement m_localElement
IRelationalReader * newReader()
IRelationalUpdater * newUpdater()
size_t getSelectionCount(const Selection &selection) const
ContainerSchema & m_schema
IRelationalReader * newReader(const Reflex::Type &dataType, MappingElement &dataMapping)
void * address(const void *topLevelAddress) const
const coral::AttributeList & data() const
bool load(void *address) const
void executeAndLoad(void *address)
static std::string variableNameFromUniqueString(const std::string &uniqueString)
bool build(DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
QueryableVectorWriter(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
DataElement & addChild(size_t declaringScopeOffset, Reflex::OffsetFunction offsetFunction)
void write(int oid, const void *data)
Writes a data element.
~QueryableVectorStreamer()
ElementType elementType() const
MappingElement & m_mappingElement
QVQueryMaker m_queryMaker
void setRecordId(const std::vector< int > &identity)
virtual ~QueryableVectorReader()
virtual std::string & whereClause()=0
void read(const std::vector< int > &fullId, void *destinationAddress)
Reflex::Type containerSubType(const Reflex::Type &typ, const std::string &subTypeName)
Reflex::Type m_objectType
std::auto_ptr< IArrayHandler > m_arrayHandler
std::vector< int > m_recordId
std::vector< std::string > recordIdColumns() const
virtual ~QueryableVectorLoader()
static IArrayHandler * newArrayHandler(const Reflex::Type &arrayType)
static std::string indexVariable()
std::string posColumn() const
static std::string elementTypeAsString(ElementType elementType)
Converts the enumeration type to a string.
QVQueryMaker(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
size_t selectionCount(const std::vector< int > &fullId, const Selection &selection)
void update(int oid, const void *data)
Updates a data element.
bool loadSelection(const Selection &selection, void *address) const
iterator find(const std::string &key)
Retrieves a sub-element.
unsigned int offset(bool)
std::string pkColumn() const
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
const std::vector< std::string > & columnNames() const
Reflex::Type containerValueType(const Reflex::Type &typ)
void read(void *address)
Reads a data element.
std::auto_ptr< SelectOperation > m_query
Reflex::Type resolvedType(const Reflex::Type &typ)
QueryableVectorReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
std::vector< int > m_identity
void setRecordId(const std::vector< int > &identity)
DataElement m_localElement
void read(void *address)
Reads a data element.
void setRecordId(const std::vector< int > &identity)
coral::ISchema & storageSchema()
void select(const std::vector< int > &fullId, const Selection &selection)
iterator end()
Returns an iterator in the end of the sequence.
char data[epos_bytes_allocation]
void setRecordId(const std::vector< int > &identity)
const std::string & tableName() const
void throwException(const std::string &message, const std::string &methodName)
const std::vector< std::pair< std::string, std::string > > & items() const
std::auto_ptr< IRelationalReader > m_dataReader
QueryableVectorLoader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema, const std::vector< int > &fullId)
QueryableVectorUpdater(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Constructor.
bool build(DataElement &offset, IRelationalData &relationalData)
bool build(DataElement &offset, IRelationalData &relationalData, RelationalBuffer &operationBuffer)
QVReader(const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
Reflex::Type m_objectType
virtual ~QueryableVectorUpdater()
virtual ~QueryableVectorWriter()