test
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 edm::TypeWithDict &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
 
edm::TypeWithDict 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 edm::TypeWithDict 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
edm::TypeWithDict m_objectType
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(), edm::TypeWithDict::cppName(), 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(), ora::MappingElement::tableName(), and ora::throwException().

Referenced by ora::QueryableVectorLoader::loadSelection(), and psClasses.BuildThread::run().

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  edm::TypeWithDict 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.cppName() + "\"",
87  "QVQueryMaker::build" );
88  }
89 
90  m_arrayHandler.reset( ArrayHandlerFactory::newArrayHandler( storeBaseType ) );
91 
93  edm::TypeWithDict 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.cppName() + "\"",
98  "QVQueryMaker::build" );
99  }
100  // Retrieve the relevant mapping element
101  MappingElement::iterator iMe = m_mappingElement.find( "value_type" );
102  if ( iMe == m_mappingElement.end() ) {
103  throwException( "Item for \"value_type\" not found in the mapping element",
104  "QVQueryMaker::build" );
105  }
106 
107  m_dataReader.reset( streamerFactory.newReader( valueResolvedType, iMe->second ) );
108  m_dataReader->build( m_localElement, *m_query );
109  return true;
110  }
int i
Definition: DBlmapReader.cc:9
edm::TypeWithDict resolvedType(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:486
ContainerSchema & m_schema
MappingElement & m_mappingElement
std::string cppName() const
std::auto_ptr< IArrayHandler > m_arrayHandler
std::vector< int > m_recordId
std::vector< std::string > recordIdColumns() const
edm::TypeWithDict containerSubType(const edm::TypeWithDict &typ, const std::string &subTypeName)
Definition: ClassUtils.cc:468
static IArrayHandler * newArrayHandler(const edm::TypeWithDict &arrayType)
iterator find(const std::string &key)
Retrieves a sub-element.
std::string pkColumn() const
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
edm::TypeWithDict m_objectType
std::auto_ptr< SelectOperation > m_query
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.
edm::TypeWithDict containerValueType(const edm::TypeWithDict &typ)
Definition: ClassUtils.cc:410
const std::string & tableName() const
std::auto_ptr< IRelationalReader > m_dataReader
void ora::QVQueryMaker::executeAndLoad ( void *  address)
inline

Definition at line 218 of file QueryableVectorStreamer.cc.

References edm::ObjectWithDict::address(), edm::TypeWithDict::construct(), edm::TypeWithDict::cppName(), edm::TypeWithDict::dataMemberByName(), edm::TypeWithDict::destruct(), i, m_arrayHandler, m_dataReader, m_mappingElement, m_objectType, m_oid, m_query, m_recordId, edm::MemberWithDict::offset(), ora::MappingElement::posColumn(), and ora::throwException().

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

218  {
219 
220  if(!m_query.get()){
221  throwException("The reader has not been built.",
222  "QVReader::read");
223  }
224  edm::TypeWithDict iteratorDereferenceReturnType = m_arrayHandler->iteratorReturnType();
225  edm::MemberWithDict firstMember = iteratorDereferenceReturnType.dataMemberByName( "first" );
226  if ( ! firstMember ) {
227  throwException( "Could not retrieve the data member \"first\" of the class \"" +
228  iteratorDereferenceReturnType.cppName() + "\"",
229  "QVQueryMakerAndLoad::read" );
230  }
231  edm::MemberWithDict secondMember = iteratorDereferenceReturnType.dataMemberByName( "second" );
232  if ( ! secondMember ) {
233  throwException( "Could not retrieve the data member \"second\" of the class \"" +
234  iteratorDereferenceReturnType.cppName() + "\"",
235  "QVQueryMakerAndLoad::read" );
236  }
237 
238  m_arrayHandler->clear( address );
239 
240  unsigned int i=0;
241  while ( m_query->nextCursorRow() ){
242 
243  // Create a new element for the array
244  void* objectData = iteratorDereferenceReturnType.construct().address();
245  void* positionData = static_cast< char* >( objectData ) + firstMember.offset();
246  void* containerData = static_cast< char* >( objectData ) + secondMember.offset();
247 
248  m_recordId[m_recordId.size()-1] = (int)i;
249  coral::AttributeList& row = m_query->data();
250 
251  *(size_t*)positionData = (size_t)(row[m_mappingElement.posColumn()].data<int>());
252 
253  m_dataReader->setRecordId( m_recordId );
254  m_dataReader->select( m_oid );
255  m_dataReader->read( containerData );
256 
257  size_t prevSize = m_arrayHandler->size( address );
258  m_arrayHandler->appendNewElement( address, objectData );
259  bool inserted = m_arrayHandler->size( address )>prevSize;
260 
261  iteratorDereferenceReturnType.destruct( objectData );
262  if ( !inserted ) {
263  throwException( "Could not insert a new element in the array type \"" +
264  m_objectType.cppName() + "\"",
265  "QVQueryMakerAndLoad::executeAndLoad" );
266  }
267  ++i;
268  }
269 
270  m_arrayHandler->finalize( address );
271  m_query->clear();
272  }
int i
Definition: DBlmapReader.cc:9
void * address() const
size_t offset() const
MappingElement & m_mappingElement
MemberWithDict dataMemberByName(std::string const &) const
std::string cppName() const
std::auto_ptr< IArrayHandler > m_arrayHandler
std::vector< int > m_recordId
std::string posColumn() const
edm::TypeWithDict m_objectType
std::auto_ptr< SelectOperation > m_query
void destruct(void *address, bool dealloc=true) const
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
ObjectWithDict construct() const
std::auto_ptr< IRelationalReader > m_dataReader
void ora::QVQueryMaker::select ( const std::vector< int > &  fullId,
const Selection selection 
)
inline

Definition at line 168 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().

168  {
169  if(!m_query.get()){
170  throwException("The reader has not been built.",
171  "QVReader::select");
172  }
173 
174  m_oid = fullId[0];
175  m_recordId.clear();
176  for(size_t i=1;i<fullId.size();i++) {
177  m_recordId.push_back( fullId[i] );
178  }
179  // allocate the element for the index...
180  m_recordId.push_back( 0 );
181 
182  coral::AttributeList& whereData = m_query->whereData();
183  whereData[ m_mappingElement.pkColumn() ].data<int>() = fullId[0];
184 
186 
187  m_query->execute();
188  }
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 190 of file QueryableVectorStreamer.cc.

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

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

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

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

Referenced by build(), and executeAndLoad().

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

Definition at line 282 of file QueryableVectorStreamer.cc.

Referenced by build(), and executeAndLoad().

DataElement ora::QVQueryMaker::m_localElement
private

Definition at line 279 of file QueryableVectorStreamer.cc.

Referenced by build().

MappingElement& ora::QVQueryMaker::m_mappingElement
private

Definition at line 276 of file QueryableVectorStreamer.cc.

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

edm::TypeWithDict ora::QVQueryMaker::m_objectType
private

Definition at line 275 of file QueryableVectorStreamer.cc.

Referenced by build(), and executeAndLoad().

int ora::QVQueryMaker::m_oid
private

Definition at line 283 of file QueryableVectorStreamer.cc.

Referenced by executeAndLoad(), and select().

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

Definition at line 280 of file QueryableVectorStreamer.cc.

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

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

Definition at line 278 of file QueryableVectorStreamer.cc.

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

ContainerSchema& ora::QVQueryMaker::m_schema
private

Definition at line 277 of file QueryableVectorStreamer.cc.

Referenced by build(), and selectionCount().