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 }
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 }