示例#1
0
        public async Task CanGetMultiQueryFromSecondLevelCacheAsync()
        {
            await(CreateItemsAsync());
            //set the query in the cache
            await(DoMutiQueryAndAssertAsync());

            var cacheHashtable  = MultipleQueriesFixtureAsync.GetHashTableUsedAsQueryCache(Sfi);
            var cachedListEntry = (IList) new ArrayList(cacheHashtable.Values)[0];
            var cachedQuery     = (IList)cachedListEntry[1];

            var firstQueryResults = (IList)cachedQuery[0];

            firstQueryResults.Clear();
            firstQueryResults.Add(3);
            firstQueryResults.Add(4);

            var secondQueryResults = (IList)cachedQuery[1];

            secondQueryResults[0] = 2;

            using (var s = Sfi.OpenSession())
            {
                var criteria = s.CreateCriteria(typeof(Item))
                               .Add(Restrictions.Gt("id", 50));
                var multiCriteria = s.CreateMultiCriteria()
                                    .Add(CriteriaTransformer.Clone(criteria).SetFirstResult(10))
                                    .Add(CriteriaTransformer.Clone(criteria).SetProjection(Projections.RowCount()));
                multiCriteria.SetCacheable(true);
                var results = await(multiCriteria.ListAsync());
                var items   = (IList)results[0];
                Assert.AreEqual(2, items.Count);
                var count = (int)((IList)results[1])[0];
                Assert.AreEqual(2L, count);
            }
        }
示例#2
0
        public async Task CanUseSecondLevelCacheWithPositionalParametersAsync()
        {
            var cacheHashtable = MultipleQueriesFixtureAsync.GetHashTableUsedAsQueryCache(Sfi);

            cacheHashtable.Clear();

            await(CreateItemsAsync());

            await(DoMutiQueryAndAssertAsync());

            Assert.AreEqual(1, cacheHashtable.Count);
        }
        public async Task CanGetMultiQueryFromSecondLevelCacheAsync()
        {
            await(CreateItemsAsync());
            //set the query in the cache
            await(DoMutiQueryAndAssertAsync());

            var cacheHashtable  = MultipleQueriesFixtureAsync.GetHashTableUsedAsQueryCache(Sfi);
            var cachedListEntry = (IList) new ArrayList(cacheHashtable.Values)[0];
            var cachedQuery     = (IList)cachedListEntry[1];

            var firstQueryResults = (IList)cachedQuery[0];

            firstQueryResults.Clear();
            firstQueryResults.Add(3);
            firstQueryResults.Add(4);

            var secondQueryResults = (IList)cachedQuery[1];

            secondQueryResults[0] = 2L;

            using (var s = Sfi.OpenSession())
            {
                var multiQuery = s.CreateMultiQuery()
                                 .Add(s.CreateSQLQuery("select * from ITEM where Id > ?").AddEntity(typeof(Item))
                                      .SetInt32(0, 50)
                                      .SetFirstResult(10))
                                 .Add(s.CreateQuery("select count(*) from Item i where i.Id > ?")
                                      .SetInt32(0, 50));
                multiQuery.SetCacheable(true);
                var results = await(multiQuery.ListAsync());
                var items   = (IList)results[0];
                Assert.AreEqual(2, items.Count);
                var count = (long)((IList)results[1])[0];
                Assert.AreEqual(2L, count);
            }
        }