Status UpdateDriver::populateDocumentWithQueryFields(const CanonicalQuery* query, mutablebson::Document& doc) const { MatchExpression* root = query->root(); MatchExpression::MatchType rootType = root->matchType(); // These copies are needed until we apply the modifiers at the end. std::vector<BSONObj> copies; // We only care about equality and "and"ed equality fields, everything else is ignored if (rootType != MatchExpression::EQ && rootType != MatchExpression::AND) return Status::OK(); if (isDocReplacement()) { BSONElement idElem = query->getQueryObj().getField("_id"); // Replacement mods need the _id field copied explicitly. if (idElem.ok()) { mb::Element elem = doc.makeElement(idElem); return doc.root().pushFront(elem); } return Status::OK(); } // Create a new UpdateDriver to create the base doc from the query Options opts; opts.logOp = false; opts.multi = false; opts.upsert = true; opts.modOptions = modOptions(); UpdateDriver insertDriver(opts); insertDriver.setContext(ModifierInterface::ExecInfo::INSERT_CONTEXT); // If we are a single equality match query if (root->matchType() == MatchExpression::EQ) { EqualityMatchExpression* eqMatch = static_cast<EqualityMatchExpression*>(root); const BSONElement matchData = eqMatch->getData(); BSONElement childElem = matchData; // Make copy to new path if not the same field name (for cases like $all) if (!root->path().empty() && matchData.fieldNameStringData() != root->path()) { BSONObjBuilder copyBuilder; copyBuilder.appendAs(eqMatch->getData(), root->path()); const BSONObj copy = copyBuilder.obj(); copies.push_back(copy); childElem = copy[root->path()]; } // Add this element as a $set modifier Status s = insertDriver.addAndParse(modifiertable::MOD_SET, childElem); if (!s.isOK()) return s; } else { // parse query $set mods, including only equality stuff for (size_t i = 0; i < root->numChildren(); ++i) { MatchExpression* child = root->getChild(i); if (child->matchType() == MatchExpression::EQ) { EqualityMatchExpression* eqMatch = static_cast<EqualityMatchExpression*>(child); const BSONElement matchData = eqMatch->getData(); BSONElement childElem = matchData; // Make copy to new path if not the same field name (for cases like $all) if (!child->path().empty() && matchData.fieldNameStringData() != child->path()) { BSONObjBuilder copyBuilder; copyBuilder.appendAs(eqMatch->getData(), child->path()); const BSONObj copy = copyBuilder.obj(); copies.push_back(copy); childElem = copy[child->path()]; } // Add this element as a $set modifier Status s = insertDriver.addAndParse(modifiertable::MOD_SET, childElem); if (!s.isOK()) return s; } } } // update the document with base field Status s = insertDriver.update(StringData(), &doc); copies.clear(); if (!s.isOK()) { return Status(ErrorCodes::UnsupportedFormat, str::stream() << "Cannot create base during" " insert of update. Caused by :" << s.toString()); } return Status::OK(); }
bool MainWindowImpl::qt_invoke( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->slotOffset() ) { case 0: insertDriver((QString)static_QUType_QString.get(_o+1)); break; case 1: tlToRoute((TLList)(*((TLList*)static_QUType_ptr.get(_o+1)))); break; case 2: routeToTl((RouteList)(*((RouteList*)static_QUType_ptr.get(_o+1)))); break; case 3: fileNew_(); break; case 4: fileOpen_(); break; case 5: static_QUType_bool.set(_o,fileSave_()); break; case 6: fileSaveAs_(); break; case 7: fileClose_(); break; case 8: chooseNet_(); break; case 9: seeNet_(); break; case 10: configRoute_(); break; case 11: editDrivers_(); break; case 12: helpContents(); break; case 13: helpAbout(); break; case 14: removeDriver_(); break; case 15: removeSensor_(); break; case 16: insertDriver_(); break; case 17: insertSensor_(); break; case 18: driverSelected_((const QString&)static_QUType_QString.get(_o+1)); break; case 19: sensorSelected_((const QString&)static_QUType_QString.get(_o+1)); break; case 20: showItems_(); break; case 21: clearFields_(); break; case 22: clearFields_((bool)static_QUType_bool.get(_o+1)); break; case 23: listTemplates_(); break; case 24: showTemplateStructure_((QListViewItem*)static_QUType_ptr.get(_o+1)); break; case 25: driverChanged_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break; case 26: sensorChanged_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break; case 27: agentChanged_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break; case 28: gammaChanged_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break; case 29: tauChanged_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break; case 30: templateChanged_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break; case 31: tableDriverClicked_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break; case 32: tableSensorClicked_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2)); break; case 33: tableTemplateClicked_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2),(int)static_QUType_int.get(_o+3),(const QPoint&)*((const QPoint*)static_QUType_ptr.get(_o+4))); break; case 34: removeOption_(); break; case 35: addOption_(); break; case 36: saveTemplate_(); break; case 37: descriptionChanged_(); break; case 38: setDriverRoutes_((RouteList)(*((RouteList*)static_QUType_ptr.get(_o+1)))); break; case 39: newTemplate_(); break; case 40: removeTemplate_(); break; case 41: runSimulation_(); break; case 42: viewSimulation_(); break; case 43: view3D_((QString)static_QUType_QString.get(_o+1)); break; case 44: chooseAgentsFile_(); break; case 45: createNewNet_(); break; case 46: runAgents_(); break; case 47: showAgents_((XmlAgentList)(*((XmlAgentList*)static_QUType_ptr.get(_o+1)))); break; case 48: addAgent_(); break; case 49: listAgentsSelectionChanged_((QListBoxItem*)static_QUType_ptr.get(_o+1)); break; case 50: removeAgent_(); break; case 51: saveAgents_(); break; case 52: saveAsAgents_(); break; case 53: tableAgentsClicked_((int)static_QUType_int.get(_o+1),(int)static_QUType_int.get(_o+2),(int)static_QUType_int.get(_o+3),(const QPoint&)*((const QPoint*)static_QUType_ptr.get(_o+4))); break; case 54: setNewAgent_((RouteList)(*((RouteList*)static_QUType_ptr.get(_o+1)))); break; default: return MainWindow::qt_invoke( _id, _o ); } return TRUE; }