MojErr MojDbKindEngine::find(const MojDbQuery& query, MojDbCursor& cursor, MojDbWatcher* watcher, MojDbReq& req, MojDbOp op) { MojAssert(isOpen()); MojLogTrace(s_log); MojErr err = query.validate(); MojErrCheck(err); // In order to find collate index, cursor needs kindEngine cursor.kindEngine(this); err = cursor.init(query); MojErrCheck(err); MojDbKind* kind = NULL; err = getKind(query.from().data(), kind); MojErrCheck(err); MojAssert(kind); err = kind->find(cursor, watcher, req, op); MojErrCheck(err); cursor.kindEngine(this); return MojErrNone; }
MojErr MojDbKind::updateSupers(const KindMap& map, const StringVec& superIds, bool updating, MojDbReq& req) { MojLogTrace(s_log); MojInt32 indexes = 0; if (updating) { KindVec addedSupers; MojErr err = diffSupers(map, superIds, m_superIds, addedSupers); MojErrCheck(err); KindVec removedSupers; err = diffSupers(map, m_superIds, superIds, removedSupers); MojErrCheck(err); // remove/add our objects from new/removed supers if (!addedSupers.empty() || !removedSupers.empty()) { MojDbQuery query; err = query.from(m_id); MojErrCheck(err); err = query.includeDeleted(true); MojErrCheck(err); MojDbCursor cursor; cursor.kindEngine(m_kindEngine); err = find(cursor, NULL, req, OpKindUpdate); MojErrCheck(err); for (;;) { MojObject obj; bool found = false; err = cursor.get(obj, found); MojErrCheck(err); if (!found) break; for (KindVec::ConstIterator i = addedSupers.begin(); i != addedSupers.end(); ++i) { err = (*i)->updateOwnIndexes(&obj, NULL, req, indexes); MojErrCheck(err); } for (KindVec::ConstIterator i = removedSupers.begin(); i != removedSupers.end(); ++i) { err = (*i)->updateOwnIndexes(NULL, &obj, req, indexes); MojErrCheck(err); } } } } // remove old supers m_superIds = superIds; MojErr err = clearSupers(); MojErrCheck(err); // look for new supers for (StringVec::ConstIterator i = m_superIds.begin(); i != m_superIds.end(); ++i) { KindMap::ConstIterator mapIter = map.find(*i); if (mapIter != map.end()) { err = addSuper(mapIter->get()); MojErrCheck(err); } } // look for kinds that extend us for (KindMap::ConstIterator i = map.begin(); i != map.end(); ++i) { if ((*i)->m_superIds.find(m_id) != MojInvalidIndex) { err = (*i)->addSuper(this); MojErrCheck(err); } } // add root kind if we have no supers if (m_supers.empty()) { KindMap::ConstIterator mapIter = map.find(MojDbKindEngine::RootKindId); if (mapIter != map.end()) { err = addSuper(mapIter->get()); MojErrCheck(err); } } return MojErrNone; }