CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
ora::QVQueryMaker Class Reference

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< IArrayHandlerm_arrayHandler
 
std::auto_ptr< IRelationalReaderm_dataReader
 
DataElement m_localElement
 
MappingElementm_mappingElement
 
Reflex::Type m_objectType
 
int m_oid
 
std::auto_ptr< SelectOperationm_query
 
std::vector< int > m_recordId
 
ContainerSchemam_schema
 

Detailed Description

Definition at line 50 of file QueryableVectorStreamer.cc.

Constructor & Destructor Documentation

ora::QVQueryMaker::QVQueryMaker ( const Reflex::Type &  objectType,
MappingElement mapping,
ContainerSchema contSchema 
)
inline

Definition at line 52 of file QueryableVectorStreamer.cc.

52  :
53  m_objectType( objectType ),
54  m_mappingElement( mapping ),
55  m_schema( contSchema ),
56  m_recordId(),
58  m_query(),
60  m_oid(-1){
61  }
ContainerSchema & m_schema
MappingElement & m_mappingElement
std::auto_ptr< IArrayHandler > m_arrayHandler
std::vector< int > m_recordId
std::auto_ptr< SelectOperation > m_query
ora::QVQueryMaker::~QVQueryMaker ( )
inline

Definition at line 63 of file QueryableVectorStreamer.cc.

63  {
64  }

Member Function Documentation

bool ora::QVQueryMaker::build ( )
inline

Definition at line 66 of file QueryableVectorStreamer.cc.

References ora::DataElement::clear(), ora::ClassUtils::containerSubType(), ora::ClassUtils::containerValueType(), ora::MappingElement::end(), ora::MappingElement::find(), i, m_arrayHandler, m_dataReader, m_localElement, m_mappingElement, m_objectType, m_query, m_recordId, m_schema, ora::ArrayHandlerFactory::newArrayHandler(), ora::RelationalStreamerFactory::newReader(), ora::MappingElement::pkColumn(), ora::MappingElement::recordIdColumns(), ora::ClassUtils::resolvedType(), ora::ContainerSchema::storageSchema(), AlCaHLTBitMon_QueryRunRegistry::string, ora::MappingElement::tableName(), and ora::throwException().

Referenced by ora::QueryableVectorLoader::loadSelection().

66  {
68  m_recordId.clear();
69  // allocate for the index...
70  m_recordId.push_back(0);
71 
72  RelationalStreamerFactory streamerFactory( m_schema );
73  // first open the insert on the extra table...
74  m_query.reset( new SelectOperation( m_mappingElement.tableName(), m_schema.storageSchema() ));
75 
76  m_query->addWhereId( m_mappingElement.pkColumn() );
77  std::vector<std::string> recIdCols = m_mappingElement.recordIdColumns();
78  for( size_t i=0; i<recIdCols.size(); i++ ){
79  m_query->addId( recIdCols[ i ] );
80  m_query->addOrderId( recIdCols[ i ] );
81  }
82 
83  Reflex::Type storeBaseType = ClassUtils::containerSubType(m_objectType,"range_store_base_type");
84  if( !storeBaseType ){
85  throwException( "Missing dictionary information for the range store base type of the container \"" +
86  m_objectType.Name(Reflex::SCOPED) + "\"",
87  "QVQueryMaker::build" );
88  }
89 
90  m_arrayHandler.reset( ArrayHandlerFactory::newArrayHandler( storeBaseType ) );
91 
93  Reflex::Type valueResolvedType = ClassUtils::resolvedType(valueType);
94  // Check the component type
95  if ( ! valueType ||!valueResolvedType ) {
96  throwException( "Missing dictionary information for the content type of the container \"" +
97  m_objectType.Name(Reflex::SCOPED) + "\"",
98  "QVQueryMaker::build" );
99  }
100  std::string valueName = valueType.Name();
101  // Retrieve the relevant mapping element
103  if ( iMe == m_mappingElement.end() ) {
104  throwException( "Item for \"" + valueName + "\" not found in the mapping element",
105  "QVQueryMaker::build" );
106  }
107 
108  m_dataReader.reset( streamerFactory.newReader( valueResolvedType, iMe->second ) );
109  m_dataReader->build( m_localElement, *m_query );
110  return true;
111  }
int i
Definition: DBlmapReader.cc:9
ContainerSchema & m_schema
MappingElement & m_mappingElement
Reflex::Type containerSubType(const Reflex::Type &typ, const std::string &subTypeName)
Definition: ClassUtils.cc:389
std::auto_ptr< IArrayHandler > m_arrayHandler
std::vector< int > m_recordId
std::vector< std::string > recordIdColumns() const
static IArrayHandler * newArrayHandler(const Reflex::Type &arrayType)
iterator find(const std::string &key)
Retrieves a sub-element.
std::string pkColumn() const
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
Reflex::Type containerValueType(const Reflex::Type &typ)
Definition: ClassUtils.cc:341
std::auto_ptr< SelectOperation > m_query
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:404
coral::ISchema & storageSchema()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
iterator end()
Returns an iterator in the end of the sequence.
const std::string & tableName() const
std::auto_ptr< IRelationalReader > m_dataReader
void ora::QVQueryMaker::executeAndLoad ( void *  address)
inline

