void DBController::remove(const char* db, const char* ns, const char* documentId, const char* revision, const BSONObj* options) { if (_logger->isDebug()) _logger->debug(2, "DBController::update db: %s, ns: %s, documentId: %s, revision: %s", db, ns, documentId, revision); StreamType* streamData = StreamManager::getStreamManager()->open(db, ns, DATA_FTYPE); IndexAlgorithm* impl = IndexFactory::indexFactory.index(db, ns, "_id"); BSONObj indexBSON; indexBSON.add("_id", documentId); Index* index = impl->find(&indexBSON); if (index != NULL) { // TODO check the revision id StreamType* out = StreamManager::getStreamManager()->open(db, ns, DATA_FTYPE); out->flush(); long currentPos = out->currentPos(); out->seek(index->posData); BSONObj* obj = readBSON(out); obj->add("_status", 2); // DELETED // Get back to the record start out->seek(index->posData); writeBSON(out, obj); // restores the last position out->seek(currentPos); //std::string id = obj->getDJString("_id"); //CacheManager::objectCache()->remove(id); delete obj; } }
void DBController::update(const char* db, const char* ns, BSONObj* obj, const BSONObj* options) { if (_logger->isDebug()) _logger->debug(2, "DBController::update ns: %s, bson: %s", ns, obj->toChar()); StreamType* streamData = StreamManager::getStreamManager()->open(db, ns, DATA_FTYPE); Index* index = findIndex(db, ns, obj); long currentPos = streamData->currentPos(); // Moves to the record to update streamData->seek(index->posData); BSONObj* previous = readBSON(streamData); previous->add("_status", 3); // Updated streamData->seek(index->posData); writeBSON(streamData, previous); // Back to the end of the stream streamData->seek(currentPos); updateIndex(db, ns, obj, streamData->currentPos()); obj->add("_status", 1); // Active writeBSON(streamData, obj); //std::string id = obj->getDJString("_id"); //CacheManager::objectCache()->add(id, new BSONObj(*obj)); }