Example #1
0
        public IEnumerable<ISourcedEvent> GetAllEventsSinceVersion(Guid id, long version)
        {
            IDBCollection eventSources = database.GetCollection("Events");

            var query = new DBQuery("_SourceId", id.ToString());
            IDocument source = eventSources.FindOne();

            if (source == null) return new SourcedEvent[] { };

            var eventsAsDbObjects = ((DBObjectArray)source["_Events"]).Values.Cast<IDBObject>();

            //no benefit yield now we have single doc - might confused people due to lazy style invocation - esp if exception thrown
            var events = new List<SourcedEvent>();

            foreach (var eventDbObject in eventsAsDbObjects)
            {
                var evnt = DeserializeToEventIDBObject(eventDbObject);

                // TODO: Optimize: do not first serializing event before event sequence check.
                if (evnt.EventSequence > version)
                    events.Add(evnt);
            }

            // TODO: Add order to the query for optimization.
            return events.OrderBy(evnt => evnt.EventSequence);
        }
Example #2
0
 public void DBQueryConstructorTest1()
 {
     string key = string.Empty; // TODO: Initialize to an appropriate value
     object value = null; // TODO: Initialize to an appropriate value
     DBQuery target = new DBQuery(key, value);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DBCursorOptions"/> class.
        /// </summary>
        /// <param name="collection">The collection to query against.</param>
        /// <param name="selector">The selector query.</param>
        /// <param name="returnFields">The fields to be returned.</param>
        /// <param name="orderBy">The field or fields to order the results by.</param>
        /// <param name="numberToSkip">The number of results to skip.</param>
        /// <param name="numberToReturn">The number to return in a given batch.</param>
        /// <param name="limit">If specified, only this many results are returned.</param>
        /// <param name="explain">if set to <c>true</c> a query explanation will be included.</param>
        /// <param name="snapshot">if set to <c>true</c> then execute against a data snapshot.</param>
        /// <param name="flags">The option flags.</param>
        /// <param name="explicitIndexHint">The explicit index hint.</param>
        public DBCursorOptions(IDBCollection collection,
            DBQuery selector = null,
            DBFieldSet returnFields = null,
            DBFieldSet orderBy = null,
            int? numberToSkip = null,
            int? numberToReturn = null,
            int? limit = null,
            bool explain = false,
            bool snapshot = false,
            CursorFlags flags = CursorFlags.None,
            IDBIndex explicitIndexHint = null)
        {
            Condition.Requires(snapshot, "snapshot")
                .Evaluate(!(snapshot && explicitIndexHint != null), "Snapshot is not allowed when there is an explicit hint")
                .Evaluate(!(snapshot && orderBy != null), "Snapshot is not allowed when there field set to order by");
            Condition.Requires(numberToReturn, "numberToReturn")
                .Evaluate(!(numberToReturn.HasValue && limit.HasValue), "You may not specify both numberToReturn AND limit. They are ways to set a common property. Choose one to set.");

            Collection = collection;
            Selector = selector ?? DBQuery.SelectAll;
            ReturnFields = returnFields;
            Explain = explain;
            Flags = flags;
            Hint = explicitIndexHint;
            OrderBy = orderBy;
            Snapshot = snapshot;

            if (numberToSkip.HasValue)
                NumberToSkip = numberToSkip;
            if (numberToReturn.HasValue)
                NumberToReturn = numberToReturn.Value;
            if (limit.HasValue)
                Limit = limit;

            //If we have special query details
            if (OrderBy != null && OrderBy.Keys.Any() ||
                Hint != null ||
                Explain)
            {
                //Push everything into a container
                DBQuery query = Selector;
                Selector = new DBQuery();
                Selector["query"] = query;
                if (OrderBy != null && OrderBy.Keys.Any())
                    Selector["orderby"] = OrderBy;
                if (Hint != null)
                    Selector["$hint"] = Hint.Name;
                if (Explain)
                    Selector["$explain"] = true;
                if (Snapshot)
                    Selector["$snapshot"] = true;
            }
        }
Example #4
0
 /// <summary>
 /// Execute a database command directly. <a href="http://mongodb.onconfluence.com/display/DOCS/Mongo+Commands">Mongo Commands</a>
 /// </summary>
 /// <param name="cmd">The command object to execute.</param>
 /// <returns>The response object</returns>
 public IDBObject ExecuteCommand(DBQuery cmd)
 {
     return CmdCollection.FindOne(cmd);
 }
Example #5
0
 public void DBQueryConstructorTest3()
 {
     string whereClause = string.Empty; // TODO: Initialize to an appropriate value
     DBQuery target = new DBQuery(whereClause);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Example #6
0
 public void DBQueryConstructorTest2()
 {
     DBQuery target = new DBQuery();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Example #7
0
 public void DBQueryConstructorTest()
 {
     IDictionary<string, object> obj = null; // TODO: Initialize to an appropriate value
     DBQuery target = new DBQuery(obj);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }