public SavedRevision GetRevision(string id) { if (currentRevision != null && id.Equals(currentRevision.GetId())) { return(currentRevision); } EnumSet <Database.TDContentOptions> contentOptions = EnumSet.NoneOf <Database.TDContentOptions >(); RevisionInternal revisionInternal = database.GetDocumentWithIDAndRev(GetId(), id, contentOptions); SavedRevision revision = null; revision = GetRevisionFromRev(revisionInternal); return(revision); }
private SavedRevision GetRevisionWithId(String revId) { if (!String.IsNullOrWhiteSpace(revId) && revId.Equals(currentRevision.Id)) { return(currentRevision); } return(GetRevisionFromRev(Database.GetDocumentWithIDAndRev(Id, revId, EnumSet.NoneOf <TDContentOptions>()))); }
/// <summary>The revision with the specified ID.</summary> /// <param name="id">the revision ID</param> /// <returns>the SavedRevision object</returns> public SavedRevision GetRevision(String id) { if (CurrentRevision != null && id.Equals(CurrentRevision.Id)) { return(CurrentRevision); } var contentOptions = EnumSet.NoneOf <TDContentOptions>(); var revisionInternal = Database.GetDocumentWithIDAndRev(Id, id, contentOptions); var revision = GetRevisionFromRev(revisionInternal); return(revision); }
private static void VerifyHistory(Database db, RevisionInternal rev, IList <string > history) { RevisionInternal gotRev = db.GetDocumentWithIDAndRev(rev.GetDocId(), null, EnumSet .NoneOf <TDContentOptions>()); NUnit.Framework.Assert.AreEqual(rev, gotRev); NUnit.Framework.Assert.AreEqual(rev.Properties, gotRev.Properties); IList <RevisionInternal> revHistory = db.GetRevisionHistory(gotRev); NUnit.Framework.Assert.AreEqual(history.Count, revHistory.Count); for (int i = 0; i < history.Count; i++) { RevisionInternal hrev = revHistory[i]; NUnit.Framework.Assert.AreEqual(rev.GetDocId(), hrev.GetDocId()); NUnit.Framework.Assert.AreEqual(history[i], hrev.GetRevId()); NUnit.Framework.Assert.IsFalse(rev.IsDeleted()); } }
private void VerifyHistory(Database db, RevisionInternal rev, IList <string> history) { var gotRev = db.GetDocumentWithIDAndRev(rev.GetDocId(), null, DocumentContentOptions.None); Assert.AreEqual(rev, gotRev); AssertPropertiesAreEqual(rev.GetProperties(), gotRev.GetProperties()); var revHistory = db.GetRevisionHistory(gotRev); Assert.AreEqual(history.Count, revHistory.Count); for (int i = 0; i < history.Count; i++) { RevisionInternal hrev = revHistory[i]; Assert.AreEqual(rev.GetDocId(), hrev.GetDocId()); Assert.AreEqual(history[i], hrev.GetRevId()); Assert.IsFalse(rev.IsDeleted()); } }
/// <summary>Queries the view.</summary> /// <remarks>Queries the view. Does NOT first update the index.</remarks> /// <param name="options">The options to use.</param> /// <returns>An array of QueryRow objects.</returns> /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception> internal IEnumerable <QueryRow> QueryWithOptions(QueryOptions options) { if (options == null) { options = new QueryOptions(); } Cursor cursor = null; IList <QueryRow> rows = new List <QueryRow>(); try { cursor = ResultSetWithOptions(options); int groupLevel = options.GetGroupLevel(); var group = options.IsGroup() || (groupLevel > 0); var reduceBlock = Reduce; var reduce = GroupOrReduce(options); if (reduce && (reduceBlock == null) && !group) { var msg = "Cannot use reduce option in view " + Name + " which has no reduce block defined"; Log.W(Database.Tag, msg); throw new CouchbaseLiteException(StatusCode.BadRequest); } if (reduce || group) { // Reduced or grouped query: rows = ReducedQuery(cursor, group, groupLevel); } else { // regular query cursor.MoveToNext(); while (!cursor.IsAfterLast()) { var key = FromJSON(cursor.GetBlob(0)); var value = FromJSON(cursor.GetBlob(1)); var docId = cursor.GetString(2); var sequenceLong = cursor.GetLong(3); var sequence = Convert.ToInt32(sequenceLong); IDictionary <string, object> docContents = null; if (options.IsIncludeDocs()) { // http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views#Linked_documents if (value is IDictionary <string, object> && ((IDictionary <string, object>)value).ContainsKey("_id")) { var linkedDocId = (string)((IDictionary <string, object>)value).Get("_id"); var linkedDoc = Database.GetDocumentWithIDAndRev(linkedDocId, null, DocumentContentOptions.None); docContents = linkedDoc.GetProperties(); } else { var revId = cursor.GetString(4); docContents = Database.DocumentPropertiesFromJSON(cursor.GetBlob(5), docId, revId, false, sequenceLong, options.GetContentOptions()); } } var row = new QueryRow(docId, sequence, key, value, docContents); row.Database = Database; rows.AddItem <QueryRow>(row); // NOTE.ZJG: Change to `yield return row` to convert to a generator. cursor.MoveToNext(); } } } catch (SQLException e) { var errMsg = string.Format("Error querying view: {0}", this); Log.E(Database.Tag, errMsg, e); throw new CouchbaseLiteException(errMsg, e, new Status(StatusCode.DbError)); } finally { if (cursor != null) { cursor.Close(); } } return(rows); }
private static void VerifyHistory(Database db, RevisionInternal rev, IList<string > history) { RevisionInternal gotRev = db.GetDocumentWithIDAndRev(rev.GetDocId(), null, EnumSet .NoneOf<Database.TDContentOptions>()); NUnit.Framework.Assert.AreEqual(rev, gotRev); NUnit.Framework.Assert.AreEqual(rev.GetProperties(), gotRev.GetProperties()); IList<RevisionInternal> revHistory = db.GetRevisionHistory(gotRev); NUnit.Framework.Assert.AreEqual(history.Count, revHistory.Count); for (int i = 0; i < history.Count; i++) { RevisionInternal hrev = revHistory[i]; NUnit.Framework.Assert.AreEqual(rev.GetDocId(), hrev.GetDocId()); NUnit.Framework.Assert.AreEqual(history[i], hrev.GetRevId()); NUnit.Framework.Assert.IsFalse(rev.IsDeleted()); } }
public IList <QueryRow> QueryWithOptions(QueryOptions options) { if (options == null) { options = new QueryOptions(); } Cursor cursor = null; IList <QueryRow> rows = new AList <QueryRow>(); try { cursor = ResultSetWithOptions(options); int groupLevel = options.GetGroupLevel(); bool group = options.IsGroup() || (groupLevel > 0); bool reduce = options.IsReduce() || group; if (reduce && (reduceBlock == null) && !group) { Log.W(Log.TagView, "Cannot use reduce option in view %s which has no reduce block defined" , name); throw new CouchbaseLiteException(new Status(Status.BadRequest)); } if (reduce || group) { // Reduced or grouped query: rows = ReducedQuery(cursor, group, groupLevel); } else { // regular query cursor.MoveToNext(); while (!cursor.IsAfterLast()) { JsonDocument keyDoc = new JsonDocument(cursor.GetBlob(0)); JsonDocument valueDoc = new JsonDocument(cursor.GetBlob(1)); string docId = cursor.GetString(2); int sequence = Sharpen.Extensions.ValueOf(cursor.GetString(3)); IDictionary <string, object> docContents = null; if (options.IsIncludeDocs()) { object valueObject = valueDoc.JsonObject(); // http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views#Linked_documents if (valueObject is IDictionary && ((IDictionary)valueObject).ContainsKey("_id")) { string linkedDocId = (string)((IDictionary)valueObject).Get("_id"); RevisionInternal linkedDoc = database.GetDocumentWithIDAndRev(linkedDocId, null, EnumSet.NoneOf <Database.TDContentOptions>()); docContents = linkedDoc.GetProperties(); } else { docContents = database.DocumentPropertiesFromJSON(cursor.GetBlob(5), docId, cursor .GetString(4), false, cursor.GetLong(3), options.GetContentOptions()); } } QueryRow row = new QueryRow(docId, sequence, keyDoc.JsonObject(), valueDoc.JsonObject (), docContents); row.SetDatabase(database); rows.AddItem(row); cursor.MoveToNext(); } } } catch (SQLException e) { string errMsg = string.Format("Error querying view: %s", this); Log.E(Log.TagView, errMsg, e); throw new CouchbaseLiteException(errMsg, e, new Status(Status.DbError)); } finally { if (cursor != null) { cursor.Close(); } } return(rows); }
private void VerifyHistory(Database db, RevisionInternal rev, IList<string> history) { var gotRev = db.GetDocumentWithIDAndRev(rev.GetDocId(), null, DocumentContentOptions.None); Assert.AreEqual(rev, gotRev); AssertPropertiesAreEqual(rev.GetProperties(), gotRev.GetProperties()); var revHistory = db.GetRevisionHistory(gotRev); Assert.AreEqual(history.Count, revHistory.Count); for (int i = 0; i < history.Count; i++) { RevisionInternal hrev = revHistory[i]; Assert.AreEqual(rev.GetDocId(), hrev.GetDocId()); Assert.AreEqual(history[i], hrev.GetRevId()); Assert.IsFalse(rev.IsDeleted()); } }