public void AndQueries()
        {
            QueryBuilder builder = new QueryBuilder(typeof(TradeLike));

            DomainDescription domainAll = new DomainDescription(typeof(TradeLike));

            domainAll.IsFullyLoaded = true;

            //check the trivial case of a complete domain (all queries are subsets of a complete domain)
            AndQuery q1 = builder.MakeAndQuery(builder.MakeAtomicQuery("Folder", "BBB"));

            Assert.IsTrue(q1.IsSubsetOf(domainAll));

            //create a complex domain definition containing all data for Folder == AAA and for ValueDate > 20010101
            DomainDescription complexDomain = new DomainDescription(typeof(TradeLike));
            AtomicQuery       q2            = builder.MakeAtomicQuery("Folder", "AAA");
            AtomicQuery       q3            = builder.MakeAtomicQuery("Folder", "BBB");
            AtomicQuery       q4            = builder.MakeAtomicQuery("ValueDate", QueryOperator.Gt, new DateTime(2001, 1, 1));

            complexDomain.AddOrReplace(q2);
            complexDomain.AddOrReplace(q4);

            AndQuery q23 = builder.MakeAndQuery();

            q23.Elements.Add(q2);
            q23.Elements.Add(q3);

            Assert.IsTrue(q23.IsSubsetOf(complexDomain));

            AtomicQuery q5  = builder.MakeAtomicQuery("ValueDate", QueryOperator.Ge, new DateTime(2001, 1, 1));
            AndQuery    q55 = builder.MakeAndQuery(q5);

            Assert.IsFalse(q55.IsSubsetOf(complexDomain));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Mostly useful in distributed cache mode without persistence. Declare all instances of a given type as being
        ///     available
        ///     Usually called after the cache is fed. This will enable "get many" operations
        /// </summary>
        public void DeclareFullyLoaded(bool fullyLoaded = true)
        {
            var emptyQuery = new OrQuery(_collectionName);
            var domain     = new DomainDescription(emptyQuery, fullyLoaded);

            _client.DeclareDomain(domain);
        }
        public void OrQueries()
        {
            QueryBuilder builder = new QueryBuilder(typeof(TradeLike));

            DomainDescription domainAll = new DomainDescription(typeof(TradeLike));

            domainAll.IsFullyLoaded = true;

            OrQuery q = builder.GetManyWhere("VALUEDATE > 20100101");

            Assert.IsTrue(q.IsSubsetOf(domainAll));

            DomainDescription complexDomain = new DomainDescription(typeof(TradeLike));
            AtomicQuery       q2            = builder.MakeAtomicQuery("Folder", "AAA");
            AtomicQuery       q4            = builder.MakeAtomicQuery("ValueDate", QueryOperator.Gt, new DateTime(2001, 1, 1));

            complexDomain.AddOrReplace(q2);
            complexDomain.AddOrReplace(q4);
            OrQuery qq = builder.GetManyWhere("FOLDER = AAA, VALUEDATE > 20010101");

            Assert.IsTrue(qq.IsSubsetOf(complexDomain));

            OrQuery qqq = builder.GetManyWhere("VALUEDATE >= 20010101");

            Assert.IsFalse(qqq.IsSubsetOf(complexDomain));

            AtomicQuery q3  = builder.MakeAtomicQuery("Folder", "BBB");
            AndQuery    q33 = builder.MakeAndQuery(q3);

            qq.Elements.Add(q33);
            //the query is now (FOLDER = AAA AND VALUEDATE > 20010101) OR (FOLDER = BBB ) ans is not a subset
            //any more
            Assert.IsFalse(qq.IsSubsetOf(complexDomain));
        }
Exemplo n.º 4
0
        public void DomainDescription()
        {
            var evalResult = _client.IsComplete <CacheableTypeOk>(i => i.IndexKeyFolder == "aaa");

            Assert.IsFalse(evalResult);


            var item1 = new CacheableTypeOk(1, 1001, "aaa", new DateTime(2010, 10, 10), 1500);

            _client.PutOne(item1);

            var item2 = new CacheableTypeOk(2, 1002, "aaa", new DateTime(2010, 10, 10), 1600);

            _client.PutOne(item2);

            evalResult = _client.IsComplete <CacheableTypeOk>(i => i.IndexKeyFolder == "aaa");
            Assert.IsFalse(evalResult);

            var description = new DomainDescription(OrQuery.Empty <CacheableTypeOk>());

            //describe the domain as complete
            _client.DeclareDomain(description);

            evalResult = _client.IsComplete <CacheableTypeOk>(i => i.IndexKeyFolder == "aaa");
            Assert.IsTrue(evalResult);
        }
Exemplo n.º 5
0
        public void DomainDescription()
        {
            var builder    = new QueryBuilder(typeof(CacheableTypeOk));
            var evalResult = _client.EvalQuery(builder.GetMany("IndexKeyFolder=aaa"));

            Assert.IsFalse(evalResult.Key);
            Assert.AreEqual(evalResult.Value, 0);

            var item1 = new CacheableTypeOk(1, 1001, "aaa", new DateTime(2010, 10, 10), 1500);

            _client.Put(item1);

            var item2 = new CacheableTypeOk(2, 1002, "aaa", new DateTime(2010, 10, 10), 1600);

            _client.Put(item2);

            evalResult = _client.EvalQuery(builder.GetMany("IndexKeyFolder=aaa"));
            Assert.IsFalse(evalResult.Key);
            Assert.AreEqual(evalResult.Value, 2);

            var description = new DomainDescription(OrQuery.Empty <CacheableTypeOk>());

            //describe the domain as complete
            _client.DeclareDomain(description);
            evalResult = _client.EvalQuery(builder.GetMany("IndexKeyFolder=aaa"));
            Assert.IsTrue(evalResult.Key);
            Assert.AreEqual(evalResult.Value, 2);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     This query is a subset of a domain if at least one of the contained atomic queries is a subset
        /// </summary>
        /// <param name="domain"></param>
        /// <returns></returns>
        public bool IsSubsetOf(DomainDescription domain)
        {
            if (domain.IsFullyLoaded)
            {
                return(true);
            }

            return(_elements.Any(query => query.IsSubsetOf(domain)));
        }
Exemplo n.º 7
0
 public void DeclareDomain(DomainDescription domain)
 {
     try
     {
         Parallel.ForEach(CacheClients, client => client.DeclareDomain(domain));
     }
     catch (AggregateException e)
     {
         if (e.InnerException != null)
         {
             throw e.InnerException;
         }
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Only used in cache-only mode (no persistence). Declare a subset of the data as being fully loaded into the cache
        /// Any expression that can be used for querying is valid here
        /// </summary>
        /// <param name="domainDefinition"></param>
        /// <param name="humanReadableDescription">Optional description of the loaded domain</param>
        public void DeclareLoadedDomain([NotNull] Expression <Func <T, bool> > domainDefinition, string humanReadableDescription = null)
        {
            if (domainDefinition == null)
            {
                throw new ArgumentNullException(nameof(domainDefinition));
            }


            var query = PredicateToQuery(domainDefinition);

            var domain = new DomainDescription(query, false, humanReadableDescription);

            _client.DeclareDomain(domain);
        }
        public void DomainDescription()
        {
            var builder    = new QueryBuilder(typeof(CacheableTypeOk));
            var evalResult = _client.EvalQuery(builder.GetMany("IndexKeyFolder=aaa"));

            Assert.IsFalse(evalResult.Key);
            Assert.AreEqual(evalResult.Value, 0);

            var item1 = new CacheableTypeOk(1, 1001, "aaa", new DateTime(2010, 10, 10), 1500);

            _client.Put(item1);

            var item2 = new CacheableTypeOk(2, 1002, "aaa", new DateTime(2010, 10, 10), 1600);

            _client.Put(item2);

            evalResult = _client.EvalQuery(builder.GetMany("IndexKeyFolder=aaa"));
            Assert.IsFalse(evalResult.Key);
            Assert.AreEqual(evalResult.Value, 2);

            var description = new DomainDescription(typeof(CacheableTypeOk))
            {
                IsFullyLoaded = true
            };

            //describe the domain as complete
            _client.DeclareDomain(description, DomainDeclarationAction.Set);
            evalResult = _client.EvalQuery(builder.GetMany("IndexKeyFolder=aaa"));
            Assert.IsTrue(evalResult.Key);
            Assert.AreEqual(evalResult.Value, 2);

            //remove the completeness declaration
            _client.DeclareDomain(description, DomainDeclarationAction.Remove);
            evalResult = _client.EvalQuery(builder.GetMany("IndexKeyFolder=aaa"));
            Assert.IsFalse(evalResult.Key);

            description.AddOrReplace(builder.MakeAtomicQuery("IndexKeyFolder", "aaa"));
            _client.DeclareDomain(description, DomainDeclarationAction.Add);
            evalResult = _client.EvalQuery(builder.GetMany("IndexKeyFolder=aaa"));
            Assert.IsTrue(evalResult.Key);

            _client.DeclareDomain(description, DomainDeclarationAction.Remove);
            evalResult = _client.EvalQuery(builder.GetMany("IndexKeyFolder=aaa"));
            Assert.IsFalse(evalResult.Key);
        }
Exemplo n.º 10
0
        public void DeclareDomain(DomainDescription domain)
        {
            if (domain == null)
            {
                throw new ArgumentNullException(nameof(domain));
            }

            if (domain.DescriptionAsQuery.CollectionName == null)
            {
                throw new ArgumentNullException(nameof(domain), "CollectionName not specified");
            }

            var request  = new DomainDeclarationRequest(domain);
            var response = Channel.SendRequest(request);

            if (response is ExceptionResponse exResponse)
            {
                throw new CacheException("Error while declaring a domain", exResponse.Message, exResponse.CallStack);
            }
        }
Exemplo n.º 11
0
        public void DataAccess()
        {
            var builder = new QueryBuilder(typeof(CacheableTypeOk));

            //add two new items
            var item1 = new CacheableTypeOk(1, 1001, "aaa", new DateTime(2010, 10, 10), 1500);

            _client.Put(item1);

            var item2 = new CacheableTypeOk(2, 1002, "aaa", new DateTime(2010, 10, 10), 1600);

            _client.Put(item2);

            var domainDeclaration = new DomainDescription(typeof(CacheableTypeOk));

            domainDeclaration.AddOrReplace(builder.MakeAtomicQuery("IndexKeyFolder", "aaa"));
            _client.DeclareDomain(domainDeclaration, DomainDeclarationAction.Set);

            var eval = _client.EvalQuery(builder.GetManyWhere("IndexKeyFolder == aaa"));

            Assert.IsTrue(eval.Key); //domain is complete
            Assert.AreEqual(eval.Value, 2);

            eval = _client.EvalQuery(builder.GetManyWhere("IndexKeyFolder == bbb"));
            Assert.IsFalse(eval.Key); //domain is incomplete
            Assert.AreEqual(eval.Value, 0);

            //reload the first one by primary key
            var item1Reloaded = _client.GetOne <CacheableTypeOk>(1);

            Assert.AreEqual(item1, item1Reloaded);

            //reload both items by folder name
            IList <CacheableTypeOk> itemsInAaa =
                new List <CacheableTypeOk>(_client.GetMany <CacheableTypeOk>("IndexKeyFolder == aaa"));

            Assert.AreEqual(itemsInAaa.Count, 2);

            //change the folder of the first item and put it back into the cache
            item1.IndexKeyFolder = "bbb";
            _client.Put(item1);

            //now it should be only one item left in aaa
            itemsInAaa = new List <CacheableTypeOk>(_client.GetMany <CacheableTypeOk>("IndexKeyFolder == aaa"));
            Assert.AreEqual(itemsInAaa.Count, 1);

            //get both of them again by date
            IList <CacheableTypeOk> allItems =
                new List <CacheableTypeOk>(_client.GetMany <CacheableTypeOk>($"IndexKeyDate ==  {new DateTime(2010, 10, 10).Ticks}"));

            Assert.AreEqual(allItems.Count, 2);

            //get both of them using an In query

            var q = builder.In("indexkeyfolder", "aaa", "bbb");

            allItems = _client.GetMany <CacheableTypeOk>(q).ToList();
            Assert.AreEqual(allItems.Count, 2);

            //remove the first one
            _client.Remove <CacheableTypeOk>(1);

            //the previous query should now return only one item
            allItems = _client.GetMany <CacheableTypeOk>(q).ToList();
            Assert.AreEqual(allItems.Count, 1);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Mostly useful in distributed cache mode without persistence. Declare all instances of a given type as being available
        /// Usually called after the cache is fed. This will enable "get many" operations
        /// </summary>
        public void DeclareFullyLoaded(bool fullyLoaded = true)
        {
            var domain = new DomainDescription(OrQuery.Empty <T>(), fullyLoaded);

            _client.DeclareDomain(domain);
        }
Exemplo n.º 13
0
 /// <summary>
 ///     Create a new request for the specified type. The domain description will be empty
 /// </summary>
 public DomainDeclarationRequest(DomainDescription description)
     : base(DataAccessType.Write, description.DescriptionAsQuery.TypeName)
 {
     _description = description;
 }
 /// <summary>
 ///     Create a new request for the specified type. The domain description will be empty
 /// </summary>
 public DomainDeclarationRequest(DomainDescription description, DomainDeclarationAction action)
     : base(DataAccessType.Write, description.FullTypeName)
 {
     _action      = action;
     _description = description;
 }