コード例 #1
0
        public IList <T> List(IEnumerable identities)
        {
            if (identities == null)
            {
                return(null);
            }

            return(inIdentitiesQuery.GetExecutableQuery(session)
                   .SetParameterList("identities", identities)
                   .List <T>());
        }
コード例 #2
0
        public void Serializable()
        {
            DetachedQuery dq = new DetachedQuery("from Foo f where f.Name=:pn and f.Description=:pd");

            dq.SetString("pn", "N2").SetString("pd", "D2");
            byte[] bytes = SerializationHelper.Serialize(dq);

            DetachedQuery dqs = (DetachedQuery)SerializationHelper.Deserialize(bytes);

            using (ISession s = OpenSession())
            {
                dqs.GetExecutableQuery(s).List();
            }
        }
コード例 #3
0
        public void PerformanceDiffSimplyQuery()
        {
            DateTime      sDQStart = DateTime.Now;
            DetachedQuery dq       = new DetachedQuery("from Foo f where f.Name=:pn and f.Description=:pd");

            dq.SetString("pn", "N2").SetString("pd", "D2");
            using (ISession s = OpenSession())
            {
                IQuery q = dq.GetExecutableQuery(s);
            }
            DateTime sDQStop = DateTime.Now;

            DateTime sQStart = DateTime.Now;

            using (ISession s = OpenSession())
            {
                IQuery q = s.CreateQuery("from Foo f where f.Name=:pn and f.Description=:pd").SetString("pn", "N2").SetString("pd", "D2");
            }
            DateTime sQStop = DateTime.Now;

            Console.WriteLine("DetachedQueryCycle={0} QueryCycl={1}  Diff={2}", sDQStop - sDQStart, sQStop - sQStart,
                              (sDQStop - sDQStart) - (sQStop - sQStart));
        }
コード例 #4
0
        public void ExecutableQuery()
        {
            // Simply fetch
            IDetachedQuery dq = new DetachedQuery("from Foo");

            using (ISession s = OpenSession())
            {
                IQuery q = dq.GetExecutableQuery(s);
                IList  l = q.List();
                Assert.AreEqual(totalFoo, l.Count);
            }

            // With Typed Parameters
            dq = new DetachedQuery("from Foo f where f.Name=:pn and f.Description=:pd");
            dq.SetString("pn", "N2").SetString("pd", "D2");
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(1, l.Count);
                Assert.AreEqual("N2", l[0].Name);
                Assert.AreEqual("D2", l[0].Description);
            }

            // With UnTyped Parameters
            dq = new DetachedQuery("from Foo f where f.Name=:pn and f.Description=:pd");
            dq.SetParameter("pn", "N2").SetParameter("pd", "D2");
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(1, l.Count);
                Assert.AreEqual("N2", l[0].Name);
                Assert.AreEqual("D2", l[0].Description);
            }

            // With UnTyped Parameter List
            dq = new DetachedQuery("from Foo f where f.IntValue in (:pn)");
            dq.SetParameterList("pn", new int[] { 2, 3 });
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(2, l.Count);

                Assert.True(l.Contains(new Foo("N2", "D2")));
                Assert.True(l.Contains(new Foo("N3", "D3")));
            }

            // Pagination
            dq = new DetachedQuery("from Foo f order by f.IntValue");
            dq.SetFirstResult(0).SetMaxResults(2);
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(2, l.Count);
                Assert.AreEqual("N0", l[0].Name);
                Assert.AreEqual("N1", l[1].Name);
            }
            dq.SetFirstResult(2).SetMaxResults(1);
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(1, l.Count);
                Assert.AreEqual("N2", l[0].Name);
            }
        }
コード例 #5
0
        public void FullCreamIntegration()
        {
            // Fill DB
            SessionFactory.EncloseInTransaction(session =>
            {
                for (int i = 0; i < 10; i++)
                {
                    session.Save(new MusicCD {
                        Name = "Music" + (i / 2)
                    });
                    session.Save(new Antique {
                        Name = "Antique" + (i / 2)
                    });
                }
            });

            // Queries
            var musicQuery =
                new DetachedQuery("select m.Name, count(*) from MusicCD m group by m.Name")
                .SetCacheable(true)
                .SetCacheRegion("SearchStatistics");

            var antiquesQuery =
                new DetachedQuery("select a.Name, count(*) from Antique a group by a.Name")
                .SetCacheable(true)
                .SetCacheRegion("SearchStatistics");

            // Clear SessionFactory Statistics
            SessionFactory.Statistics.Clear();

            // Put in second-level-cache
            SessionFactory.EncloseInTransaction(session =>
            {
                musicQuery.GetExecutableQuery(session).List();
                antiquesQuery.GetExecutableQuery(session).List();
            });

            // Asserts after execution
            SessionFactory.Statistics.QueryCacheHitCount
            .Should("not hit the query cache").Be.EqualTo(0);

            SessionFactory.Statistics.QueryExecutionCount
            .Should("execute both queries").Be.EqualTo(2);

            // Update both tables
            SessionFactory.EncloseInTransaction(session =>
            {
                session.Save(new MusicCD {
                    Name = "New Music"
                });
                session.Save(new Antique {
                    Name = "New Antique"
                });
            });

            // Clear SessionFactory Statistics again
            SessionFactory.Statistics.Clear();

            // Execute both queries again
            SessionFactory.EncloseInTransaction(session =>
            {
                musicQuery.GetExecutableQuery(session).List();
                antiquesQuery.GetExecutableQuery(session).List();
            });

            // Asserts after execution
            SessionFactory.Statistics.QueryCacheHitCount
            .Should("Hit the query cache").Be.EqualTo(1);

            SessionFactory.Statistics.QueryExecutionCount
            .Should("execute only the query for Antiques").Be.EqualTo(1);

            // Clear SessionFactory Statistics again
            SessionFactory.Statistics.Clear();

            // Wait for cache expiration
            Thread.Sleep(new TimeSpan(0, 0, 10));
            // Execute
            SessionFactory.EncloseInTransaction(session => musicQuery.GetExecutableQuery(session).List());

            SessionFactory.Statistics.QueryCacheHitCount
            .Should("Not hit the query cache because stale").Be.EqualTo(0);

            SessionFactory.Statistics.QueryExecutionCount
            .Should("execute the query for MusicCD").Be.EqualTo(1);

            // Cleanup
            SessionFactory.EncloseInTransaction(session =>
            {
                session.Delete("from MusicCD");
                session.Delete("from Antique");
            });
        }
コード例 #6
0
 public IList <T> List()
 {
     return(allQuery.GetExecutableQuery(session).List <T>());
 }
コード例 #7
0
 public IList <TType> GetList <TType>(DetachedQuery dq)
 {
     return(dq.GetExecutableQuery(Session).List <TType>());
 }