예제 #1
0
		protected override void OnSetUp()
		{
			cfg.Properties[Environment.CacheProvider] = typeof(HashtableCacheProvider).AssemblyQualifiedName;
			cfg.Properties[Environment.UseQueryCache] = "true";
			sessions = (ISessionFactoryImplementor)cfg.BuildSessionFactory();

			using (ISession session = OpenSession())
			using(ITransaction tx = session.BeginTransaction())
			{
				Item item = new Item();
				item.Id = 1;
				session.Save(item);
				for (int i = 0; i < 4; i++)
				{
					Item child = new Item();
					child.Id = i + 2;
					child.Parent = item;
					session.Save(child);
					item.Children.Add(child);
				}

				for (int i = 0; i < 5; i++)
				{
					AnotherItem obj = new AnotherItem("Item #" + i);
					obj.Id = i+1;
					session.Save(obj);
				}

				tx.Commit();
			}

			sessions.Evict(typeof(Item));
			sessions.EvictCollection(typeof(Item).FullName + ".Children");
		}
예제 #2
0
        protected override void OnSetUp()
        {
            // Clear cache at each test.
            RebuildSessionFactory();
            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    Item item = new Item();
                    item.Id = 1;
                    session.Save(item);
                    for (int i = 0; i < 4; i++)
                    {
                        Item child = new Item();
                        child.Id     = i + 2;
                        child.Parent = item;
                        session.Save(child);
                        item.Children.Add(child);
                    }

                    for (int i = 0; i < 5; i++)
                    {
                        AnotherItem obj = new AnotherItem("Item #" + i);
                        obj.Id = i + 1;
                        session.Save(obj);
                    }

                    tx.Commit();
                }

            Sfi.Evict(typeof(Item));
            Sfi.EvictCollection(typeof(Item).FullName + ".Children");
        }
		protected override void OnSetUp()
		{
			cfg.Properties[Environment.CacheProvider] = typeof(HashtableCacheProvider).AssemblyQualifiedName;
			cfg.Properties[Environment.UseQueryCache] = "true";
			sessions = (ISessionFactoryImplementor)cfg.BuildSessionFactory();

			using (ISession session = OpenSession())
			using(ITransaction tx = session.BeginTransaction())
			{
				Item item = new Item();
				item.Id = 1;
				session.Save(item);
				for (int i = 0; i < 4; i++)
				{
					Item child = new Item();
					child.Id = i + 2;
					child.Parent = item;
					session.Save(child);
					item.Children.Add(child);
				}

				for (int i = 0; i < 5; i++)
				{
					AnotherItem obj = new AnotherItem("Item #" + i);
					obj.Id = i+1;
					session.Save(obj);
				}

				tx.Commit();
			}

			sessions.Evict(typeof(Item));
			sessions.EvictCollection(typeof(Item).FullName + ".Children");
		}
예제 #4
0
        public async Task SimpleProjectionsAsync()
        {
            var transformer = new CustomTransformer();

            await(Sfi.EvictQueriesAsync());
            Sfi.Statistics.Clear();

            const string queryString = "select i.Name, i.Description from AnotherItem i where i.Name='widget'";

            object savedId;

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    await(s.CreateQuery(queryString).SetCacheable(true).ListAsync());
                    var i = new AnotherItem {
                        Name = "widget"
                    };
                    savedId = await(s.SaveAsync(i));
                    await(tx.CommitAsync());
                }

            QueryStatistics  qs = Sfi.Statistics.GetQueryStatistics(queryString);
            EntityStatistics es = Sfi.Statistics.GetEntityStatistics(typeof(AnotherItem).FullName);

            Thread.Sleep(200);

            IList result;

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    await(s.CreateQuery(queryString).SetCacheable(true).ListAsync());
                    await(tx.CommitAsync());
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(0));

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    await(s.CreateQuery(queryString).SetCacheable(true).ListAsync());
                    await(tx.CommitAsync());
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(1));

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    await(s.CreateQuery(queryString).SetCacheable(true).SetResultTransformer(transformer).ListAsync());
                    await(tx.CommitAsync());
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(2), "hit count should go up since the cache contains the result before the possible application of a resulttransformer");

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    await(s.CreateQuery(queryString).SetCacheable(true).SetResultTransformer(transformer).ListAsync());
                    await(tx.CommitAsync());
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(3), "hit count should go up since we are using the same resulttransformer");
            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    result = await(s.CreateQuery(queryString).SetCacheable(true).ListAsync());
                    Assert.That(result.Count, Is.EqualTo(1));
                    var i = await(s.GetAsync <AnotherItem>(savedId));
                    i.Name = "Widget";
                    await(tx.CommitAsync());
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(4));
            Assert.That(qs.CacheMissCount, Is.EqualTo(2));

            Thread.Sleep(200);

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    await(s.CreateQuery(queryString).SetCacheable(true).ListAsync());

                    var i = await(s.GetAsync <AnotherItem>(savedId));
                    Assert.That(i.Name, Is.EqualTo("Widget"));

                    await(s.DeleteAsync(i));
                    await(tx.CommitAsync());
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(4));
            Assert.That(qs.CacheMissCount, Is.EqualTo(3));
            Assert.That(qs.CachePutCount, Is.EqualTo(3));
            Assert.That(qs.ExecutionCount, Is.EqualTo(3));
            Assert.That(es.FetchCount, Is.EqualTo(0));             //check that it was being cached
        }
