bool WaveMetaDocument::addContainer(WaveContainer* c) { Q_ASSERT(container() == c->parentContainer()); ObjectMutation rootop(true); if ( !jsonObject().hasAttribute("containers")) { JSONObject documentsOp(true); documentsOp.setAttribute(c->name(), JSONObject(true)); rootop.setMutation("containers", documentsOp); } else { ObjectMutation documentsOp(true); documentsOp.setMutation(c->name(), InsertMutation(JSONObject(true))); rootop.setMutation("containers", documentsOp); } DocumentMutation docop(rootop); docop.setDocumentId(documentId()); docop.setRevision(revision()); // qDebug("OP=%s", qPrintable(docop.mutation().toJSON())); JSONObject result = container()->put(docop.mutation().toObject(), documentId()); return result.attribute("ok").toBool(); }
bool WaveMetaDocument::addDocument(WaveDocument* wdoc) { // Strip the "_" in front. QString docid = wdoc->documentId().mid(1); ObjectMutation rootop(true); if ( !jsonObject().hasAttribute("documents")) { JSONObject documentsOp(true); documentsOp.setAttribute(docid, JSONObject(true)); rootop.setMutation("documents", documentsOp); } else { ObjectMutation documentsOp(true); documentsOp.setMutation(docid, InsertMutation(JSONObject(true))); rootop.setMutation("documents", documentsOp); } DocumentMutation docop(rootop); docop.setDocumentId(documentId()); docop.setRevision(revision()); qDebug("OP=%s", qPrintable(docop.mutation().toJSON())); JSONObject result = container()->put(docop.mutation().toObject(), documentId()); return result.attribute("ok").toBool(); }
Index* retrieveIndexElement(MemoryStream* stream) { BSONInputStream* bis = new BSONInputStream(stream); int i = stream->readInt(); Index* index = NULL; if (i == 1) { index = new Index(); BSONObj* key = bis->readBSON(); index->key = key; std::string documentId(stream->readChars()); index->documentId = djondb::string(documentId.c_str(), documentId.length()); index->posData = stream->readLong(); index->indexPos = stream->readLong(); } else { delete bis->readBSON(); free(stream->readChars()); stream->readLong(); stream->readLong(); } delete bis; return index; }