Definition at line 219 of file QueryableVectorStreamer.cc.

References i, m_arrayHandler, m_dataReader, m_mappingElement, m_objectType, m_oid, m_query, m_recordId, ora::MappingElement::posColumn(), and ora::throwException().

Referenced by ora::QueryableVectorLoader::loadSelection().

219  {
220 
221  if(!m_query.get()){
222  throwException("The reader has not been built.",
223  "QVReader::read");
224  }
225  Reflex::Type iteratorDereferenceReturnType = m_arrayHandler->iteratorReturnType();
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" );
231  }
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" );
237  }
238 
239  m_arrayHandler->clear( address );
240 
241  unsigned int i=0;
242  while ( m_query->nextCursorRow() ){
243 
244  // Create a new element for the array
245  void* objectData = iteratorDereferenceReturnType.Construct().Address();
246  void* positionData = static_cast< char* >( objectData ) + firstMember.Offset();
247  void* containerData = static_cast< char* >( objectData ) + secondMember.Offset();
248 
249  m_recordId[m_recordId.size()-1] = (int)i;
250  coral::AttributeList& row = m_query->data();
251 
252  *(size_t*)positionData = (size_t)(row[m_mappingElement.posColumn()].data<int>());
253 
254  m_dataReader->setRecordId( m_recordId );
255  m_dataReader->select( m_oid );
256  m_dataReader->read( containerData );
257 
258  size_t prevSize = m_arrayHandler->size( address );
259  m_arrayHandler->appendNewElement( address, objectData );
260  bool inserted = m_arrayHandler->size( address )>prevSize;
261 
262  iteratorDereferenceReturnType.Destruct( objectData );
263  if ( !inserted ) {
264  throwException( "Could not insert a new element in the array type \"" +
265  m_objectType.Name(Reflex::SCOPED|Reflex::FINAL) + "\"",
266  "QVQueryMakerAndLoad::executeAndLoad" );
267  }
268  ++i;
269  }
270 
271  m_arrayHandler->finalize( address );
272  m_query->clear();
273  }
int i
Definition: DBlmapReader.cc:9
MappingElement & m_mappingElement
std::auto_ptr< IArrayHandler > m_arrayHandler
std::vector< int > m_recordId
std::string posColumn() const
std::auto_ptr< SelectOperation > m_query
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
std::auto_ptr< IRelationalReader > m_dataReader
void ora::QVQueryMaker::select ( const std::vector< int > &  fullId,
const Selection selection 
)
inline

Definition at line 169 of file QueryableVectorStreamer.cc.

References i, m_mappingElement, m_oid, m_query, m_recordId, ora::MappingElement::pkColumn(), setQueryCondition(), and ora::throwException().

Referenced by Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), ora::QueryableVectorLoader::loadSelection(), Vispa.Views.LineDecayView.LineDecayContainer::mousePressEvent(), Vispa.Gui.PortConnection.PointToPointConnection::mousePressEvent(), Vispa.Gui.VispaWidget.VispaWidget::mousePressEvent(), and Vispa.Views.AbstractView.AbstractView::restoreSelection().

