/// <summary> /// Constructs an entity live query. /// </summary> /// <param name="liveQuery">The base <see cref="Query"/>.</param> /// <param name="postFilter">The post row folder or <c>null</c>.</param> /// <param name="start">Indicates that the live query should be started immediately.</param> internal EntityLiveQuery(LiveQuery liveQuery, Func <EntityQueryRow <TEntity>, bool> postFilter, bool start) { Covenant.Requires <ArgumentNullException>(liveQuery != null); this.liveQuery = liveQuery; this.rowList = new List <EntityQueryRow <TEntity> >(); this.postFilter = postFilter; liveQuery.Changed += OnChanged; if (start) { Start(); } }
void CreateGameObjectsView () { var view = _db.GetView ("SphereDocs"); var success = view.SetMap ((doc, emit) => { object key; var hasType = doc.TryGetValue ("type", out key); if (hasType && key.Equals ("CouchbaseSphere")) { emit (doc ["_id"], null); } }, "1.0"); _query = view.CreateQuery ().ToLiveQuery (); _query.Changed += (sender, e) => { ProcessRows(e.Rows); }; _query.Start (); }
public void TestPullerWithLiveQuery() { // Even though this test is passed, there is a runtime exception // thrown regarding the replication's number of changes count versus // number of completed changes count. Investigation is required. Log.D(Database.Tag, "testPullerWithLiveQuery"); string docIdTimestamp = System.Convert.ToString(Runtime.CurrentTimeMillis()); string doc1Id = string.Format("doc1-{0}", docIdTimestamp); string doc2Id = string.Format("doc2-{0}", docIdTimestamp); AddDocWithId(doc1Id, "attachment2.png"); AddDocWithId(doc2Id, "attachment2.png"); int numDocsBeforePull = database.DocumentCount; View view = database.GetView("testPullerWithLiveQueryView"); view.SetMapReduce((document, emitter) => { if (document.Get("_id") != null) { emitter(document.Get("_id"), null); } }, null, "1"); LiveQuery allDocsLiveQuery = view.CreateQuery().ToLiveQuery(); allDocsLiveQuery.Changed += (sender, e) => { int numTimesCalled = 0; if (e.Error != null) { throw new RuntimeException(e.Error); } if (numTimesCalled++ > 0) { NUnit.Framework.Assert.IsTrue(e.Rows.Count > numDocsBeforePull); } Log.D(Database.Tag, "rows " + e.Rows); }; // the first time this is called back, the rows will be empty. // but on subsequent times we should expect to get a non empty // row set. allDocsLiveQuery.Start(); DoPullReplication(); allDocsLiveQuery.Stop(); }
static ContactDatabase() { database = Manager.SharedInstance.GetDatabase ("contacts"); emailLookup = new Dictionary<string, string> (); lookupView = database.GetView ("addresses"); lookupView.SetMap ((document, emit) => { var val = document["contact.address.address"]; emit(document["_id"], val); }, "1"); Query lookupQuery = lookupView.CreateQuery (); BuildLookup(lookupQuery.Run ()); lookupViewLiveQuery = lookupQuery.ToLiveQuery(); lookupViewLiveQuery.Changed += (object sender, QueryChangeEventArgs e) => { BuildLookup(e.Rows); }; lookupViewLiveQuery.Start (); }
void CreateCounterView () { var view = _db.GetView ("SphereCount"); var success = view.SetMapReduce ((doc, emit) => { object key; var hasType = doc.TryGetValue ("type", out key); if (hasType && key.Equals ("CouchbaseSphere")) { emit (doc ["_id"], null); } }, (keys, vals, rereduce) => { return keys.Count (); }, "1.0"); _reduceQuery = view.CreateQuery ().ToLiveQuery (); _reduceQuery.Changed += (sender, e) => { int counter = _counter; Interlocked.CompareExchange(ref _counter, (int)e.Rows.ElementAt(0).Value, counter); }; _reduceQuery.Start (); }
private void InitializeCouchbase() { _db = Manager.SharedInstance.GetDatabase("wpf-lite"); var view = _db.GetView("todos"); if (view.Map == null) { view.SetMap((props, emit) => { Console.WriteLine("Mapper mapping"); emit(DateTime.UtcNow.ToString(), props["text"]); }, "1"); } _query = view.CreateQuery().ToLiveQuery(); _query.Changed += QueryChanged; _query.Completed += QueryCompleted; _query.Start(); }
public TaskManager () { _db = Manager.SharedInstance.GetDatabase("kitchen-sync"); View view = _db.GetView("viewItemsByDate"); view.SetMap((doc, emit) => { if(doc.ContainsKey("created_at") && doc["created_at"] is DateTime) { emit(doc["created_at"], null); } }, "1"); _query = view.CreateQuery().ToLiveQuery(); _query.Descending = true; _query.Changed += (sender, e) => { if(TasksUpdated != null) { var tasks = from row in e.Rows select Task.FromDictionary(row.Document.Properties); TasksUpdated(this, tasks.ToList()); } }; _query.Start(); }
public override void WillUpdateFromQuery(CouchbaseTableSource source, LiveQuery query) { return; }
public void TestCustomFilter() { var view = database.GetView("vu"); view.SetMap((doc, emit) => { emit(doc["name"], doc["skin"]); }, "1"); Assert.IsNotNull(view.Map); database.RunInTransaction(() => { CreateDocumentWithProperties(database, new Dictionary<string, object> { { "name", "Barry" }, { "skin", "none" } }); CreateDocumentWithProperties(database, new Dictionary<string, object> { { "name", "Terry" }, { "skin", "furry" } }); CreateDocumentWithProperties(database, new Dictionary<string, object> { { "name", "Wanda" }, { "skin", "scaly" } }); return true; }); var query = view.CreateQuery(); query.PostFilter = row => (row.Value as string).EndsWith("y"); var rows = query.Run(); Assert.AreEqual(2, rows.Count); CollectionAssert.AreEqual(new[] { "furry", "scaly" }, rows.Select(x => x.Value)); query = view.CreateQuery(); query.PostFilter = row => (row.Value as string).EndsWith("y"); query.Limit = 1; rows = query.Run(); Assert.AreEqual(1, rows.Count); Assert.AreEqual("furry", rows.ElementAt(0).Value); query.Limit = 0; rows = query.Run(); Assert.AreEqual(0, rows.Count); query = view.CreateQuery(); query.PostFilter = row => (row.Value as string).EndsWith("y"); query.Skip = 1; rows = query.Run(); Assert.AreEqual(1, rows.Count); Assert.AreEqual("scaly", rows.ElementAt(0).Value); }
public _Runnable_317(LiveQuery _enclosing, Future queryFutureInProgress) { this._enclosing = _enclosing; this.queryFutureInProgress = queryFutureInProgress; }
public _QueryCompleteListener_281(LiveQuery _enclosing) { this._enclosing = _enclosing; }
public void Changed(LiveQuery.ChangeEvent @event) { QueryEnumerator rows = @event.GetRows(); for (IEnumerator<QueryRow> it = rows; it.HasNext(); ) { QueryRow row = it.Next(); if (expectedKeys.Contains(row.GetKey())) { expectedKeys.Remove(row.GetKey()); doneSignal.CountDown(); } } }
public UserAdapter(ShareActivity _enclosing, Context context, LiveQuery query) : base(context, query) { this._enclosing = _enclosing; }
private void RestartLiveQuery() { if (mListsLiveQuery != null) { mListsLiveQuery.Stop(); } mListsLiveQuery = GetLiveQuery(); mListsLiveQuery.Start(); }
public void Changed(LiveQuery.ChangeEvent @event) { if (@event.GetError() != null) { Log.E(ViewsTest.Tag, "LiveQuery change event had error", @event.GetError()); } else { if (@event.GetRows().GetCount() == 1 && ((double)@event.GetRows().GetRow(0).GetValue ()) == 2 * kNDocs + 5) { gotExpectedQuery1Result.CountDown(); } } }
private void InitializeCouchbase() { _db = Manager.SharedInstance.GetDatabase("wpf-lite"); _viewModel = new SimpleViewModel(new SimpleModel(Manager.SharedInstance, "wpf-lite")); if (_viewModel.SyncURL != null) { UpdateReplications(_viewModel.SyncURL); } _viewModel.PropertyChanged += (sender, args) => { Console.WriteLine("Replication URL changed to {0}", _viewModel.SyncURL); UpdateReplications(_viewModel.SyncURL); }; var view = _db.GetView("todos"); if (view.Map == null) { view.SetMap((props, emit) => { object date; if (!props.TryGetValue(CREATION_DATE_PROPERTY_NAME, out date)) { return; } object deleted; if (props.TryGetValue("_deleted", out deleted)) { return; } emit(date, props["text"]); }, "1"); } _query = view.CreateQuery().ToLiveQuery(); _query.Changed += QueryChanged; _query.Start(); }
public ListLiveQueryAdapter(Context context, LiveQuery query) : base(context, query) { }
public _Runnable_315(LiveQuery _enclosing) { this._enclosing = _enclosing; }
public override void UpdateFromQuery(CouchbaseTableSource source, LiveQuery query, QueryRow[] previousRows) { return; }
internal QueryChangeEventArgs(LiveQuery liveQuery, QueryEnumerator enumerator, Exception error) { Source = liveQuery; Rows = enumerator; Error = error; }
private void CallToView () { var the_view = database.GetView ("testView"); the_view.SetMap (delegate(IDictionary<string, object> document, EmitDelegate emit) { try{ emit (null, document); } catch(Exception ex){ Debug.WriteLine(ex); } }, "0.1.2"); query = the_view.CreateQuery ().ToLiveQuery(); query.Changed += delegate(object sender, QueryChangeEventArgs e) { Debug.WriteLine("changed!"); }; query.Start (); }
internal ChangeEvent(LiveQuery source, QueryEnumerator queryEnumerator) { this.source = source; this.queryEnumerator = queryEnumerator; }
public void Changed(LiveQuery.ChangeEvent @event) { Log.D(LiteTestCase.Tag, "changed called, atomicInteger.incrementAndGet"); atomicInteger.IncrementAndGet(); NUnit.Framework.Assert.IsNull(@event.GetError()); if (@event.GetRows().GetCount() == kNDocs) { doneSignal.CountDown(); } }
public void Changed(LiveQuery.ChangeEvent @event) { int numTimesCalled = 0; if (@event.GetError() != null) { throw new RuntimeException(@event.GetError()); } if (numTimesCalled++ > 0) { NUnit.Framework.Assert.IsTrue(@event.GetRows().GetCount() > numDocsBeforePull); } Log.D(Database.Tag, "rows " + @event.GetRows()); }
public void AddChangeListener(LiveQuery.ChangeListener changeListener) { observers.AddItem(changeListener); }
internal QueryChangeEventArgs (LiveQuery liveQuery, QueryEnumerator enumerator, Exception error) { Source = liveQuery; Rows = enumerator; Error = error; }
public void RemoveChangeListener(LiveQuery.ChangeListener changeListener) { observers.Remove(changeListener); }