예제 #5
0
		public void SimpleProjections()
		{
			var transformer = new CustomTrasformer();
			sessions.EvictQueries();
			sessions.Statistics.Clear();

			const string queryString = "select i.Name, i.Description from AnotherItem i where i.Name='widget'";

			object savedId;
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.CreateQuery(queryString).SetCacheable(true).List();
				var i = new AnotherItem { Name = "widget" };
				savedId = s.Save(i);
				tx.Commit();
			}

			QueryStatistics qs = sessions.Statistics.GetQueryStatistics(queryString);
			EntityStatistics es = sessions.Statistics.GetEntityStatistics(typeof(AnotherItem).FullName);

			Thread.Sleep(200);

			IList result;
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.CreateQuery(queryString).SetCacheable(true).List();
				tx.Commit();
			}

			Assert.That(qs.CacheHitCount, Is.EqualTo(0));

			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.CreateQuery(queryString).SetCacheable(true).List();
				tx.Commit();
			}

			Assert.That(qs.CacheHitCount, Is.EqualTo(1));

			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.CreateQuery(queryString).SetCacheable(true).SetResultTransformer(transformer).List();
				tx.Commit();
			}

			Assert.That(qs.CacheHitCount, Is.EqualTo(1), "hit count should not go up since we are adding a resulttransformer");

			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.CreateQuery(queryString).SetCacheable(true).SetResultTransformer(transformer).List();
				tx.Commit();
			}

			Assert.That(qs.CacheHitCount, Is.EqualTo(2), "hit count should go up since we are using the same resulttransformer");
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				result = s.CreateQuery(queryString).SetCacheable(true).List();
				Assert.That(result.Count, Is.EqualTo(1));
				var i = s.Get<AnotherItem>(savedId);
				i.Name = "Widget";
				tx.Commit();
			}

			Assert.That(qs.CacheHitCount, Is.EqualTo(3));
			Assert.That(qs.CacheMissCount, Is.EqualTo(3));

			Thread.Sleep(200);

			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				s.CreateQuery(queryString).SetCacheable(true).List();

				var i = s.Get<AnotherItem>(savedId);
				Assert.That(i.Name, Is.EqualTo("Widget"));

				s.Delete(i);
				tx.Commit();
			}

			Assert.That(qs.CacheHitCount, Is.EqualTo(3));
			Assert.That(qs.CacheMissCount, Is.EqualTo(4));
			Assert.That(qs.CachePutCount, Is.EqualTo(4));
			Assert.That(qs.ExecutionCount, Is.EqualTo(4));
			Assert.That(es.FetchCount, Is.EqualTo(0)); //check that it was being cached
		}
예제 #6
0
        public void SimpleProjections()
        {
            var transformer = new CustomTrasformer();

            sessions.EvictQueries();
            sessions.Statistics.Clear();

            const string queryString = "select i.Name, i.Description from AnotherItem i where i.Name='widget'";

            object savedId;

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    s.CreateQuery(queryString).SetCacheable(true).List();
                    var i = new AnotherItem {
                        Name = "widget"
                    };
                    savedId = s.Save(i);
                    tx.Commit();
                }

            QueryStatistics  qs = sessions.Statistics.GetQueryStatistics(queryString);
            EntityStatistics es = sessions.Statistics.GetEntityStatistics(typeof(AnotherItem).FullName);

            Thread.Sleep(200);

            IList result;

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    s.CreateQuery(queryString).SetCacheable(true).List();
                    tx.Commit();
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(0));

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    s.CreateQuery(queryString).SetCacheable(true).List();
                    tx.Commit();
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(1));

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    s.CreateQuery(queryString).SetCacheable(true).SetResultTransformer(transformer).List();
                    tx.Commit();
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(1), "hit count should not go up since we are adding a resulttransformer");

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    s.CreateQuery(queryString).SetCacheable(true).SetResultTransformer(transformer).List();
                    tx.Commit();
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(2), "hit count should go up since we are using the same resulttransformer");
            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    result = s.CreateQuery(queryString).SetCacheable(true).List();
                    Assert.That(result.Count, Is.EqualTo(1));
                    var i = s.Get <AnotherItem>(savedId);
                    i.Name = "Widget";
                    tx.Commit();
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(3));
            Assert.That(qs.CacheMissCount, Is.EqualTo(3));

            Thread.Sleep(200);

            using (ISession s = OpenSession())
                using (ITransaction tx = s.BeginTransaction())
                {
                    s.CreateQuery(queryString).SetCacheable(true).List();

                    var i = s.Get <AnotherItem>(savedId);
                    Assert.That(i.Name, Is.EqualTo("Widget"));

                    s.Delete(i);
                    tx.Commit();
                }

            Assert.That(qs.CacheHitCount, Is.EqualTo(3));
            Assert.That(qs.CacheMissCount, Is.EqualTo(4));
            Assert.That(qs.CachePutCount, Is.EqualTo(4));
            Assert.That(qs.ExecutionCount, Is.EqualTo(4));
            Assert.That(es.FetchCount, Is.EqualTo(0));             //check that it was being cached
        }