169  {
170  if(!m_query.get()){
171  throwException("The reader has not been built.",
172  "QVReader::select");
173  }
174 
175  m_oid = fullId[0];
176  m_recordId.clear();
177  for(size_t i=1;i<fullId.size();i++) {
178  m_recordId.push_back( fullId[i] );
179  }
180  // allocate the element for the index...
181  m_recordId.push_back( 0 );
182 
183  coral::AttributeList& whereData = m_query->whereData();
184  whereData[ m_mappingElement.pkColumn() ].data<int>() = fullId[0];
185 
187 
188  m_query->execute();
189  }
int i
Definition: DBlmapReader.cc:9
void setQueryCondition(IRelationalData &queryData, const Selection &selection, MappingElement &mappingElement)
MappingElement & m_mappingElement
std::vector< int > m_recordId
std::string pkColumn() const
std::auto_ptr< SelectOperation > m_query
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
size_t ora::QVQueryMaker::selectionCount ( const std::vector< int > &  fullId,
const Selection selection 
)
inline

Definition at line 191 of file QueryableVectorStreamer.cc.

References i, m_mappingElement, m_schema, ora::MappingElement::pkColumn(), ora::MappingElement::recordIdColumns(), query::result, setQueryCondition(), ora::ContainerSchema::storageSchema(), AlCaHLTBitMon_QueryRunRegistry::string, and ora::MappingElement::tableName().

Referenced by ora::QueryableVectorLoader::getSelectionCount().

191  {
192  SelectOperation countQuery( m_mappingElement.tableName(), m_schema.storageSchema() );
193  std::string countColumn("COUNT(*)");
194  countQuery.addData( countColumn ,typeid(int) );
195  countQuery.addWhereId( m_mappingElement.pkColumn() );
196  std::vector<std::string> recIdColumns = m_mappingElement.recordIdColumns();
197  for( size_t i=0;i<recIdColumns.size();i++){
198  countQuery.addWhereId( recIdColumns[i] );
199  }
200 
201  coral::AttributeList& whereData = countQuery.whereData();
202  // Fill-in the identities.
203  whereData[ m_mappingElement.pkColumn() ].data<int>() = fullId[0];
204  for ( size_t i=0;i<fullId.size();i++ ){
205  whereData[ recIdColumns[i] ].data<int>() = fullId[i+1];
206  }
207 
208  setQueryCondition( countQuery, selection, m_mappingElement );
209  countQuery.execute();
210 
211  size_t result = 0;
212  if( countQuery.nextCursorRow() ){
213  coral::AttributeList& row = countQuery.data();
214  result = row[countColumn].data<int>();
215  }
216  return result;
217  }
int i
Definition: DBlmapReader.cc:9
void setQueryCondition(IRelationalData &queryData, const Selection &selection, MappingElement &mappingElement)
ContainerSchema & m_schema
MappingElement & m_mappingElement
std::vector< std::string > recordIdColumns() const
tuple result
Definition: query.py:137
std::string pkColumn() const
coral::ISchema & storageSchema()
const std::string & tableName() const
void ora::QVQueryMaker::setQueryCondition ( IRelationalData queryData,
const Selection selection,
MappingElement mappingElement 
)
inline

Definition at line 113 of file QueryableVectorStreamer.cc.

References ora::MappingElement::columnNames(), ora::Selection::data(), ora::MappingElement::elementType(), ora::MappingElement::elementTypeAsString(), ora::MappingElement::end(), ora::MappingElement::find(), i, ora::Selection::indexVariable(), ora::Selection::items(), ora::MappingElement::Object, ora::MappingElement::Primitive, AlCaHLTBitMon_QueryRunRegistry::string, ora::throwException(), ora::Selection::variableNameFromUniqueString(), ora::IRelationalData::whereClause(), and ora::IRelationalData::whereData().

Referenced by select(), and selectionCount().

113  {
114  coral::AttributeList& whereData = queryData.whereData();
115  // adding the selection conditions
116  const std::vector<std::pair<std::string,std::string> >& theItems = selection.items();
117  std::stringstream cond;
118  unsigned int i=0;
119  for(std::vector<std::pair<std::string,std::string> >::const_iterator iItem = theItems.begin();
120  iItem != theItems.end();
121  ++iItem){
122  cond << " AND ";
124  std::stringstream selColumn;
125  std::string colName("");
126  if(varName == Selection::indexVariable()){
127  colName = mappingElement.columnNames()[mappingElement.columnNames().size()-1]; // the position column is the last
128  selColumn << colName<<"_"<<i;
129  whereData.extend<int>(selColumn.str());
130  whereData[selColumn.str()].data<int>() = selection.data()[iItem->first].data<int>();
131  } else {
132  MappingElement::iterator iElem = mappingElement.find("value_type");
133  if ( iElem == mappingElement.end() ) {
134  throwException( "Item for element \"value_type\" not found in the mapping element",
135  "QVQueryMaker::setQueryCondition" );
136  }
137  MappingElement& valueTypeElement = iElem->second;
138  if( valueTypeElement.elementType()==MappingElement::Primitive ){
139  if(varName!="value_type"){
140  throwException( "Item for element \"" + varName + "\" not found in the mapping element",
141  "QVQueryMaker::setQueryCondition" );
142  }
143  colName = valueTypeElement.columnNames()[0];
144  } else if( valueTypeElement.elementType()==MappingElement::Object ){
145  MappingElement::iterator iInnerElem = valueTypeElement.find(varName);
146  if ( iInnerElem == valueTypeElement.end() ) {
147  throwException( "Item for element \"" + varName + "\" not found in the mapping element",
148  "QVQueryMaker::setQueryCondition" );
149  }
150  colName = iInnerElem->second.columnNames()[0];
151  } else {
152  throwException( "Queries cannot be executed on types mapped on "+
153  MappingElement::elementTypeAsString(valueTypeElement.elementType()),
154  "QVQueryMaker::setQueryCondition" );
155  }
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());
159  }
160  cond << colName << " " << iItem->second << " :"<<selColumn.str();
161  i++;
162  selColumn.str("");
163  }
164 
165  // add the resulting condition clause
166  queryData.whereClause()+=cond.str();
167  }
int i
Definition: DBlmapReader.cc:9
static std::string variableNameFromUniqueString(const std::string &uniqueString)
Definition: Selection.cc:14
static std::string indexVariable()
Definition: Selection.cc:20
static std::string elementTypeAsString(ElementType elementType)
Converts the enumeration type to a string.
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10

Member Data Documentation

std::auto_ptr<IArrayHandler> ora::QVQueryMaker::m_arrayHandler
private

Definition at line 282 of file QueryableVectorStreamer.cc.

Referenced by build(), and executeAndLoad().

std::auto_ptr<IRelationalReader> ora::QVQueryMaker::m_dataReader
private

Definition at line 283 of file QueryableVectorStreamer.cc.

Referenced by build(), and executeAndLoad().

DataElement ora::QVQueryMaker::m_localElement
private

Definition at line 280 of file QueryableVectorStreamer.cc.

Referenced by build().

MappingElement& ora::QVQueryMaker::m_mappingElement
private

Definition at line 277 of file QueryableVectorStreamer.cc.

Referenced by build(), executeAndLoad(), select(), and selectionCount().

Reflex::Type ora::QVQueryMaker::m_objectType
private

Definition at line 276 of file QueryableVectorStreamer.cc.

Referenced by build(), and executeAndLoad().

int ora::QVQueryMaker::m_oid
private

Definition at line 284 of file QueryableVectorStreamer.cc.

Referenced by executeAndLoad(), and select().

std::auto_ptr<SelectOperation> ora::QVQueryMaker::m_query
private

Definition at line 281 of file QueryableVectorStreamer.cc.

Referenced by build(), executeAndLoad(), and select().

std::vector<int> ora::QVQueryMaker::m_recordId
private

Definition at line 279 of file QueryableVectorStreamer.cc.

Referenced by build(), executeAndLoad(), and select().

ContainerSchema& ora::QVQueryMaker::m_schema
private

Definition at line 278 of file QueryableVectorStreamer.cc.

Referenced by build(), and selectionCount().